Skip to content

Restrict HTTP methods and headers with CORS - #695

Merged
haralde merged 2 commits into
mainfrom
cors_hardening
May 18, 2026
Merged

Restrict HTTP methods and headers with CORS#695
haralde merged 2 commits into
mainfrom
cors_hardening

Conversation

@fmell

@fmell fmell commented May 11, 2026

Copy link
Copy Markdown
Collaborator

Restrict allowed CORS methods to: GET, POST, PUT, DELETE, OPTIONS
Restrict allowed CORS headers to: Authorization, Content-Type
Add fail-fast validation that raises on origin "*" when allow_credentials is true, as this will fail silently in the browser if misconfigured

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens the backend’s CORS configuration by explicitly allowing only the HTTP methods and request headers the frontend uses, and by adding a startup-time guard against an invalid credentialed CORS configuration (allow_credentials=True with allow_origins=["*"]).

Changes:

  • Add fail-fast validation that raises if "*" is present in the configured CORS origins while credentials are enabled.
  • Restrict CORS allowed methods to GET, POST, PUT, DELETE, OPTIONS (instead of "*").
  • Restrict CORS allowed headers to Authorization and Content-Type (instead of "*").

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lars-petter-hauge

Copy link
Copy Markdown
Collaborator

don't see a reason for not adding this, gogogo :)

@haralde
haralde merged commit 4228496 into main May 18, 2026
7 checks passed
@haralde
haralde deleted the cors_hardening branch May 18, 2026 13:09
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.

4 participants