SPB Git

Repository Public

SECURITY.md 9.9 KB

# Security

Scope: the public site (read-only, anonymous) and the private studio under /admin (passkeys, uploads, media pipeline). This document describes what is implemented and tested in this repository; the gateway (TLS, HTTP/2, rate limiting at the edge) is outside it and was not verified. No external security review or penetration test has been done.

# Controls in place

Area Control Where Verified by
Learners No account, no cookie, no analytics, no third-party request. The studio's cookies are scoped to /admin: the public pages never receive, read or set one. guard.ts e2e: context.cookies() empty after every anonymous journey; the editor's cookie is not sent to /programme
Authentication Passkeys only (WebAuthn, user verification required, discoverable credentials). No password. First enrolment by a one-time token produced in the server's shell; token stored as SHA-256, 30 min, single use, one live token per editor. src/server/auth.ts, scripts/studio.ts studio-auth.test.ts; e2e with a virtual authenticator
Sessions Server-side; cookie = random 256-bit token (database keeps its SHA-256); HttpOnly, SameSite=Strict, Secure on HTTPS, Path=/admin; 12 h absolute, 2 h idle; new identifier at every sign-in; revocable; die when an editor is disabled or a passkey revoked. auth.ts, guard.ts unit + e2e
Replay A WebAuthn challenge is single-use, 5 min, bound to the browser that asked (HttpOnly pre-auth cookie); a closed session's cookie and CSRF token are dead; content writes carry a revision and a stale one is refused (409). auth.ts, content.ts unit + e2e
Brute force 30 auth requests/min per address; lock-out after 5 refused sign-ins per address per hour (1 min, 5 min, 1 h), derived from the audit log so it survives restarts; 240 writes/min and 3000 upload pieces/min per session. In memory, per process. http.ts, auth.ts unit + e2e
CSRF Every state-changing request: same Origin, Sec-Fetch-Site same-origin, and the session's token in x-csrf-token. guard.ts e2e: 24 write routes × foreign origin, cross-site, missing token, wrong token → 403
Authorisation One dispatcher for the whole private API: session and permission are checked before any handler; every private page calls requireEditorPage. Roles owner / publisher / author. An anonymous caller gets 401 for any path, existing or not. src/lib/studio/api.ts, guard.ts e2e: 15 reads + 24 writes anonymous → 401; author → 403 on publish, access, export
Indexing, caching /admin/**: X-Robots-Tag: noindex, Cache-Control: private, no-store, robots metadata, Disallow: /admin, absent from the sitemap. next.config.ts, layouts e2e
Publication gate The public site is built only from immutable publications that are due, through buildView. Drafts, previews, scheduled entries, private items, solutions and quiz answers of unpublished sessions are not in the manifest the public code receives. publish.ts, publication.ts, content.ts studio-publication.test.ts; e2e by URL, search index, sitemap, API, media; pnpm leak-check (build scan + live crawl of 252 URLs)
Media A file under /media/ is served only if a live publication names it (exact files, or the directory of its HLS playlist). Each encode and each caption file has its own name; masters, uploads and scratch space are never served. mediaAllowed, uploads.ts, worker.ts unit + e2e (404 before publication and after withdrawal)
Uploads Pieces of 4 MiB, SHA-256 per piece, fingerprint and whole-file hash on assembly; type by magic bytes vs extension allow-list; size limits per purpose; file names reduced to a harmless base name; storage budget; nothing executable accepted (no html, svg, sh, exe…). Downloads are sent as attachments with nosniff and a sandboxing CSP. uploads.ts, magic.ts, serve.ts studio-media.test.ts, studio-captions.test.ts, e2e (disguised files)
Archives Own extractor for zip and tar.gz: traversal names refuse the archive; links, devices and odd names are skipped; limits on entries, per-file and total size counted on inflated bytes, compression ratio; never overwrites; encrypted and ZIP64 refused. archive.ts studio-archive.test.ts (forged archives)
Slides Built from the public web PDFs by poppler (fixed arguments, no shell, on copies); packs validated file by file (checksums, SVG inspected, names by pattern); served only for a published deck, as images under a sandboxing CSP. Speaker notes are never read; a leak test looks for them in decks, database, search index and pages. slides.ts, slides-serve.ts studio-slides.test.ts, e2e/slides.spec.ts, pnpm leak-check
Imported content Read as data: YAML core schema, size limits, confined paths, no execution, solution/ never opened; SVG rejected if active. importer.ts, adapter.ts importer.test.ts, studio-sync.test.ts
XSS Markdown rendered without raw HTML; links http(s) only; images dropped; KaTeX with trust off; highlighting by class names. Same component for the studio preview and the public page. JSON sections validated by schema and rendered by React. Markdown.tsx markdown.test.ts, e2e (script/onerror/javascript: probes)
SQL injection Parameterised statements everywhere; the only interpolated SQL is the backup path (refused if it contains a quote) and fixed placeholder lists. db.ts review
Path traversal isSafeRelPath + realpath containment (FsStorage); identifiers matched by strict patterns in the API routes. storage, api.ts e2e (encoded .. on 13 routes)
SSRF The server makes no outbound request; the link checker validates external URLs syntactically and never fetches them. ops.ts by construction
ffmpeg Started without a shell, fixed arguments, input = the stored master only; time limit, bounded concurrency, killed by PID; duration limit; output in scratch space then moved. transcode.ts, worker.ts unit
Secrets, logs No secret in the repository or the client bundle; structured logs redact tokens, cookies, CSRF, authorization, challenges; the audit log stores hashes and snapshots, never tokens. log.ts, audit.ts pnpm secret-scan, bundle scan in leak-check, unit, e2e (journal searched for the cookie, CSRF token and enrolment token)
Headers CSP default-src 'self' with no remote origin, frame-ancestors 'none', nosniff, HSTS, COOP, Referrer-Policy, Permissions-Policy. next.config.ts e2e
Dependencies Lockfile; pnpm audit (all dependencies) on 2026-11-22: no known vulnerability, after pinning KaTeX to 0.19.1 (GHSA-238p-pmpm-9mq7 in the copy rehype-katex brought). pnpm-workspace.yaml pnpm audit
Clean checkout A guard fails when a source file is git-ignored or untracked, and type-checks a git archive HEAD export. scripts/clean-checkout-check.sh pnpm clean-check

# Threat model

Threat Treatment Residual risk
Stolen or guessed admin credential No shared secret exists; a passkey needs the device and its biometric/passcode. A stolen unlocked device; a synced passkey in a compromised cloud account. Mitigation: revoke in Accès, recovery link.
Enrolment link intercepted Single use, 30–60 min, shown once. Whoever uses it first gets the role: send it over a trusted channel; check Accès afterwards.
Session theft HttpOnly, Strict, Secure, path-scoped; server-side expiry and revocation. Malware on the editor's machine.
CSRF / cross-origin writes Origin + fetch-metadata + token. —
XSS in authored or imported content No raw HTML anywhere; schema-validated JSON. script-src 'unsafe-inline' remains in the CSP (Next's inline bootstrap, no nonce): an HTML-injection flaw, if one existed, would not be stopped by the CSP.
Malicious editor Roles; audit log of every change with before/after; publications are immutable and reversible. An owner can do everything; an author can upload large files up to the limits. The audit log lives in the same database as the data it audits.
Leaking unpublished material Single gate, immutable snapshots, exact media permission, leak check. Titles, outcomes and tags of the plan are public by design once the plan is published.
Malicious upload (video, PDF, ZIP) Content check, no execution, attachment downloads; ffmpeg only parses stored masters. A crafted video could exploit a vulnerability in ffmpeg's demuxers/decoders: the worker is a separate process but not sandboxed (same user, same filesystem). No antivirus scan. PDFs are not inspected beyond their header. Only authenticated editors can upload.
Zip bomb / slip Limits and refusals above. ZIP archives are read into memory (≤ ATLAS_MAX_ARCHIVE_MB, 300 MB).
Denial of service Rate limits on auth and writes; streamed media with ranges; bounded concurrency and time for encodes. Public pages are rendered per request with no rate limit of their own: protection against floods is the gateway's. Limits are per process and reset on restart.
Prompt injection in imported material No model reads the content. Would matter only if an AI feature were added.
Supply chain Lockfile, audit, two packages allowed to run install scripts. —
Loss of the node Backup and restore scripts, tested drill. No scheduled or off-node backup exists yet.

# Accepted limitations and open items

  • CSP with 'unsafe-inline' for scripts and styles (unchanged from Phases 1–3).
  • The worker is isolated as a process, not sandboxed (no sandbox-exec, container or separate user).
  • Rate limits and lock-out trust X-Forwarded-For as set by the gateway; if the node were reachable directly, the header could be forged.
  • The database and backups are not encrypted at rest.
  • Real passkeys on real devices, the gateway's behaviour and the production origin were not tested.
  • No security contact is published yet; one must be added before launch.
Files main
Menu

Theme