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

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

Synced Dec 4, 14:15 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/checkout-7 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/globals-17.15.0 dependabot/npm_and_yarn/frontend/vite-8.4.0 dependabot/npm_and_yarn/frontend/vitest-5.1.2 dependabot/npm_and_yarn/frontend/vitest/coverage-v8-5.1.2 dependabot/pip/backend/mypy-gte-1.13-and-lt-3 dependabot/pip/backend/pytest-cov-gte-6.0-and-lt-8 dependabot/pip/backend/setuptools-gte-75-and-lt-85 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 5.28 KB

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 approve and the client-supplied actor.

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.