Linora

0023. Security model

Status: Accepted (2026-11-27). Details and threat model: ../architecture/security.md.

Decision

  1. Passwords: argon2id via Node’s built-in crypto.argon2 (m=64 MiB, t=3, p=1, 16-byte salt, PHC string). Constant-time compare; generic “invalid credentials”.
  2. Browser sessions: 256-bit random token in linora_session cookie (HttpOnly; Secure; SameSite=Lax; Path=/, __Host- prefix in production), stored as SHA-256 only, 30-day sliding expiry, rotated on login and privilege change. CSRF: SameSite=Lax + mutating requests must be JSON (Content-Type: application/json) with an allowed Origin, plus a double-submit X-CSRF-Token for all non-GET routes.
  3. Realtime tokens: HMAC-SHA256 signed, 5-minute TTL, bound to user + file + role (+ PAT scopes); verified in memory at WS upgrade (no DB). Key rotation via kid. Revocation: API NOTIFY -> realtime closes affected sockets; a denylist of revoked credential ids is kept for one token TTL.
  4. Personal access tokens: linora_pat_ + 32 random bytes, SHA-256 at rest, shown once, scopes (files:read, files:write, projects:admin), optional project allow-list and expiry, last_used_at, revocable.
  5. Authorization on every op and query: each route declares scope and minimum role (shared/src/api.ts); role is resolved from project membership of the path’s project/file (tenant isolation). Realtime: role and scopes come from the signed token and are re-checked on every OPS frame (viewer -> read_only). Role changes and removals push file_event and close or downgrade sockets.
  6. SQL: parameterized only (postgres.js tagged templates); no string-built SQL; a lint rule bans unsafe() outside migrations.
  7. Limits: request body size per route, ops per batch, blob/string/key sizes, nodes per page, pages per file (limits.ts); token buckets per connection, user, PAT and IP (login and signup stricter); WS connections per user and per IP.
  8. Audit log: append-only audit_log for membership, role, token, project/file deletion and login failures (rate-aggregated); readable by project owners.
  9. Transport: TLS 1.2+ at the edge in production, HSTS, secure WebSocket only; internal traffic on a private network (mTLS optional later).
  10. Secrets: from environment (LINORA_TOKEN_KEYS, DATABASE_URL, blob credentials), never committed; .env is gitignored; startup fails if missing.
  11. Headers: strict CSP for the web app (scripts from self only), X-Content-Type-Options, Referrer-Policy, frame-ancestors none.

Alternatives

JWT sessions for the browser (revocation harder), Ed25519 realtime tokens (only needed if third parties verify; 50x slower), OAuth for MCP now (PATs first; OAuth 2.1 later per MCP spec).

Consequences

Every new route must declare scope + role; a test enforces it (shared/test/schema.test.ts). Security review is part of CONTRIBUTING for auth/limits changes.