Repository navigation
Conversation
…fault to SameSite=Lax
Without allowed_origins, the cross-site check passed any request it could not
settle from Sec-Fetch-Site, so a sibling subdomain (same-site) or a request
with no fetch metadata got through with any Origin. It now requires the Origin
host and port to equal the request's Host, ignoring a default port. A
same-site request with no Origin is refused, and a Sec-Fetch-Site value other
than same-origin, same-site, none and cross-site is treated as cross-site.
This covers the auth routes and the FastAPI and Django guards, which share
the check. The refusal is unchanged: 403 {"error": "cross_site_request_blocked"}.
Cookies now default to SameSite=Lax, whatever insecure_cookies says. The
conformance reference apps set same_site="None", as the contract asks.
Closes #41
BREAKING CHANGE: auth cookies default to SameSite=Lax instead of None. A
frontend on another site than the API must pass same_site="None". Without
allowed_origins, a state-changing request whose Origin does not match Host now
answers 403 cross_site_request_blocked, as does a same-site request with no
Origin or an unknown Sec-Fetch-Site value. A frontend on another origin than
the API, or a proxy that rewrites Host, must list the frontend's origin in
allowed_origins.
This branch has not been deployed
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.
Closes #41 (M12, part of fells-code/seamless-auth-api#603).
What changes
allowed_originsis not set andSec-Fetch-Sitedoes not settle the request (same-site, or absent with anOrigin), theOriginhost and port must equal the request'sHost, ignoring a default port (:443for https,:80for http). Previously such a request passed.Sec-Fetch-Sitevalues are treated as cross-site (parity item from the issue). Previously they fell through to the Origin check.SameSite=Laxby default, whateverinsecure_cookiessays. PreviouslyNonefor secure cookies.same_site="None", sinceverify/CONFORMANCE.mdasks forSameSite=Nonereference cookies. Adapter-mode specs send noOrigin, so the Host rule does not affect them.Unchanged: option names (
same_site,allowed_origins), the refusal (403 {"error": "cross_site_request_blocked"}),Origin: nullrefused first, requests with neither header still pass (native and bearer clients), and the body gate.The check lives in the core (
Adapter._check_origin), so the auth routes,RequireUser(FastAPI) and the Django guard all get it. Both bindings already pass the rawHostheader through.Breaking change (minor bump, pre-1.0)
same_site="None".Host, must list the frontend's origin inallowed_origins.X-Forwarded-Hostis not trusted for this.Tests
HOST_CASEStable intests/test_adapter.py: case, default ports, explicit ports, IPv6, sibling subdomains, scheme mismatch with default port, missing or empty Host, unparseable Origin.Checks (local)
uv run pytest: 1117 passeduv run ruff check .: all checks passeduv run ruff format --check .: 45 files already formatteduv run mypy: no issues in 15 source filesscripts/check-manifest.sh: bundled manifest matches