Skip to content

Handle AntiforgeryValidationException in CookieOnlyAutoValidateAntiforgeryTokenAuthorizationFilter#1152

Merged
hishamco merged 1 commit into
simplcommerce:masterfrom
cx-alex-shleymovich:fix/antiforgery-exception-handling
Jun 8, 2026
Merged

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

Conversation

@cx-alex-shleymovich

Copy link
Copy Markdown
Contributor

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

sonarqubecloud Bot commented Jun 7, 2026

Copy link
Copy Markdown

@hishamco

hishamco commented Jun 7, 2026

Copy link
Copy Markdown
Member

I will review ASAP then merge

@hishamco hishamco merged commit 3472ba0 into simplcommerce:master Jun 8, 2026
10 of 12 checks passed
@hishamco

hishamco commented Jun 8, 2026

Copy link
Copy Markdown
Member

Thanks

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