Expand description
The browser sessions of a headless srv that serves its own UI on loopback: one-time codes, the pending sessions a code makes, and the live sessions a person confirms.
The flow, from the personβs side: agentmux-srv open mints a code with the key, the browser
enters it, the page shows a short check phrase, open shows the same phrase and asks the
person to confirm. Only a confirmed session is live. Codes and pending sessions are memory only
and a restart ends them. The live sessions are kept across a restart when a data root is given
(SessionStore::keep_in, the file is in local_session_file.rs): only their digests, and only
while they are inside their limits.
A live session is a pair: a cookie (sent by the browser to every port of the address, so it
proves little alone) and a per-tab token the page keeps in sessionStorage (isolated by
origin, port included). One record holds the hash of both, and a request needs both to name it
(SessionStore::admit). Secrets are kept as SHA-256 digests; a code, handle, cookie or token
never reaches a log.
StructsΒ§
- Confirm π
- One confirm of a session, as
statusshows it. It holds no value of a code, cookie or token: the session is named by its check phrase, which the person saw. - Entered π
- What a code entry made.
- Grant π
- What a sessionβs page was handed, once.
- Inner π
- Pending π
- Persist π
- Where the live sessions are kept across a restart, once that is on.
- Session π
- Session
Id π - Which session a request came from (the digest of its cookie), carried on the request so a WebSocket upgraded with it can be closed when the session ends.
- Session
Store π
EnumsΒ§
- Code
State π - Where a code stands, for the
openthat minted it. - Collected π
- The waiting pageβs answer.
- Confirm
How π - How a confirm was made: where the process that sent it stands.
- Outcome π
- Route
Class π - What a request to a route may present.
ConstantsΒ§
- CODE_
LIFE π - A code can be entered for this long after it is minted.
- LIVE_
RECHECK π - How often a socket re-checks that its session is still live (a logout is heard at once).
- LOGGED_
FAILURES π - This many refusals in a minute are logged one by one; after them, one line says the rest are only counted.
- MAX_
CONFIRMS π - Most confirms remembered at once; the oldest goes first.
- MAX_
FAILURES π - Most refusals remembered at once (they are counted over a minute).
- MAX_
HELD π - Most codes and most pending sessions held at once; the oldest goes first.
- PENDING_
LIFE π - A pending session waits this long, from the moment its code was entered, for the personβs answer.
- SESSION_
IDLE_ πLIFE - A session ends after this long without a request.
- SESSION_
MAX_ πLIFE - A session ends this long after it was confirmed, however much it is used: a browser that is
always open signs in again (with
agentmux-srv open) once a week.
FunctionsΒ§
- check_
phrase π - Two short pronounceable words from 1024 each (about 20 bits), e.g.
kela-mivo: easy to compare by eye. - digest π
- end_
pending π - phrase_
word π - Word
n(0..1024): consonant, vowel, consonant, vowel from 8 consonants and 4 vowels. - prune π
- Drop what has expired. A grant nobody collected ends its session too.
- random_
secret π - 256 random bits as 64 hex characters (a valid WebSocket subprotocol token and cookie value).
- save π
- Write the live sessions to the file, or delete it when there are none. A write that fails is logged (its kind only) and the sessions stay in memory: nothing is lost but a sign-in surviving the next restart.
- save_
if_ πdue - A use of a session is written at most every
file::SAVE_EVERY.
Type AliasesΒ§
- Digest32 π