Document antiforgery HTTP method limitations and HttpMethodOverride i…#37224
Open
GrantTotinov wants to merge 1 commit into
Open
Document antiforgery HTTP method limitations and HttpMethodOverride i…#37224GrantTotinov wants to merge 1 commit into
GrantTotinov wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
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
HttpMethodOverrideMiddlewarein 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`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Documents that
AntiforgeryMiddlewareandUseAntiforgery()only validate antiforgery tokens for POST, PUT, and PATCH requests, and explains how to validate other HTTP methods explicitly usingIAntiforgery.Also documents the interaction with
HttpMethodOverrideMiddlewarewhen configured withFormFieldName, 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