-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Closed
Copy link
Labels
Complexity: MediumHandline this issue may not be as simple and may involve some non-trivial effortHandline this issue may not be as simple and may involve some non-trivial effortarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-mvc-antiforgerygood first issueGood for newcomers.Good for newcomers.help wantedUp for grabs. We would accept a PR to help resolve this issueUp for grabs. We would accept a PR to help resolve this issue
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
Related to one of issues discussed here #18087
We use CSRF token from headers and have custom file upload middleware.
For it we don't want to have current behavior when call to IAntiforgery.IsRequestValidAsync drains request body stream if there is no token header, which makes stream unusable for custom form parser and consume a lot of resources on big uploads for nothing. For similar reason we don't want to move CSRF check to form parse code - it complicates parse logic and results in a lot of discarded work (especially if you already saved received file body to file system/database) if validation fails (perfect example where fail fast behavior is a must)
Describe the solution you'd like
// AntiforgeryOptions.cs
public bool SuppressTokenFromForm { get; set; } // or whatever name you likeAdditional context
if (requestToken.Count == 0 && httpContext.Request.HasFormContentType)
// proposed change
if (requestToken.Count == 0 && httpContext.Request.HasFormContentType && !_options.SuppressTokenFromForm)Summary Comment : #51912 (comment)
Metadata
Metadata
Assignees
Labels
Complexity: MediumHandline this issue may not be as simple and may involve some non-trivial effortHandline this issue may not be as simple and may involve some non-trivial effortarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-mvc-antiforgerygood first issueGood for newcomers.Good for newcomers.help wantedUp for grabs. We would accept a PR to help resolve this issueUp for grabs. We would accept a PR to help resolve this issue