Skip to content

fix(csrf)!: require Origin to match Host without an allow-list and default to SameSite=Lax - #49

Merged
Bccorb merged 1 commit into
mainfrom
fix/csrf-host-origin-and-lax-default
Nov 21, 2026
Merged

Bccorb merged 1 commit into
mainfrom
fix/csrf-host-origin-and-lax-default

Conversation

@Bccorb

@Bccorb Bccorb commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Closes #42. Part of fells-code/seamless-auth-api#603 (v0.24, M12).

What changes

  • With no allowed_origins, an unsafe request with Sec-Fetch-Site: same-site, or with no Sec-Fetch-Site and an Origin, needs the Origin's host[:port] to equal the request's Host header (or the HTTP/2 URI authority). A default port (:443 for https, :80 for http) on either side does not count against a match. Before, both cases passed.
  • A same-site request with no Origin is refused without an allow-list too, as it already was with one.
  • An unknown Sec-Fetch-Site value is treated as cross-site.
  • Refusals keep the existing 403 { "error": "cross_site_request_blocked" }. No option names change. The allow-list path is unchanged.
  • Auth cookies default to SameSite=Lax (was None when Secure, Lax with insecure_cookies).
  • The conformance reference app sets same_site(SameSite::None), which verify/CONFORMANCE.md expects.
  • README and builder docs describe the new rules and defaults.

Behaviour change

The commit carries a BREAKING CHANGE footer, so release-plz bumps the minor version (pre-1.0). A frontend on another site that calls the adapter with credentials must now set same_site(SameSite::None) and allowed_origins. A deployment behind a proxy that rewrites Host should set allowed_origins.

Checks

  • cargo fmt --check: clean
  • cargo clippy --all-targets -- -D warnings (default, --all-features, --no-default-features, --no-default-features --features native-tls): clean
  • cargo test --all-features: 155 passed
  • cargo +1.88 test: 155 passed
  • scripts/check-manifest.sh: matches

…ault to SameSite=Lax

Without allowed_origins, the cross-site check let a same-site request from a
sibling subdomain through, and passed a request without fetch metadata
whatever Origin it carried. Now, with no allow-list, a same-site request or
one without Sec-Fetch-Site that carries an Origin needs that Origin's
host[:port] to equal the request's Host header (or the HTTP/2 authority), a
default port aside. A Sec-Fetch-Site value the check does not know is
treated as cross-site. Refusals keep answering 403 cross_site_request_blocked.

Cookies now default to SameSite=Lax instead of None.

The reference app pins SameSite=None, which the conformance contract
expects.

Closes #42

BREAKING CHANGE: auth cookies default to SameSite=Lax (was None when
Secure). A frontend on another site that calls the adapter with credentials
must set same_site(SameSite::None). Without allowed_origins, an unsafe
request whose Origin does not name the request's own Host is refused with
403 cross_site_request_blocked; behind a proxy that rewrites Host, or for a
frontend on another origin, set allowed_origins.
@Bccorb Bccorb changed the title fix(csrf): require Origin to match Host without an allow-list and default to SameSite=Lax fix(csrf)!: require Origin to match Host without an allow-list and default to SameSite=Lax Nov 20, 2026
@Bccorb
Bccorb merged commit 9edce72 into main Nov 21, 2026
4 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 21, 2026
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.

fix(csrf): require Origin to match Host without an allow-list and default to SameSite=Lax

1 participant