Mirrored from https://github.com/davoodmehraban89/Aram.git
Synced Dec 4, 14:15 UTC
dependabot/npm_and_yarn/frontend/vitest-5.1.2
ADR-030 — R1 real authentication: parameters and boundary decisions
- Status: Accepted (R1, booklet 2.1)
- Date: 2026-12-04
- Booklet: 2.1 §1 (no deferral of security defects) + R1; booklet 1 §7/§12. Supersedes the
Phase 7 "bootstrap/dev" exemptions in
approveand the client-suppliedactor.
Context
Before R1 anyone reaching the port could approve a year with {"actor": "admin"}, and with
zero users the role gate was skipped entirely. Login issued no credential; the legacy pilot
exposed 17 unauthenticated routes at /; backup dest was unvalidated; the desktop launcher
had no local token. The owner delegated N and the token lifetime to the agent.
Decision — credentials
Hashing: PBKDF2-HMAC-SHA256, 600,000 iterations. argon2, argon2-cffi, passlib
and bcrypt are absent and booklet 2 §16 forbids new runtime dependencies offline, so
R1's fallback applies: 200,000 → 600,000 (OWASP floor), measured 0.199 s per hash
here. users.password_rounds stores it per row: pre-R1 hashes stay verifiable and are
rehashed to 600,000 on first successful login. Salt handling is unchanged
(bytes.fromhex(salt)), so no password reset is forced.
Failed attempts: N = 5, lockout 15 minutes. An offline single-user tool has no
legitimate reason for five consecutive failures. After the 5th the account locks for
15 minutes and even the correct password is refused; counter and lock clear on a
successful login after expiry. Lockout is per account, not per IP: the threat model is a
local process. Unknown usernames burn the same work factor and return the identical
Persian message, so timing and text reveal nothing. auth.locked is audited.
Session token: 256 random bits, hash-only storage, 8-hour absolute TTL.
secrets.token_urlsafe(32) is returned once; only SHA-256(token) is stored in
auth_sessions, so the plaintext never touches database, log or URL. Lifetime is 8
hours absolute — one shift, no sliding renewal, so a stolen token cannot be kept
alive by use. Logout sets revoked; deactivating a user revokes all their sessions.
Expired, revoked, unknown and malformed tokens all yield 401 with WWW-Authenticate:
Bearer. A bearer token rather than a cookie is deliberate: the browser never sends it
automatically, so there is no CSRF surface. The client keeps it in sessionStorage
(never localStorage, never disk).
Decision — boundaries
One dependency, four exemptions. current_user in aram_backend/auth.py is the only
source of identity, attached at router level (statements, admin, schema, pilot) so new
routes are protected by default. Exactly four routes work without a session:
GET /health (readiness, no data), POST /auth/login (establishes the session),
POST /auth/launch (exchanges the one-time desktop token) and POST /users (only
while zero users exist). bootstrap_guard runs before body validation on /users, so
once any user exists it answers 401 even for a malformed body. The first user is forced
to ADMIN and the bootstrap cannot repeat; logout and all reads need a session too.
Approval without users is impossible: the if list_users(session) shortcut is deleted
and the role gate runs before the year-existence check. actor is gone from every request
model; the audit log is attributed to the authenticated username.
Backup dest confined. confine_dest resolves the path (expanding ~, following
symlinks) and refuses anything not strictly inside the allowed root: .. traversal,
outside absolute paths and symlink escapes are rejected after resolution. The root
defaults to the parent of source_store_root, narrowed by ARAM_BACKUP_ROOT; both
/backup and /backup/verify enforce it.
Desktop one-time local token. The launcher arms a random 256-bit token and opens
http://127.0.0.1:<port>/#launch=<token>. The fragment never travels over HTTP nor
reaches access logs. The page exchanges it once at /auth/launch for a grant, scrubs the
fragment with history.replaceState, and sends the grant in X-Aram-Launch on every
call. A replay cannot mint a second grant; without it another local process cannot reach
even bootstrap or login. /health stays open.
Legacy surfaces and frontend. pilot_api's router, the /pilot mount and the HTML
formerly at / are removed from main.py; the router module keeps the same current_user
dependency, so it can never be anonymous if mounted again (a test-only app covers it).
/docs, /redoc and /openapi.json are disabled in both apps: they are endpoints, and
only the four above are exempt. static/pilot and pilot_api.py stay in the tree
(unserved, unimported) to respect the size cap. The workbench sits behind LoginPanel;
client.ts attaches Authorization (and X-Aram-Launch) to every request and clears the
session on any 401. Export links were plain <a href download>, which cannot carry a
header — they are now authenticated fetch + blob downloads, so no token is put in a URL.
Consequences
Migration 20261204_08 adds auth_sessions + three users columns; verified on a copy
of a populated DB (131,280 ledger rows, 2 users, 28 triggers unchanged, legacy rows keep
password_rounds = 200000 until first login). R4 owns replacing create_all with
alembic upgrade head at startup; until then an existing DB needs it applied once.