Skip to content

[WIP] Sec-Fetch-* based Antiforgery Version-2#66411

Draft
DeagleGross wants to merge 3 commits intodotnet:mainfrom
DeagleGross:dmkorolev/cross-origin-v2
Draft

[WIP] Sec-Fetch-* based Antiforgery Version-2#66411
DeagleGross wants to merge 3 commits intodotnet:mainfrom
DeagleGross:dmkorolev/cross-origin-v2

Conversation

@DeagleGross
Copy link
Copy Markdown
Member

[IN DESIGN]

Fixes #65127

Lightweight, auto-enabled cross-origin request protection that works
without AddAntiforgery()/UseAntiforgery() and has no DataProtection
dependency — AOT/trim safe.

Architecture:
- ICrossOriginProtection + CrossOriginValidationResult in Http.Abstractions
  (namespace Microsoft.AspNetCore.Antiforgery for discoverability)
- CrossOriginRequestValidator as shared source in src/Shared/
  (compiled into Routing now, Antiforgery later)
- CrossOriginProtectionOptions + DefaultCrossOriginProtection in Routing
- EndpointMiddleware uses ICrossOriginProtection.Validate() with tri-state
  result (Allowed/Denied/Disabled) instead of throwing on missing middleware

Algorithm (matches Go 1.25 CrossOriginProtection):
1. Safe methods (GET/HEAD/OPTIONS/TRACE) → allow
2. Trusted origins → allow
3. Sec-Fetch-Site same-origin/none → allow, cross-site → deny
4. Origin vs request host fallback
5. No headers (non-browser) → allow

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Cross-Site Request Forgery Algorithm based on Fetch Metadata headers

1 participant