Skip to content

Document antiforgery HTTP method limitations and HttpMethodOverride i…#37224

Open
GrantTotinov wants to merge 1 commit into
dotnet:mainfrom
GrantTotinov:issue-66687-aspnetcore-docs
Open

Document antiforgery HTTP method limitations and HttpMethodOverride i…#37224
GrantTotinov wants to merge 1 commit into
dotnet:mainfrom
GrantTotinov:issue-66687-aspnetcore-docs

Conversation

@GrantTotinov
Copy link
Copy Markdown

@GrantTotinov GrantTotinov commented Jun 3, 2026

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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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`.
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

3 participants