Skip to content

web: Cross-origin protection - #3762

Merged
bdarnell merged 10 commits into
tornadoweb:masterfrom
bdarnell:claude/dreamy-fermat-7oki7f
Oct 6, 2026
Merged

bdarnell merged 10 commits into
tornadoweb:masterfrom
bdarnell:claude/dreamy-fermat-7oki7f

Conversation

@bdarnell

@bdarnell bdarnell commented Oct 5, 2026

Copy link
Copy Markdown
Member

This branch implements cross-origin protection based on fetch-metadata/sec-fetch-site. The naming and algorithm follows that used by Go. This is intended to become the main method of XSRF protection for tornado and I plan to turn it on by default in 6.7.

Builds on @takluyver 's work in #3576

Closes #3576
Closes #3495

takluyver and others added 10 commits May 8, 2026 08:34
The behavior is not exactly identical (cross_origin is now called
a little later in the process, after first-line same-origin checks
have failed), but since this method was used to expand access
rather than restrict it it should be functionally equivalent.
Tests:
- web: Sec-Fetch-Site none/same-site, precedence of Sec-Fetch-Site over
  Origin, trusted_origins (both paths, exact matching), null Origin,
  Referer not consulted, safe vs unsafe methods, setting disabled by
  default, check_origin overrides, interaction with xsrf_cookies, and
  ErrorHandler returning 404/417 instead of 403.
- websocket: xsrf_cookies does not apply to websockets, trusted_origins,
  Sec-Fetch-Site handling, check_origin override, and mixed-case Upgrade
  headers not bypassing the origin check.

Docs:
- Restore the security warning and examples in check_origin's docstring
  that were dropped when it moved from WebSocketHandler.
- Fix stale references to xsrf_protection and check_trusted_origin, and
  the link to Go's CrossOriginProtection.
- Document that websockets always use these checks, and that requests
  without Sec-Fetch-Site or Origin are allowed.
- Move trusted_origins to its alphabetical place in the settings list.

Also replace the separate urlparse import with urllib.parse.urlsplit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01USrW1MXy2Ea3H3S1ZHyPjw
@bdarnell
bdarnell merged commit 80ec622 into tornadoweb:master Oct 6, 2026
29 of 33 checks passed
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.

web: New XSRF/CSRF protection: Sec-Fetch-Site

3 participants