Why it matters
A page on another site can submit this form with the user's cookies.
How to fix it
Remove the attribute and send the antiforgery token with the request. An API authenticated by a bearer header rather than a cookie does not need the token; mark that with [ApiController].
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
using Microsoft.AspNetCore.Mvc;
public class ProfileController : Controller
{
[HttpPost]
[IgnoreAntiforgeryToken]
public IActionResult Update(ProfileForm form)
{
return RedirectToAction("Index");
}
}using Microsoft.AspNetCore.Mvc;
public class ProfileController : Controller
{
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Update(ProfileForm form)
{
return RedirectToAction("Index");
}
}What TrustIvan reads
Runs on repository scans of C# source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.
Weakness classes and references
Related checks
- JWT validation disabled (C#)
C#Severity: High
trustivan-csharp-jwt-validation-disabled - Cookie flags disabled (C#)
C#Severity: Medium
trustivan-csharp-cookie-flags-disabled - JWT hardcoded secret (C#)
C#Severity: High
trustivan-csharp-jwt-hardcoded-secret - CORS any origin callback (C#)
C#Severity: Medium
trustivan-csharp-cors-any-origin-callback - Hardcoded password connection string (C#)
C#Severity: High
trustivan-csharp-hardcoded-password-connection-string - Developer exception page (C#)
C#Severity: Medium
trustivan-csharp-developer-exception-page
Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10
All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation