Skip to content

Handle AntiforgeryValidationException in CookieOnlyAutoValidateAntiforgeryTokenAuthorizationFilter#1152

Open
cx-alex-shleymovich wants to merge 1 commit into
simplcommerce:masterfrom
cx-alex-shleymovich:fix/antiforgery-exception-handling
Open

Handle AntiforgeryValidationException in CookieOnlyAutoValidateAntiforgeryTokenAuthorizationFilter#1152
cx-alex-shleymovich wants to merge 1 commit into
simplcommerce:masterfrom
cx-alex-shleymovich:fix/antiforgery-exception-handling

Conversation

@cx-alex-shleymovich
Copy link
Copy Markdown

This is a follow-up to #1150.

antiforgery.ValidateRequestAsync() throws AntiforgeryValidationException when the CSRF token is missing or invalid. Because the exception is not caught, it propagates as an unhandled exception and produces a 500 Internal Server Error instead of the expected 400 Bad Request.

This PR wraps the call in a try/catch and sets context.Result = new AntiforgeryValidationFailedResult().

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 7, 2026

@hishamco
Copy link
Copy Markdown
Member

hishamco commented Jun 7, 2026

I will review ASAP then merge

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.

2 participants