@davoodmehraban89 / Aram-2 Mirror · read-only
Fork 0

Mirrored from https://github.com/davoodmehraban89/Aram.git

Synced Dec 4, 18:00 UTC

dependabot/npm_and_yarn/frontend/vitest-5.1.2
add-index-html-10623938925177053894 arena/094f314c-aram arena/2d4eda07-aram chatgpt-phase1b2-autopilot codex/adr-future-connectors-pi-v1 codex/aram-account-note-source-trace-20261031 codex/aram-actions-node24-maintenance-20261031 codex/aram-analyst-review-workbook-20261031 codex/aram-bs-candidate-statement-20261031 codex/aram-cash-flow-direct-candidate-20261031 codex/aram-clean-reference-year-integrity-20261030 codex/aram-cross-statement-controls-20261031 codex/aram-equity-changes-candidate-20261031 codex/aram-five-statement-cli-20261031 codex/aram-five-statement-integration-20261031 codex/aram-five-statement-orchestrator-20261031 codex/aram-gate3-coverage-target-guard-20261030 codex/aram-gate3-hidden-xlsx-guard-20261030 codex/aram-gate3-integration-validation-20261030 codex/aram-gate3-mapping-change-preview-20261030 codex/aram-gate3-stale-note-guard-20261030 codex/aram-income-statement-candidate-20261031 codex/aram-manifest-referential-integrity-20261031 codex/aram-mapping-source-parser-20261101 codex/aram-multidimensional-mapping-20261101 codex/aram-multistatement-mapping-20261031 codex/aram-pipeline-manifest-schema-20261031 codex/aram-readonly-mapping-coverage-20261031 codex/aram-reconciliation-review-gate-20261031 codex/aram-same-flush-fiscal-lock-20261030 codex/aram-synthetic-windows-demo-20261031 codex/aram-trial-balance-diagnostic-20261031 codex/aram-windows-background-detail-search-20261031 codex/aram-windows-detail-review-20261031 codex/aram-windows-five-statement-pilot-20261031 codex/aram-windows-statement-figures-20261031 codex/gate-2a-pilot-workbook codex/gate-2a-pilot-workbook-6864754244772568979 codex/gate3-authenticated-principal-boundary-20261030 codex/gate3-authored-draft-staging-20261030 codex/gate3-carry-forward-preview-20261023 codex/gate3-draft-staging-audit-20261030 codex/gate3-mapping-batch-freshness-20261030 codex/gate3-mapping-batch-review-20261030 codex/gate3-mapping-core codex/gate3-mapping-coverage-20261023 codex/gate3-mapping-excel-20261023 codex/gate3-note-mapping-review-20261023 codex/gate3-signed-year-scope-20261030 codex/gate3-unapproved-proposal-storage-20261030 codex/payvast-mapping-discovery-20261023 codex/phase-2a-backend-foundation codex/phase-2b-post-merge-record codex/phase-2b-source-registration codex/phase-2b-source-registration-12955190277775369594 codex/post-gate2a-control-reconciliation codex/post-pr18-acceptance-record codex/project-control-foundation codex/t1-repo-hygiene-20261023 codex/t2-ci-hardening-20261023 codex/t3-explicit-migrations-20261023 codex/t6a-readonly-diagnostics-20261023 codex/v1-01-safety-gate-hardening codex/v1-year-isolation-followup-20261023 codex/windows-native-pilot-shell-20261030 dependabot/github_actions/actions/setup-node-6 dependabot/github_actions/actions/setup-python-7 dependabot/github_actions/actions/upload-artifact-7 dependabot/npm_and_yarn/frontend/eslint-plugin-react-hooks-7.1.1 dependabot/npm_and_yarn/frontend/vite-8.4.0 dependabot/npm_and_yarn/frontend/vitest-5.1.2 docs/aram-master-control-plan-20261111 docs/aram-roadmap-dashboard-20261030 docs/financial-statement-reconciliation-1402-1404-20261110 feat/gate3-governed-mapping-20261101 feat/gate3-package9-1-security-20261103 feat/gate3-package9-isolated-20261103 fix/password-unicode-validation-20261111 governance/aram-5-1-3-controls-20261030 governance/role-based-operating-model jules-1168663913887856558-73b8a885 jules-gate-2b-mapping-workflow-foundation-4137724387867065330 phase-1b1-audit-report-7365389436990903239 phase-2a-backend-foundation-10237597358138521261 phase1b2-postmerge-metadata-fix refactor/drg-parent-year-id-15088443704684163304 source-data-cleanup
md 83 lines 5.28 KB
Rendered Raw
1 # ADR-030 — R1 real authentication: parameters and boundary decisions
2
3 - Status: Accepted (R1, booklet 2.1)
4 - Date: 2026-12-04
5 - Booklet: 2.1 §1 (no deferral of security defects) + R1; booklet 1 §7/§12. Supersedes the
6 Phase 7 "bootstrap/dev" exemptions in `approve` and the client-supplied `actor`.
7
8 ## Context
9
10 Before R1 anyone reaching the port could approve a year with `{"actor": "admin"}`, and with
11 zero users the role gate was skipped entirely. Login issued no credential; the legacy pilot
12 exposed 17 unauthenticated routes at `/`; backup `dest` was unvalidated; the desktop launcher
13 had no local token. The owner delegated **N** and the **token lifetime** to the agent.
14
15 ## Decision — credentials
16
17 **Hashing: PBKDF2-HMAC-SHA256, 600,000 iterations.** `argon2`, `argon2-cffi`, `passlib`
18 and `bcrypt` are absent and booklet 2 §16 forbids new runtime dependencies offline, so
19 R1's fallback applies: 200,000 → **600,000** (OWASP floor), measured **0.199 s** per hash
20 here. `users.password_rounds` stores it per row: pre-R1 hashes stay verifiable and are
21 **rehashed to 600,000 on first successful login**. Salt handling is unchanged
22 (`bytes.fromhex(salt)`), so no password reset is forced.
23
24 **Failed attempts: N = 5, lockout 15 minutes.** An offline single-user tool has no
25 legitimate reason for five consecutive failures. After the 5th the account locks for
26 **15 minutes** and even the correct password is refused; counter and lock clear on a
27 successful login after expiry. Lockout is per account, not per IP: the threat model is a
28 local process. Unknown usernames burn the same work factor and return the identical
29 Persian message, so timing and text reveal nothing. `auth.locked` is audited.
30
31 **Session token: 256 random bits, hash-only storage, 8-hour absolute TTL.**
32 `secrets.token_urlsafe(32)` is returned **once**; only `SHA-256(token)` is stored in
33 `auth_sessions`, so the plaintext never touches database, log or URL. Lifetime is **8
34 hours absolute** — one shift, **no sliding renewal**, so a stolen token cannot be kept
35 alive by use. Logout sets `revoked`; deactivating a user revokes all their sessions.
36 Expired, revoked, unknown and malformed tokens all yield 401 with `WWW-Authenticate:
37 Bearer`. A bearer token rather than a cookie is deliberate: the browser never sends it
38 automatically, so there is no CSRF surface. The client keeps it in `sessionStorage`
39 (never `localStorage`, never disk).
40
41 ## Decision — boundaries
42
43 **One dependency, four exemptions.** `current_user` in `aram_backend/auth.py` is the only
44 source of identity, attached at router level (statements, admin, schema, pilot) so new
45 routes are protected by default. Exactly four routes work without a session:
46 `GET /health` (readiness, no data), `POST /auth/login` (establishes the session),
47 `POST /auth/launch` (exchanges the one-time desktop token) and `POST /users` (**only
48 while zero users exist**). `bootstrap_guard` runs before body validation on `/users`, so
49 once any user exists it answers 401 even for a malformed body. The first user is forced
50 to ADMIN and the bootstrap cannot repeat; logout and all reads need a session too.
51 Approval **without users is impossible**: the `if list_users(session)` shortcut is deleted
52 and the role gate runs before the year-existence check. `actor` is gone from every request
53 model; the audit log is attributed to the authenticated username.
54
55 **Backup `dest` confined.** `confine_dest` resolves the path (expanding `~`, following
56 symlinks) and refuses anything not strictly inside the allowed root: `..` traversal,
57 outside absolute paths and symlink escapes are rejected after resolution. The root
58 defaults to the parent of `source_store_root`, narrowed by `ARAM_BACKUP_ROOT`; both
59 `/backup` and `/backup/verify` enforce it.
60
61 **Desktop one-time local token.** The launcher arms a random 256-bit token and opens
62 `http://127.0.0.1:<port>/#launch=<token>`. The **fragment** never travels over HTTP nor
63 reaches access logs. The page exchanges it once at `/auth/launch` for a grant, scrubs the
64 fragment with `history.replaceState`, and sends the grant in `X-Aram-Launch` on every
65 call. A replay cannot mint a second grant; without it another local process cannot reach
66 even bootstrap or login. `/health` stays open.
67
68 **Legacy surfaces and frontend.** `pilot_api`'s router, the `/pilot` mount and the HTML
69 formerly at `/` are removed from `main.py`; the router module keeps the same `current_user`
70 dependency, so it can never be anonymous if mounted again (a test-only app covers it).
71 `/docs`, `/redoc` and `/openapi.json` are disabled in both apps: they are endpoints, and
72 only the four above are exempt. `static/pilot` and `pilot_api.py` stay in the tree
73 (unserved, unimported) to respect the size cap. The workbench sits behind `LoginPanel`;
74 `client.ts` attaches `Authorization` (and `X-Aram-Launch`) to every request and clears the
75 session on any 401. Export links were plain `<a href download>`, which cannot carry a
76 header — they are now authenticated `fetch` + blob downloads, so no token is put in a URL.
77
78 ## Consequences
79
80 Migration `20261204_08` adds `auth_sessions` + three `users` columns; verified on a copy
81 of a populated DB (131,280 ledger rows, 2 users, 28 triggers unchanged, legacy rows keep
82 `password_rounds = 200000` until first login). R4 owns replacing `create_all` with
83 `alembic upgrade head` at startup; until then an existing DB needs it applied once.