Client session handling: stop reaching into private state, validate snapshots, clear keys on logout #10
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Three defects in
src/client.ts, all in the session lifecycle:toJSONreads a private field by string index.src/client.ts:141doestoken: this.api["token"]!to bypass TypeScript's private-field check, with a non-nullassertion on top. If
toJSON()is called on a client with no token, this silently emitsundefinedinto a snapshot that is then written to disk as a valid session file.fromJSONdoes not validate the snapshot.src/client.ts:107-120runsfromBase64over four fields with no shape check. A truncated, hand-edited, or corrupt
session.jsonthrows a raw libsodium error out of the CLI with no indication that thesession file is the problem.
bin/quak.tscompounds this by swallowing session-load errorsentirely, so a corrupt session is indistinguishable from "not logged in".
logout()does not clear key material.src/client.ts:148-151flips a flag and clearsthe API token, but
masterKey,secretKeyandpublicKeystay live in memory. For aclient whose whole job is holding the keys to someone's photo library, logout should mean
the keys are gone.
Definition of done
ApiClientexposes a proper accessor for the current auth token;Client.toJSONuses itand no longer indexes into a private field or uses a non-null assertion.
toJSON()on a client with no auth token fails with a clear error rather than emitting asnapshot containing
undefined.fromJSONvalidates the snapshot: required fields present, correct types, base64 decodingto the expected byte lengths for each key. An invalid snapshot throws an error that names
the offending field and says the session data is invalid.
bin/quak.tsdistinguishes "no session file" from "session file is corrupt" and tells theuser which one it is, with a non-zero exit code for the corrupt case.
logout()zeroes the key material buffers in addition to clearing the token, and anysubsequent operation on the logged-out client throws the same way it does today.
toJSONround-tripping throughfromJSONunchanged, and every rejection case in item 3.
make checkgreen.TODO.mdupdated in the same commit.