fix(backend): restrict cors allowlist to first-party hosts
Implements decision #2 of ADR 2026-06-05-csrf-posture.md (bundled). From the CSRF /research-and-decide on #1244.
What
Restricts the credentialed CORS allowlist to first-party hosts:
- Drops
*.replit.dev,*.repl.co,*.replit.app— multi-tenant dev platforms that should never be trusted withcredentials: true. - Gates
localhost/127.0.0.1to non-production only. - Keeps
lucassantana.tech/luk-homeserver.com.br(+ subdomains) and the explicitconfiguredOrigins.
Why
Not a CSRF hole — the explicit SameSite=lax session cookie already blocks the cookie on cross-site requests, so a replit.dev page can't forge an authenticated mutation regardless of CORS. But allowing untrusted multi-tenant origins (and prod localhost) with credentials: true is a defense-in-depth weakness for credentialed cross-origin reads, surfaced by the CSRF review. Tightening costs nothing and shrinks the surface.
The companion decision — keep SameSite=lax, no CSRF token (the vector is already closed; strict would break Discord OAuth) — is recorded in the bundled ADR. The CodeQL js/missing-token-validation alert is being dismissed as mitigated with that ADR as evidence.
Verification
Backend type:check clean · full backend suite 994/994 pass (no CORS-origin test asserted the removed hosts).
@cubic-dev-ai please review.
Summary by cubic
Tightens backend CORS to only first-party hosts and gates localhost to non-production to reduce risk of credentialed cross-origin reads. Bundles an ADR that documents the CSRF posture (keep SameSite=lax; no CSRF token) and addresses the CodeQL alert in #1244.
- Bug Fixes
- Remove
*.replit.dev,*.repl.co,*.replit.appfrom the credentialed CORS allowlist. - Allow
localhostand127.0.0.1only when not in production. - Keep
lucassantana.techandluk-homeserver.com.br(and subdomains). - Add
decisions/2026-06-05-csrf-posture.mdto record the decision and rationale.
- Remove