Skip to main content

Module local_session_file

Module local_session_file 

Source
Expand description

The file that keeps a headless srv’s browser sessions across a restart (sessions.bin, in the data root). docs/specs/SPEC_WINDOWS_HEADLESS_AS_A_SERVICE_2026_11_20.md D.2.

What it holds: for each live session the SHA-256 of its cookie and of its per-tab token (the same digests the store keeps in memory, never a cookie or a token), when it was confirmed and when it was last used, as wall-clock seconds. One-time codes and pending sessions are never written. The file is written by a temp file and a rename, owner-only, when a session is confirmed or ended and (at most every SAVE_EVERY) when one is used.

What it refuses: a file that cannot be trusted is ignored, every session in it is cleared, and the reason is logged once (never a digest). That is a file whose folder or own access list lets anyone but the owner, the system and the administrators open it, one that is truncated, has extra bytes, does not parse or fails its check value, one saved at a time after now (the clock has moved back, so the time that has passed is unknown), one with a time that cannot be (a session used before it was confirmed, or after the file was saved), and one made under a different sign-in key when the key is one the person provided. A key srv generated is new at every start, so a session cannot depend on it: the check value of such a file is a plain SHA-256, and of a file made under a provided key an HMAC under that key.

StructsΒ§

Record πŸ”’
One saved session: the digests and the wall-clock seconds of its confirmation and last use.

EnumsΒ§

KeyBinding πŸ”’
What the file is bound to: nothing (the key was generated at this start), or the key the person provided.
Refused πŸ”’
Why the file was not used. A fixed text: it names no value from the file.

ConstantsΒ§

FILE_NAME πŸ”’
The file’s name in the data root.
HEADER_LEN πŸ”’
MAGIC πŸ”’
MAX_SESSIONS πŸ”’
Most sessions the file holds or accepts.
RECORD_LEN πŸ”’
SAVE_EVERY πŸ”’
A use of a session is written at most this often; the saved time of last use is then at most this stale, which makes a session older after a restart, never younger.
TRAILER_LEN πŸ”’

FunctionsΒ§

clear πŸ”’
Delete the file (a logout, or a refusal). Nothing is wrong if it is not there. When it cannot be deleted (a sharing violation, a scanner holding it) it is replaced by a file with no sessions; only when that fails too is the error returned, and the file, with whatever sessions it holds, is still there.
decode πŸ”’
The sessions in bytes, if it is a whole file made under binding and saved at or before now_secs.
encode πŸ”’
The bytes of a file of records, saved at saved_secs.
load πŸ”’
Read the file: Ok(None) when there is none, the sessions when it can be trusted. On any refusal the file is deleted, so a later start does not meet it again.
private_enough πŸ”’
Whether the file and its folder can be opened by nobody but the owner, the system and the administrators. A failure to find out is a refusal.
save πŸ”’
Write the file: a temp file in the same folder (owner-only before it holds anything on unix, and with its list set on Windows) and a rename over the old one.

Type AliasesΒ§

Digest32 πŸ”’