dotnet / dotnet/aspnetcore

Add a way to access reason of a Mvc filter failure (ex: AntiforgeryTokenAuthorizationFilter.cs)

Open
#4,847 9 comments 2 reactions 0 assignees View on GitHub
affected-few area-mvc enhancement feature-mvc-execution-pipeline Needs: Design severity-nice-to-have
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

When `AntiforgeryValidation` fails, there is no way to track back the reason of the failure from `UseStatusCodePages` Handlers. This would be useful, to take the right action from client side.

From : ValidateAntiforgeryTokenAuthorizationFilter.cs
```
public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

if (IsClosestAntiforgeryPolicy(context.Filters) && ShouldValidate(context))
{
try
{
await _antiforgery.ValidateRequestAsync(context.HttpContext);
}
catch (AntiforgeryValidationException exception)
{
_logger.AntiforgeryTokenInvalid(exception.Message, exception);
context.Result = new BadRequestResult();
}
}
}

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.