ADRs 0023 (model), 0011 (authn/authz), 0019 (op validation), 0020 (limits), 0301-0305 (API service). Every tier owner is responsible for the controls in its tier; changes to auth or limits need a security review (CONTRIBUTING).
| Control | Where | How |
|—|—|—|
| Password storage | API | argon2id (crypto.argon2, m=64 MiB, t=3, p=1), PHC string, constant-time compare; at most LINORA_ARGON2_CONCURRENCY (2) hashes at once with a bounded queue (503 beyond), dummy verify for unknown accounts, rehash on login when parameters rise |
| Browser sessions | API | 256-bit cookie token, SHA-256 at rest, __Host-linora_session HttpOnly Secure SameSite=Lax (production; linora_session in dev; also linora_session without Secure, but only for requests whose Host is a plain-HTTP LAN origin listed in LINORA_COOKIE_INSECURE_ORIGINS, which other hosts never accept, ADR 0905), 30-day sliding (written <= 1/h), a presented old session is deleted on login/signup (rotation); logout revokes on every replica via linora_auth; users list their sessions and revoke one or all others (/v1/me/sessions, session-only, audited, closes realtime sockets; ADR 0307) |
| CSRF | API | SameSite=Lax + JSON-only bodies + allowed Origin (required on every cookie-authenticated non-GET, and checked when present on signup/login) + X-CSRF-Token equal to the session’s server-stored 256-bit secret (delivered in the X-CSRF-Token response header of signup/login/me and the readable linora_csrf cookie); credentialed CORS only for LINORA_ALLOWED_ORIGINS |
| Agent credentials | API | PATs linora_pat_..., SHA-256 at rest, shown once, scopes, project allow-list (members only), expiry, revocable (every API replica within 1 s via linora_auth, tested), last_used_at (batched), max 100 active per user; PATs cannot manage tokens or log out, allow-listed PATs cannot create projects |
| Realtime auth | realtime | HMAC-SHA256 tokens, 5-min TTL, bound to user+file+role(+scopes), verified at upgrade before any allocation; kid rotation; denylist for revoked credentials |
| Token keys per purpose | all | one HKDF-derived key per purpose (rt, cg, svc:api, svc:docworker); each tier holds only its purposes (LINORA_TOKEN_KEYS_*) and refuses to start without them, so a doc worker cannot mint user tokens (SR-07, ADR 0310) |
| Database roles | all | one least-privilege role per tier (linora_api, linora_realtime, linora_docworker, linora_compactor, migration 0002): column grants enforce ADR 0021 write ownership; doc workers are read-only; only the API reads accounts and credentials (SR-07, ADR 0310) |
| Authorization | API, realtime, doc workers | each route declares scope + minimum role; role from project membership of the path’s project/file; realtime re-checks per OPS frame; doc workers accept only internal requests |
| Tenant isolation | all | every query filters by project membership; ids in paths never grant access; tests hit every route with a foreign tenant’s ids |
| Op validation | realtime | ScanBatch (types, ranges, sizes, UTF-8, keys, id ownership) + StructIndex (existence, cycles, kinds); rejected ops never journaled or broadcast |
| Prototype-safe input | API, doc workers, MCP | bodies come from JSON.parse and query strings are built with Object.fromEntries, so client keys are own data properties and never reach a setter such as __proto__; schema validation (shared validate, the MCP’s validateArgs) looks up own keys only, so __proto__, constructor and other Object.prototype names are unknown fields (400) |
| SQL injection | all | postgres.js tagged templates only; unsafe() banned outside migrations (lint); the API validates every uuid/email format before it reaches a query and treats malformed path ids as 404 |
| Resource limits | all | body sizes, ops/batch, blob/string/key sizes, nodes/page, pages/file; token buckets per connection, user, PAT, IP; connections per user/IP; send-buffer caps; structural-index and ring budgets; doc-worker and compactor memory caps |
| Audit | API | audit_log (written in the same transaction as the change): project.create/delete, member.add/role/remove, token.create/revoke, session.revoke/revoke_others, file.delete, page.delete; login.failed aggregated per (email, IP) per minute (first failure written at once, the rest as one row with count) |
| API request limits | API | token buckets, global across replicas (ADR 0306), per IP (100/s; IPv6 by /64; X-Forwarded-For only from LINORA_TRUSTED_PROXIES), user (50/s, across all sessions and PATs), PAT (50/s); signup/login 10 then 1/6 s per IP; failed logins 10 then 1/min per (account, client) + 100/h per account; nodes/search 5/s per user, 1 in flight per user / 4 per IP; body caps per route (16 KiB default, 4 MiB binary ops); process-wide body budget (64 MiB, 503 beyond); header/request timeouts 10/30 s; 16 KiB headers |
| Transport | edge | TLS 1.2+, HSTS, WSS only; private network for internal links. The outermost proxy replaces X-Forwarded-For with the peer address (prod-like edge, ADR 0905). The local prod-like stack is plain HTTP on 127.0.0.1; its opt-in LAN mode is plain HTTP on the LAN (ADR 0905) |
| Secrets | all | env only (LINORA_TOKEN_KEYS or per-purpose LINORA_TOKEN_KEYS_*, DATABASE_URL per tier role, LINORA_S3_ACCESS_KEY_ID/LINORA_S3_SECRET_ACCESS_KEY); .env gitignored; refuse to start without them; an unset NODE_ENV means production (secure defaults, SR-17), where the dev passwords published in the repo are refused (ADR 0906) |
| Browser hardening | web | strict CSP (self scripts only), frame-ancestors none, nosniff, Referrer-Policy |
| Threat | Example | Mitigation |
|—|—|—|
| Malicious client | crafted frames, oversized blobs, NaN coordinates, cycles, foreign ids, op floods | zero-copy validation with hard bounds before any state change; structural checks; per-op rejection; token buckets per connection/user; ids must be in the sender’s clientId space; deterministic no-op apply as a second line on replicas |
| Stolen session cookie | XSS or malware on the user’s machine | HttpOnly + CSP limit XSS; sessions listed and revocable; rotation on privilege change; short realtime tokens limit socket reuse |
| Sniffing on a shared network | the prod-like stack in LAN mode (plain HTTP): someone on the same Wi-Fi reads a password or the non-Secure LAN session cookie | opt-in only (LINORA_PROD_LAN_HOSTS, local stack, never production); non-Secure cookies only for the listed LAN hosts, never for 127.0.0.1/localhost; the user turns LAN mode off on untrusted networks and can revoke sessions (/v1/me/sessions); HTTPS with a local CA is the follow-up (ADR 0905) |
| Stolen PAT | leaked in a script or log | hashed at rest, shown once, scopes + project allow-list + expiry, last_used_at, instant revoke (closes sockets via NOTIFY) |
| Stolen realtime token | copied from a WS handshake | 5-min TTL, bound to one file and role, useless for REST; credential revocation enters the denylist |
| Resource exhaustion | 100k sockets from one IP, slowloris, huge batches, slow readers, page bombs | per-IP/user connection caps, upgrade-time auth, idle timeout, message size caps, nodes/page cap, send-buffer hard cap, busy backpressure, memory budgets with LRU in every stateful tier |
| Account enumeration (SR-19) | signup 409, addMember 404/409 | invite-only sign-up in production checked before any lookup (SR-21); addMember lookups rate-limited per user (global buckets); full fix (always “check your email”) needs email verification (wave 4) |
| CPU exhaustion of shared doc workers (SR-01) | catastrophic nameRegex over a page of long distinct names, any runaway query | nameRegex only on V8’s linear engine (validated by the executor’s own rule), 256-char name window, 100 ms find budget with resumable cursors, 2 s wall-clock guard per query (503, metric), per-user search rate + 1 in flight per user / 4 per IP (ADR 0704) |
| Cross-tenant access | guessing file/page ids, PAT for project A used on project B | membership check on every route and token mint; PAT project allow-lists; realtime token bound to one file; doc workers unreachable from outside |
| Privilege drift | removed member keeps an open socket | NOTIFY linora_auth closes/downgrades sockets within 1 s; tokens re-minted only after a membership check |
| Data loss | crash between receive and commit | ACK only after commit; clients resend pending batches; snapshots + retention for recovery |
apps/api/test)| Threat | Test |
|—|—|
| Cross-tenant access | tenancy.test.ts: every route in API called anonymously (401), by a foreign tenant and a foreign PAT (404), by members below the route’s role (403), by a PAT without the scope (403) and by a PAT allow-listed to another project (404); owner data unchanged afterwards; malformed ids 404 |
| Stolen or revoked token | tokens.test.ts: revoked PAT rejected at once locally and on a second replica within 1 s; expired, forged and malformed PATs 401; disabled accounts; PATs cannot mint tokens. auth.test.ts: logout invalidates a copied cookie on every replica; login rotation kills the old cookie. sessions.test.ts: a revoked session is refused by another replica in ms, foreign session ids 404, PATs 403; pipeline.test.ts: its realtime socket closes in ~10 ms |
| CSRF | auth.test.ts: missing/wrong X-CSRF-Token, foreign or missing Origin, form-encoded bodies, DELETE without token, login from a foreign origin; CORS only for allowed origins |
| Oversized input | limits.test.ts: 413 on declared and chunked bodies, binary op cap, body budget 503, schema/format/query validation, SQL injection payloads inert |
| Prototype keys | units.test.ts: __proto__, constructor, toString in a query string stay own keys and are rejected as unknown fields; shared/test/schema.test.ts: the same keys in a JSON body |
| Rate limits / brute force | limits.test.ts: IP, user and PAT buckets with Retry-After; auth.test.ts: account lockout after 10 failures, per-IP auth bucket, argon2 queue bound, aggregated login.failed audit rows; global-limits.test.ts: buckets shared by two replicas, spoofed X-Forwarded-For ignored from untrusted peers, IPv6 /64 buckets, lockout per (account, client) + per-account cap, eviction never resets a depleted bucket |
CodeQL (security-extended) scans every push to main, every pull request and once a week (.github/workflows/codeql.yml). Alerts are fixed, or dismissed in code scanning with a written reason; the first triage is in the security review.
Email verification and password reset, MFA, SSO/OAuth (including MCP OAuth 2.1), mTLS between tiers, per-file sharing links, encryption of blobs at rest beyond the provider default.