Skip to content

fix(cors): default to same-origin and require explicit allowlist - #296

Merged
0x2E merged 1 commit into
mainfrom
fix/cors-same-origin-default
Nov 24, 2026
Merged

0x2E merged 1 commit into
mainfrom
fix/cors-same-origin-default

Conversation

@0x2E

@0x2E 0x2E commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Summary

Tighten the CORS defaults: credentialed CORS is only granted to explicitly allowlisted origins, and cross-origin state-changing requests are rejected.

 corsMiddleware
-  if Origin present
-    if allowlist empty or contains "*" or Origin → echo Origin + Allow-Credentials
-    else → 403
-  else → Access-Control-Allow-Origin: *
+  if normalized Origin in allowlist → echo Origin + Allow-Credentials (+ Allow-Headers/Methods)
+  else → no CORS headers (empty allowlist = same-origin only)
+  http.CrossOriginProtection.Check (allowlist added as trusted origins)
+    fail → 403, empty body
   OPTIONS → 204
  • "*" is no longer a wildcard; invalid entries are logged with slog.Warn and ignored.
  • isOriginAllowed removed.
  • Docs updated: config.go, .env.example, README (the variable now sits under "frontend on a different origin" instead of "reverse proxy"), docs/backend-design.md, docs/api-conventions.md.

Evidence

  • Before: with an empty allowlist, a page on another subdomain of the same site could read authenticated /api/* responses and create data via a text/plain POST (checked in headless Chromium).
    After: the same page's read is blocked by the browser and the write returns 403; data is unchanged.
  • Built-in frontend still works: login POST /api/sessions → 200, "Refresh All" POST /api/feeds/refresh → 202.
  • cors_test.go covers: unlisted origin gets no CORS headers; unlisted/same-site/cross-site POST → 403; same-origin, Sec-Fetch-Site: none, and header-less (Fever/curl) POST → 200; /fever through SetupRouter → 200; allowlisted origin GET/POST/preflight; "*" no longer allowed.
  • ./scripts.sh test-backend passes.

Merge Danger

Door: two-way

Revert restores the old behavior; no data or schema changes.

Blast Radius: split-origin deployments

Deployments serving the frontend from a different origin than the API (VITE_API_BASE_URL) must set FUSION_CORS_ALLOWED_ORIGINS, and any "*" entry must be replaced with explicit origins — please call this out in the release notes. Unlisted origins now get 200/204 without CORS headers instead of 403. Not tested: a reverse proxy that rewrites Host combined with an old browser that omits Sec-Fetch-Site would have same-origin writes rejected.

🤖 Generated with Claude Code

- Only allowlisted origins receive CORS headers; an empty
  FUSION_CORS_ALLOWED_ORIGINS now means same-origin only.
- Reject cross-origin state-changing requests with
  http.CrossOriginProtection.
- "*" is no longer a wildcard; invalid entries are ignored with a warning.

BREAKING CHANGE: deployments serving the frontend from a different origin
must list it in FUSION_CORS_ALLOWED_ORIGINS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@0x2E
0x2E merged commit dd9bd28 into main Nov 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant