Anti-CSRF Tokens Check
ID |
anti_csrf_tokens_check |
Severity |
high |
Kind |
Cross-Site Request Forgery |
CWE |
352 |
Description
A cross-site request forgery is an attack that involves forcing a victim to send an HTTP request to a target destination without their knowledge or intent in order to perform an action as the victim. The underlying cause is application functionality using predictable URL/form actions in a repeatable way. The nature of the attack is that CSRF exploits the trust that a web site has for a user. By contrast, cross-site scripting (XSS) exploits the trust that a user has for a web site. Like XSS, CSRF attacks are not necessarily cross-site, but they can be. Cross-site request forgery is also known as CSRF, XSRF, one-click attack, session riding, confused deputy, and sea surf.
CSRF attacks are effective in a number of situations, including: * The victim has an active session on the target site. * The victim is authenticated via HTTP auth on the target site. * The victim is on the same local network as the target site.
CSRF has primarily been used to perform an action against a target site using the victim’s privileges, but recent techniques have been discovered to disclose information by gaining access to the response. The risk of information disclosure is dramatically increased when the target site is vulnerable to XSS, because XSS can be used as a platform for CSRF, allowing the attack to operate within the bounds of the same-origin policy.
Rationale
Cross-Site Request Forgery exploits the trust a web application has in an authenticated user’s browser by forcing victims to submit unintended requests. Attackers craft malicious links or pages that trigger state-changing operations using the victim’s active session credentials. When the victim visits the attacker’s page, their browser automatically includes authentication cookies, allowing unauthorized actions like fund transfers, password changes, or data modifications. The attack succeeds because the application cannot distinguish legitimate user-initiated requests from forged requests originating from malicious sites.
Remediation
Implement anti-CSRF tokens by generating a unique, unpredictable nonce for each session or form, embedding it in forms, and validating it on the server before processing state-changing requests. Use established libraries like OWASP CSRFGuard or framework-provided CSRF protection mechanisms. Ensure all state-changing operations use POST, PUT, or DELETE methods rather than GET. Eliminate cross-site scripting vulnerabilities since XSS can bypass CSRF defenses. For critical operations, implement additional verification such as re-authentication or confirmation dialogs. Configure SameSite cookie attributes to prevent browsers from sending cookies with cross-origin requests.