CORS: never allow credentials for the wildcard origin - #53
Merged
Merged
Conversation
The parent app used allow_origins=['*'] with allow_credentials=True, which makes Starlette reflect any request Origin and add Access-Control-Allow-Credentials: true, so any page that got the browser to send the session cookie could read a signed-in user's responses. New PlatformConfig.cors_origins (platform.toml [platform]): ['*'] (default) allows any origin without credentials; an explicit list allows those origins with credentials; [] disables CORS. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Refuse "*" mixed with named origins (would silently drop credentials), "null" (any sandboxed page sends it), and values that are not scheme://host[:port] (never match, fail silently). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The platform-level CORS middleware was
allow_origins=["*"], allow_credentials=True. With that pair Starlette reflects the request'sOriginand addsAccess-Control-Allow-Credentials: true, so a page on another origin that gets the browser to attach the session cookie can read a signed-in user's responses (confirmed locally with a protected app behind enlace_auth).SameSite=Laxsession cookies limit which origins can do that in practice, but the header pair should never be sent for arbitrary origins.PlatformConfig.cors_origins([platform] cors_originsin platform.toml):["*"](default) — any origin, without credentials (public responses stay readable cross-origin, as before);[]— no CORS headers.cors_originsis validated:"*"must stand alone,"null"is refused, named origins must bescheme://host[:port].Independent refute-review done: no blockers; its should-fixes (
"null"re-opening exposure,"*"mixed with named origins, malformed origins silently never matching) are fixed in the second commit. Noted, not changed: auth middleware runs before CORS, so 401s carry no CORS headers (pre-existing); enlace_auth's/api/CSRF exemption relies on SameSite=Lax, which does not stop same-site sibling hosts.Behaviour change: cross-origin credentialed calls from arbitrary origins stop working unless the origin is listed. In-fleet frontends call the API same-origin (relative URLs), so nothing known depends on it.
Tests:
enlace/tests/test_cors.py(fail on main). Full suite 308 passed. Dependents against this branch: enlace_auth 377 passed, enlace_docker 58 passed / 2 skipped.🤖 Generated with Claude Code