Repository navigation
Events: refuse an http Origin on an https request - #865
Merged
Merged
Conversation
The Events CSRF floor compared only the Origin's host and port with Host. RouteRequest now carries the scheme each adapter reports (ASGI scope, wsgi.url_scheme, Django request.scheme), and enforce_floor refuses an Origin that is not https: when that scheme is https. An http request does not compare schemes, so a proxy that ends TLS keeps working. An Origin that urlsplit cannot read is refused as a plain CSRF failure. Closes #769 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Compare the request scheme case-insensitively, add a form-post test for the attack the check stops and unit tests for how the ASGI and WSGI adapters read the scheme, explain the TLS-ending proxy case and how to turn the check on there, give the http-Origin failure its own section, and refresh docs/design/security_csrf.md and the trust-boundary line numbers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Name Uvicorn's --forwarded-allow-ips (proxy headers are already on), keep the Flask ProxyFix ordering rule, give reading the proxy's scheme its own section and link to it, drop a wrong rationale comment in csrf.py, and tighten the changelog and RouteRequest.scheme wording. Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec
added a commit
that referenced
this pull request
Nov 24, 2026
#871 (#878) Records the Mechanism 7 security reviews of six merged Events changes, in the form docs/security/reviews/README.md describes. Each record is built from the pull request description, the merged diff and its tests; where a description does not record something the template asks for, the record says so. Co-authored-by: Claude Sonnet 5.5 <[email protected]>
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.
(Opus 5.5)
Closes #769.
What changes
The Events CSRF check (
enforce_floor) compared only theOriginheader's host and port withHost. It now also refuses a call whoseOriginis nothttps:when the server reports that the call arrived over https. This stops a plain-http page on the same host, which anyone on the network can rewrite, from calling an https app.RouteRequestgets a newschemefield (last, default""). The ASGI adapter reads the scope'sscheme(default"http"per the ASGI spec), the WSGI adapter readswsgi.url_scheme, and the Django adapter readsrequest.scheme, which followsSECURE_PROXY_SSL_HEADER. The preview host fills it the same way as the ASGI adapter. Flask and FastAPI go through the WSGI and ASGI adapters.Originof either scheme. Behind a proxy that serves the site over https and passes plain http to the app, the app sees http while the browser sends anhttps:origin, so that setup keeps working. The check runs there only when the server reads the forwarded scheme (DjangoSECURE_PROXY_SSL_HEADER, Uvicorn--forwarded-allow-ipsfor a proxy not on127.0.0.1, WerkzeugProxyFix(x_proto=1)); the new "Read the proxy's scheme" docs section says how.scheme(a hand-builtRouteRequest) skips the scheme check. The comparison ignores case.Originthaturlsplitcannot parse is now refused through the normal CSRF path. Before, it raisedValueError, which the dispatcher already answered ascsrf_failedbut logged with a traceback; only the log changes.Tests
packages/py/citry/tests/test_events_origin_scheme.py: the same call through WSGI, ASGI and Django for https+http Origin (403), https+https (200), the proxy case http+https (200), and http+http (200); Django withSECURE_PROXY_SSL_HEADER; a no-JS form post from an http page (403); thecsrf_failedwire error; how the ASGI and WSGI adapters read and lowercase the scheme.TestCsrfFloorintest_events_routes.py: the scheme matrix, uppercase values, noOrigin, and an unparseableOrigin.mainwithout the fix.Local checks: the focused Events, contrib, Django, route and preview-host suites (2677 passed before the review fixes; the changed files again after them),
ruff check .,ruff format --check ., mypy on the gate's full path set on macOS and with--platform linux,uv lock --check, andscripts/validate.py. The cargo phases were not run locally (Python-only change).Docs
security.md("What Citry always checks"),advanced/web-frameworks.md("Run behind a proxy", and new "Fix an http Origin" and "Read the proxy's scheme" sections), the Events v1 protocol spec,docs/design/events.md7.4,docs/design/security_csrf.md, and the CSRF row ofdocs/design/trust_boundaries.md.Versioning
RouteRequest.schemeis a new public field with a default, added last, so positional and keyword callers keep working: a minor-release addition, targeted at 1.3.0.CHANGELOG.mdentry under v1.3.0 says so. Citry already refused these calls from browsers that sendSec-Fetch-Site, so browser traffic on a correctly configured site should not change. A site served to browsers over plain http while its server reports https now fails every call that is not aGET; the docs describe the fix.citry-events/1wire format does not change.Review
An independent reviewer ran a technical, security (Mechanism 7), advisory-survey (Mechanism 8), versioning and prose pass, and a docs cold reader read the changed pages. No hole was found. Fixed during the review: a case-sensitive scheme comparison for hand-built requests, a missing form-post test, missing adapter-reading tests, a stale statement in
docs/design/security_csrf.md, stale line numbers intrust_boundaries.md, docs that did not say the check is skipped behind a TLS-ending proxy unless the server reads the forwarded scheme, and (from a second prose pass) a wrong Uvicorn flag, a missing FlaskProxyFixordering note, and an inaccurate code comment. Not checked in a real browser: the exactSec-Fetch-Sitevalue each engine sends for an http page posting to https on the same host (Citry refuses bothsame-siteandcross-site).🤖 Generated with Claude Code