Skip to content

Document antiforgery HTTP method limitations and HttpMethodOverride i… - #37224

Merged
tdykstra merged 2 commits into
dotnet:mainfrom
GrantTotinov:issue-66687-aspnetcore-docs
Jun 22, 2026
Merged

tdykstra merged 2 commits into
dotnet:mainfrom
GrantTotinov:issue-66687-aspnetcore-docs

Conversation

@GrantTotinov

@GrantTotinov GrantTotinov commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Documents that AntiforgeryMiddleware and UseAntiforgery() only validate antiforgery tokens for POST, PUT, and PATCH requests, and explains how to validate other HTTP methods explicitly using IAntiforgery.

Also documents the interaction with HttpMethodOverrideMiddleware when configured with FormFieldName, where a POST request can be overridden to a non-validated method, bypassing antiforgery validation.

Related to dotnet/aspnetcore#66687

See also: dotnet/aspnetcore#66772


Internal previews

📄 File 🔗 Preview link
aspnetcore/security/anti-request-forgery.md Prevent Cross-Site Request Forgery (XSRF/CSRF) attacks in ASP.NET Core

Copilot AI review requested due to automatic review settings June 3, 2026 01:21

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the antiforgery documentation with new guidance around HTTP method coverage and how HttpMethodOverrideMiddleware can affect CSRF validation.

Changes:

  • Updated the page metadata date.
  • Added a new section documenting which HTTP methods are validated by AntiforgeryMiddleware/UseAntiforgery() and how to validate additional methods explicitly.
  • Added a warning about a potential bypass when using HttpMethodOverrideMiddleware in form-field mode before antiforgery validation.


### HTTP method limitations and `HttpMethodOverrideMiddleware` interaction

`AntiforgeryMiddleware` and `UseAntiforgery()` validate antiforgery tokens only for HTTP **POST**, **PUT**, and **PATCH** requests. Other HTTP methods, such as **DELETE**, aren't validated automatically.
Comment on lines +360 to +361
> [!WARNING]
> When `HttpMethodOverrideMiddleware` is configured with `FormFieldName` (form-field mode) and placed before `AntiforgeryMiddleware`, a POST request can be overridden to DELETE (or another non-validated method). Because `AntiforgeryMiddleware` validates only POST, PUT, and PATCH, the overridden request bypasses antiforgery validation. To protect these endpoints, validate the antiforgery token explicitly using `IAntiforgery.ValidateRequestAsync`.
@cincuranet

Copy link
Copy Markdown
Contributor

@GrantTotinov Ping.

@GrantTotinov

Copy link
Copy Markdown
Contributor Author

@cincuranet The PR is ready for review.

@cincuranet

Copy link
Copy Markdown
Contributor

What about the comments from Copilot?

@GrantTotinov

Copy link
Copy Markdown
Contributor Author

@cincuranet Good point. I'll address the Copilot comments and update the PR shortly.

@GrantTotinov

Copy link
Copy Markdown
Contributor Author

@cincuranet Done — addressed both Copilot comments.

@cincuranet

Copy link
Copy Markdown
Contributor

@tdykstra Can I get review on this, please. Thanks.

@tdykstra tdykstra 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.

LGTM

@tdykstra
tdykstra merged commit 1a20c20 into dotnet:main Jun 22, 2026
4 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.

Document antiforgery skip in AntiforgeryMiddleware for DELETE via HttpMethodOverride

4 participants