-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatespending-ci-rerunWhen assigned to a PR indicates that the CI checks should be rerunWhen assigned to a PR indicates that the CI checks should be rerun
Description
Background and Motivation
Proposed API
namespace Microsoft.AspNetCore.Antiforgery;
public class AntiforgeryOptions
{
+ public AntiforgeryRequestTokenSource RequestTokenSource { get; set; }
}
+[Flags]
+public enum AntiforgeryRequestTokenSource
+{
+ Header = 1,
+ FormBody = 2,
+ HeaderOrFormBody = Header | FormBody
+}
public class RequireAntiforgeryTokenAttribute : Attribute, IAntiforgeryMetadata
{
+ public AntiforgeryRequestTokenSource RequestTokenSource { get; init; }
}
Usage Examples
services.AddAntiforgery(static options =>
{
options.RequestTokenSource = AntiforgeryRequestTokenSource.Header
});
[RequireAntiforgeryToken(RequestTokenSource = AntiforgeryRequestTokenSource.Header)]
public class MyController
{
[HttpPost]
public IActionResult Post() { ... }
[HttpPost]
[RequireAntiforgeryToken(RequestTokenSource = AntiforgeryRequestTokenSource.FormBody)]
public IActionResult Post2() { ... }
}Alternative Designs
Risks
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatespending-ci-rerunWhen assigned to a PR indicates that the CI checks should be rerunWhen assigned to a PR indicates that the CI checks should be rerun