Six layers of defense — from the network perimeter to observability. SSH passwords never leave the device in plaintext at any stage.
flowchart LR
PIN["Password / PIN"] --> KDF["Argon2id (credentialSalt)"]
KDF --> KEY["authKey (32 bytes)"]
CREDS["sshUser + sshPassword"] --> ENC["AES-256-GCM"]
KEY --> ENC
ENC --> BLOB["{ iv, ciphertext, tag }"]
BLOB --> SRV[("Server: stores only ciphertext")] Argon2id + AES-256-GCM — the server stores only ciphertext
flowchart TB
P["userPassword / PIN"] --> ARGON["Argon2id
memory=65536 KB, time=3, hashLen=32"]
SALT["credentialSalt (32 bytes)"] --> ARGON
ARGON --> KEY["authKey (32 bytes)"]
IV["iv = randomBytes(12)"] --> ENC["AES-256-GCM"]
KEY --> ENC
CREDS["{ sshUser, sshPassword }"] --> ENC
ENC --> OUT["{ iv, ciphertext, tag }"] Key derivation parameters and the encrypted blob format
flowchart TB
REG["Registration / OAuth"] --> GEN["Server generates credentialSalt once (32 bytes)"]
GEN --> STORE[("Stored in User.credentialSalt, never rotated")]
MD["Second device"] --> KNOWS["Knows the vault PIN + fetches credentialSalt from the server (GET /profile)"]
KNOWS --> DERIVE["authKey = Argon2id(PIN, credentialSalt)"]
DERIVE --> UNLOCK["Unlocks all credentials without exchanging secrets between devices"]
UNLOCK -.-> NOTE["authKey depends on the vault PIN, not the account password —<br/>an account password change (PATCH /profile/password) does not affect credential encryption"]
classDef note fill:#fdf6df,stroke:#151718,color:#151718
class NOTE note credentialSalt is set once at registration and is never rotated
sequenceDiagram
participant C as Client
participant S as Backend
participant R as Valkey
Note over C,S: Session setup (once per app launch)
C->>S: POST /vps/ssh-session { authKeyB64 }
S->>R: SETEX ssh-session:{userId} authKey (8h)
S-->>C: sessionId
Note over C,S: Getting a token (per operation)
C->>C: opKey = HKDF(authKey, nonce)
C->>C: ciphertext = AES-GCM(opKey, creds)
C->>S: POST /vps/:id/ssh-token { nonceB64, ciphertextB64, tagB64, timestamp, action }
S->>R: fetch authKey for the session
S->>S: HKDF → opKey → decrypt creds
S->>R: SET ssh-token:{id} creds (TTL 60s)
S-->>C: { tokenId, expiresAt }
Note over C,S: Consuming the token (headers x-ssh-token, x-ssh-token-ts, x-ssh-sig)
C->>S: POST /sftp/list { tokenId, tokenTs, tokenSig }
S->>R: GETDEL ssh-token:{id}
S->>S: SSH command, then wipe creds from memory HKDF-derived operation key + HMAC signature, 60-second TTL, single use
flowchart LR
T["Token created (TTL 60s)"] --> U{"Used within the TTL?"}
U -- "yes" --> C["GETDEL from Valkey → single use"]
U -- "TTL expired" --> E["TOKEN_NOT_FOUND"]
RL["60 requests / user / VM / 60s"] --> LIMIT["Exceeded → 400 Bad Request (no errorCode)"] Single use and rate limiting
stateDiagram-v2
[*] --> Locked: app launch
Locked --> Biometrics: hasSecureKey == true
Locked --> PinEntry: hasSecureKey == false
Biometrics --> Unlocked: success
Biometrics --> PinEntry: unavailable
PinEntry --> Unlocked: Argon2id(pin) + auth-tag check
PinEntry --> Locked: wrong PIN
Unlocked --> Locked: app backgrounded (30s)
Unlocked --> [*]: logout State transitions: lock, biometrics, PIN, logout
sequenceDiagram
participant U as User
participant App as App
participant S as Backend
participant Bot as MAX Bot
App->>App: generate a 6-digit code (sessionId)
App->>Bot: deep link .../bot?start=sessionId
App->>U: show the code in an overlay (with a "copy" button)
Note over U,Bot: if the redirect to MAX didn't fire automatically
U->>Bot: sends the code manually in chat
Bot->>S: /start <sessionId>
S->>S: store tokens in Valkey (TTL 60s)
loop poll every 3s (up to 60s)
App->>S: GET /auth/max/poll/:sessionId
S-->>App: 202 (waiting)
end
S-->>App: 200 { accessToken, refreshToken } Deep link into MAX + code as a fallback, long polling — no password on the client side
flowchart TB
URL["scriptUrl"] --> CHECK{"IP in a blocked range?"}
CHECK -- "127.*, 0.0.0.0, localhost" --> BLOCK["Rejected"]
CHECK -- "10.*, 172.16-31.*, 192.168.* (RFC1918)" --> BLOCK
CHECK -- "169.254.* (cloud metadata)" --> BLOCK
CHECK -- "100.64.* (shared address space)" --> BLOCK
CHECK -- "::1, fc00::, fd* (IPv6 private)" --> BLOCK
CHECK -- "public address" --> ALLOW["Download allowed"] Blocked ranges when downloading scripts by URL
flowchart TB
NAME["Parameter name"] --> RX{"matches the whitelist pattern?"}
RX -- "no" --> REJECT["Rejected"]
RX -- "yes" --> OK1["Allowed"]
DIR["Working directory"] --> ABS{"matches the whitelist character pattern?"}
ABS -- "no" --> REJECT
ABS -- "yes" --> OK2["Allowed"]
VAL["Parameter value"] --> BASH["shellQuoteSh(): single quotes + escaping"]
VAL --> PS["shellQuotePs(): single quotes, doubling embedded '"] Parameter validation and value escaping in commands
flowchart LR
VM["VM (installer)"] --> CB["PATCH /vps/installed?vpsName=...&installed=... + headers x-vm-ts, x-vm-signature"]
CB --> CALC["expected = HMAC-SHA256(VM_CALLBACK_SECRET, 'event:vpsName:flag:timestamp')"]
CALC --> CMP{"signature == expected and
drift within tolerance?"}
CMP -- "yes" --> ACCEPT["status = RUNNING"]
CMP -- "no" --> REJECT["Rejected"] Signature verification and allowed clock drift
flowchart LR
CONN["SSH connection"] --> STRICT{"SSH_STRICT_HOST_KEY?"}
STRICT -- "true" --> FP{"fingerprint in the allowlist?"}
FP -- "yes" --> ALLOW["Connection allowed"]
FP -- "no" --> DENY["Connection rejected"]
STRICT -- "false (dev only)" --> WARN["Log a warning, allow the connection"] Host-key pinning by SHA256 fingerprint
All exceptions are normalized by the global filter into a single format { statusCode, timestamp, path, message, error, errorCode }. 5xx responses are masked with generic text — the full error is logged only on the server.
| errorCode | Meaning | Client Action |
|---|---|---|
| sudo | A sudo password is required | Show the sudo-password prompt |
| SUDO_PASSWORD_REQUIRED | Same as above | Show the prompt |
| SUDO_PASSWORD_INVALID | Incorrect sudo password | Prompt again |
| expired_session | The refresh token has expired | Force logout |
| TOKEN_NOT_FOUND | Token already used or expired | Retry the operation |