Skip to content

Align Fetch-Metadata CSRF trust with CORS credentials intent - #69345

Merged
wtgodbe merged 2 commits into
dotnet:release/11.0from
DeagleGross:deaglegross-redesigned-invention
Sep 17, 2026
Merged

wtgodbe merged 2 commits into
dotnet:release/11.0from
DeagleGross:deaglegross-redesigned-invention

Conversation

@DeagleGross

@DeagleGross DeagleGross commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

DefaultCsrfProtection treats a matched CORS policy's allowed origin as a trust signal for Fetch-Metadata-based CSRF checks. Today it does this whenever !policy.AllowAnyOrigin && policy.IsOriginAllowed(origin) is true, without checking policy.SupportsCredentials (the property backing .AllowCredentials()).

This change adds that check, so a CORS policy only expands CSRF trust when it was also configured with .AllowCredentials().

Why is requiring AllowCredentials() fine?

CORS's AllowCredentials() (which sets policy.SupportsCredentials) is the one explicit flag a developer sets when they mean "this cross-origin caller is allowed to send/receive the user's cookies." If a developer did not set it, they were saying "this origin can call me anonymously/publicly," not "this origin can act as the logged-in user."

Since CSRF protection is entirely about authenticated, cookie-bearing actions being triggered from elsewhere, only the credentialed case is actually claiming the trust relationship CSRF protection cares about. Requiring SupportsCredentials before letting a CORS policy grant CSRF trust makes the code check what the developer actually intended, instead of trusting origins that were only ever configured for anonymous/public access.

Docs change if this is merged: dotnet/AspNetCore.Docs#37660

Copilot AI lite review requested due to automatic review settings September 16, 2026 09:49
@DeagleGross DeagleGross changed the title Require CORS AllowCredentials() for Fetch-Metadata CSRF trust Align Fetch-Metadata CSRF trust with CORS credentials intent Sep 16, 2026
@DeagleGross DeagleGross added the Servicing-consider Shiproom approval is required for the issue label Sep 16, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hi @DeagleGross. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge.

To learn more about how to prepare a servicing PR click here.

@DeagleGross DeagleGross self-assigned this Sep 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Existing integration tests must be updated to match the new credential requirement.

Get a fresh assessment by requesting another Copilot review.

Review tier: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

This pull request restricts CORS-derived CSRF trust to policies that explicitly allow credentials.

Changes:

  • Requires SupportsCredentials for CORS-based CSRF trust.
  • Adds credentialed and non-credentialed policy test coverage.
File Summary
src/​DefaultBuilder/​test/​Microsoft.AspNetCore.Tests/​DefaultCsrfProtectionTests.cs Expands coverage across CORS policy configurations.
src/​DefaultBuilder/​src/​Internal/​DefaultCsrfProtection.cs Requires credential support when deriving CSRF trust from CORS. Existing integration tests still expect non-credentialed policies to be trusted.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@DeagleGross
DeagleGross force-pushed the deaglegross-redesigned-invention branch from 1b006a5 to 4685f52 Compare September 16, 2026 10:03
DeagleGross added a commit to DeagleGross/AspNetCore.Docs that referenced this pull request Sep 16, 2026
Per feedback: the AllowCredentials() requirement for CORS-derived CSRF
trust is unreleased (dotnet/aspnetcore#69345 is still open), so it
shouldn't be documented as a breaking change or a 10->11 migration
concern yet.

- Removed breaking-changes/11/csrf-cors-allowcredentials-required.md
- Reverted the registration in breaking-changes/11/overview.md and toc.yml
- Reverted the migration/100-to-110/includes/security.md CORS bullet
- Removed the breaking-change cross-link from anti-request-forgery.md,
  keeping the AllowCredentials() requirement description, updated CORS
  code sample, and AllowAnyOrigin note

Co-authored-by: Copilot App <[email protected]>

@halter73 halter73 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the functional change is sound, but we should probably add more testing and update some more existing tests to include AllowCredentials().

@DeagleGross
DeagleGross requested a review from artl93 September 17, 2026 10:44

@artl93 artl93 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.
Behavior change after RC1 - should this be considered a breaking change?

@artl93 artl93 added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Sep 17, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hi @DeagleGross. This PR was just approved to be included in the upcoming servicing release. Somebody from the @dotnet/aspnet-build team will get it merged when the branches are open. Until then, please make sure all the CI checks pass and the PR is reviewed.

@wtgodbe
wtgodbe merged commit ebe3f44 into dotnet:release/11.0 Sep 17, 2026
33 checks passed
@DeagleGross
DeagleGross deleted the deaglegross-redesigned-invention branch September 17, 2026 16:50
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc2 milestone Sep 17, 2026
DeagleGross added a commit to dotnet/AspNetCore.Docs that referenced this pull request Sep 23, 2026
…ust (#37660)

* Document CORS AllowCredentials requirement for Fetch-Metadata CSRF trust

Contributes to dotnet/aspnetcore#69345

- security/anti-request-forgery.md: the automatic CSRF protection
  middleware's "How it works" and "Allowing cross-origin clients"
  sections now state that a CORS-allowed origin only grants CSRF trust
  when the policy also calls .AllowCredentials(). Updated the CORS code
  sample to include .AllowCredentials() so it stays a correct example,
  and added a short note next to the existing AllowAnyOrigin warning.
- migration/100-to-110/includes/security.md: one-line update to the
  CORS guidance bullet to mention the new AllowCredentials() requirement.
- breaking-changes/11/csrf-cors-allowcredentials-required.md: new
  breaking-change entry describing the behavior change, following the
  existing template. Registered in overview.md and toc.yml.

Co-authored-by: Copilot App <[email protected]>

* Remove breaking-change entry and migration note; not shipped yet

Per feedback: the AllowCredentials() requirement for CORS-derived CSRF
trust is unreleased (dotnet/aspnetcore#69345 is still open), so it
shouldn't be documented as a breaking change or a 10->11 migration
concern yet.

- Removed breaking-changes/11/csrf-cors-allowcredentials-required.md
- Reverted the registration in breaking-changes/11/overview.md and toc.yml
- Reverted the migration/100-to-110/includes/security.md CORS bullet
- Removed the breaking-change cross-link from anti-request-forgery.md,
  keeping the AllowCredentials() requirement description, updated CORS
  code sample, and AllowAnyOrigin note

Co-authored-by: Copilot App <[email protected]>

* Remove stray italics around 'and' in CSRF rule 3 wording

* minor rewording

---------

Co-authored-by: Copilot App <[email protected]>
DeagleGross added a commit to dotnet/AspNetCore.Docs that referenced this pull request Oct 7, 2026
* Document CORS AllowCredentials requirement for Fetch-Metadata CSRF trust

Contributes to dotnet/aspnetcore#69345

- security/anti-request-forgery.md: the automatic CSRF protection
  middleware's "How it works" and "Allowing cross-origin clients"
  sections now state that a CORS-allowed origin only grants CSRF trust
  when the policy also calls .AllowCredentials(). Updated the CORS code
  sample to include .AllowCredentials() so it stays a correct example,
  and added a short note next to the existing AllowAnyOrigin warning.
- migration/100-to-110/includes/security.md: one-line update to the
  CORS guidance bullet to mention the new AllowCredentials() requirement.
- breaking-changes/11/csrf-cors-allowcredentials-required.md: new
  breaking-change entry describing the behavior change, following the
  existing template. Registered in overview.md and toc.yml.

Co-authored-by: Copilot App <[email protected]>

* Remove breaking-change entry and migration note; not shipped yet

Per feedback: the AllowCredentials() requirement for CORS-derived CSRF
trust is unreleased (dotnet/aspnetcore#69345 is still open), so it
shouldn't be documented as a breaking change or a 10->11 migration
concern yet.

- Removed breaking-changes/11/csrf-cors-allowcredentials-required.md
- Reverted the registration in breaking-changes/11/overview.md and toc.yml
- Reverted the migration/100-to-110/includes/security.md CORS bullet
- Removed the breaking-change cross-link from anti-request-forgery.md,
  keeping the AllowCredentials() requirement description, updated CORS
  code sample, and AllowAnyOrigin note

Co-authored-by: Copilot App <[email protected]>

* Remove stray italics around 'and' in CSRF rule 3 wording

* minor rewording

* specify isoriginallowed behavior

---------

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Servicing-approved Shiproom has approved the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants