Description
IgnoreAntiforgeryToken turns off antiforgery validation on an ASP.NET Core controller or action. A browser may still send its user’s authentication cookie with a state-changing request.
Potential impact
The application can accept an unwanted account change, payment or deletion with the signed-in user’s privileges. Administrative actions carry the administrator’s permissions.
Remediation
Remove IgnoreAntiforgeryToken from cookie-authenticated actions that change state. Issue an antiforgery token to the client and validate it before acting. For an API-only endpoint that omits token validation, use credentials the browser does not send automatically and review its CORS policy.
Examples
Before
csharp
[IgnoreAntiforgeryToken]
[HttpPost("transfer")]
public IActionResult Transfer()
{
return Ok();
}
After
csharp
[ValidateAntiForgeryToken]
[HttpPost("transfer")]
public IActionResult Transfer()
{
return Ok();
}
Explanation:
- Before: The POST action explicitly skips the token check.
- After:
ValidateAntiForgeryTokenrequires a valid token for the POST action. TheTransfermethod shown is an excerpt that returnsOk().