Skip to main content

Module local_session_routes

Module local_session_routes 

Source
Expand description

The browser sign-in of a headless srv that serves its own UI (--frontend-dir) on loopback: the /auth/* routes, the check that admits a browser’s session in auth_middleware, and the headers of the served UI. The sessions themselves are in super::local_session.

Every answer to a failed sign-in route is the same 403 not accepted, after the same short wait, whatever was wrong; the reason goes to the log only, never the secret. The routes are registered here, not in routes.rs: they authenticate themselves (a container token never reaches them: its listener refuses a path with no audience).

StructsΒ§

CodeBody πŸ”’
ConfirmBody πŸ”’
HandleBody πŸ”’
HelloBody πŸ”’
Shape πŸ”’
What the running server accepts: set once the web listener is bound.

EnumsΒ§

Kind πŸ”’
Reason πŸ”’
Why a request was refused. For the log; the answer never says.

ConstantsΒ§

COOKIE_ONLY_GET πŸ”’
Routes that take the cookie alone: GETs that change nothing and that an element loads by URL. The UI fetches every file with its headers, so none needs it; each entry added here is a reviewed decision, and the test in tests/local_session_route_tests.rs holds it to a GET route.
COOKIE_PREFIX πŸ”’
The cookie’s name is this, then the instance id.
ENTER_CSS πŸ”’
ENTER_HTML πŸ”’
ENTER_JS πŸ”’
The code is in the fragment. The history entry loses it before anything is sent; the page then waits for the person’s answer in the terminal and keeps the token in sessionStorage only. A page opened with no code (a visitor with no session, or a browser that was disconnected) says how to open AgentMux and is no refusal: it is the same words for everyone and tells nothing about the server.
FAILURE_DELAY πŸ”’
A refused sign-in waits this long before it answers, in an async sleep.
MAX_DELAYED πŸ”’
At most this many refusals wait at once; beyond it a refusal answers at once.
TOKEN_HEADER πŸ”’
The per-tab token on a fetch.
WAIT_HOLD πŸ”’
How long a waiting page’s request is held before it asks again.
WS_PROTOCOL πŸ”’
The protocol srv selects on /ws; the other protocol the page offers is the token.

StaticsΒ§

CHANNELS πŸ”’
SHAPE πŸ”’
SHUTDOWN πŸ”’
What ends the server: the token the signal handlers cancel. agentmux stop on Windows, which has no signal to send, asks for it through /auth/shutdown.
STORE πŸ”’

FunctionsΒ§

admit_session πŸ”’
Does this request come from a live browser session? Host and Origin exact, and the cookie and token (or the cookie alone where listed, with Sec-Fetch-Site: same-origin).
channel_gate πŸ”’
open and the other commands: the shape of a non-browser caller, and a request that proves the caller holds the key on a channel it began with handle_hello. The key itself is never sent, and is not accepted on these routes.
channels πŸ”’
check_shape πŸ”’
Host is exactly an allowed one, Origin (where sent) is exactly an allowed origin, and Sec-Fetch-Site suits the kind. A missing or unreadable header counts as wrong.
content_security_policy πŸ”’
The policy of the served UI and the sign-in page. 'unsafe-inline' for styles only: the terminal and layout set inline styles. 'wasm-unsafe-eval' lets the code highlighter’s WebAssembly engine (Oniguruma, in shiki) compile and nothing else: scripts still come from this origin only, and eval of text stays refused. base-uri 'self' lets a library resolve a relative address against a base on this origin (the drag-preview picture does, for the fonts) and no other.
cookie_value πŸ”’
enable πŸ”’
Turn the sign-in on, once the web listener has its port. Only for a headless srv that serves a UI.
enabled πŸ”’
handle_code πŸ”’
POST /auth/code: a new one-time code.
handle_confirm πŸ”’
POST /auth/confirm {code, accept}: the person’s answer for the session that code made. An accept is taken only from a process found outside every agent’s process tree; one from an agent’s tree, from a process that cannot be found, or through a proxy is not taken (the answer says what works). Every accept, taken or not, is recorded with how it arrived (super::confirm_peer).
handle_enter πŸ”’
POST /auth/enter {code}: spends the code and makes a pending session; the answer is the handle to wait on and the check phrase to show. The session has no access yet.
handle_hello πŸ”’
POST /auth/hello {nonce}: srv proves to open that it holds the key and which address it is bound to, before open sends anything else. It asks for no secret, so anyone may call it; what it returns proves only what srv holds, and is made for this caller’s nonce alone.
handle_logout πŸ”’
POST /auth/logout: end every browser session.
handle_page πŸ”’
GET /auth/enter: the page. It holds no secret; the code is in the fragment, which is never sent.
handle_pending πŸ”’
POST /auth/pending {code}: what became of the code open minted.
handle_script πŸ”’
handle_sessions πŸ”’
POST /auth/sessions: how many browsers are signed in now, and how each recent confirm arrived (when, the session’s check phrase, how). Nothing that names or reaches a session.
handle_shutdown πŸ”’
POST /auth/shutdown: end the server, as a termination signal does. The answer is sent first; the server leaves a moment later, by the same path as the signal (every request in flight and every agent is closed as it is then).
handle_signout πŸ”’
POST /auth/signout: end this browser’s session, and no other. It takes the session pair like any route of the UI, from a same-origin fetch of the page; srv also tells the browser to drop the cookie.
handle_signout_all πŸ”’
POST /auth/signout-all: end every browser session, this one included, and clear the file that keeps them across a restart. It takes the session pair like any route of the UI, so a signed-in person can end every sign-in without a shell on the machine.
handle_style πŸ”’
handle_wait πŸ”’
POST /auth/wait {handle}: held until the person answers in the terminal. A confirmed session is handed over once, here: the cookie in Set-Cookie and the token in the body.
hval πŸ”’
is_websocket_route πŸ”’
The routes a browser opens as a WebSocket, which can carry no header: the token travels as a protocol.
no_store πŸ”’
proved πŸ”’
A 200 answer that carries the proof of the channel for the request it answers.
refusal πŸ”’
refuse πŸ”’
The same 403 for every refusal, in the same time: the wait is the same for every reason.
route_class πŸ”’
How a route takes a session. Every route needs the cookie and the token, except the GETs named in COOKIE_ONLY_GET.
routes πŸ”’
The /auth/* routes.
session_ended πŸ”’
Completes when the browser session behind a WebSocket ends; never for a connection that came with the key.
session_token πŸ”’
The token a request carries: X-AM-Session, or on a WebSocket route the protocol offered beside WS_PROTOCOL.
set_shutdown πŸ”’
Give the shutdown route the token that ends the server.
sign_in_exists πŸ”’
Whether something here can vouch for a browser’s connection as the person’s: this srv serves its own sign-in, or a browser has signed in.
store πŸ”’
ui_headers πŸ”’
Middleware for the served UI’s files.
ui_host_ok πŸ”’
Is the UI’s file asked for on an address this server serves? The files hold no secret, but a name that is not the server’s own (a DNS-rebinding page, a stray alias) gets nothing from it: the same rule as the sign-in and API routes.
with_ui_headers πŸ”’