# Top 10 2017-A8-Cross-Site Request Forgery (CSRF)

From OWASP

==The Top 10-2017 Wiki is under Construction. The Content is Not Finished yet.==
==Edits to this page will be lost. If you wish a change, please file an issue on GitHub. ==

← A7-Insufficient Attack Protection | 2017 Table of Contents 2017 Top 10 List | A9-Using Components with Known Vulnerabilities →

Threat Agents | Attack Vectors | Security Weakness | Technical Impacts | Business Impacts
--- | --- | --- | --- | ---
Application Specific | Exploitability AVERAGE | Prevalence UNCOMMON | Detectability EASY | Impact MODERATE | Application / Business Specific
Consider anyone who can load content into your users’ browsers, and thus force them to submit a request to your website, including any website or other HTML feed that your users visit. | Attackers create forged HTTP requests and trick a victim into submitting them via image tags, iframes, XSS, or various other techniques. If the user is authenticated, the attack succeeds. | CSRF takes advantage of the fact that most web apps allow attackers to predict all the details of a particular action. Because browsers send credentials like session cookies automatically, attackers can create malicious web pages which generate forged requests that are indistinguishable from legitimate ones. Detection of CSRF flaws is fairly easy via penetration testing or code analysis. | Attackers can trick victims into performing any state changing operation the victim is authorized to perform (e.g., updating account details, making purchases, modifying data). | Consider the business value of the affected data or application functions. Imagine not being sure if users intended to take these actions. Consider the impact to your reputation.

Am I Vulnerable To 'Cross-Site Request Forgery (CSRF)'? To check whether an application is vulnerable, see if any links and forms lack an unpredictable CSRF token. Without such a token, attackers can forge malicious requests. An alternate defense is to require the user to prove they intended to submit the request, such as through reauthentication. Focus on the links and forms that invoke state-changing functions, since those are the most important CSRF targets. Multistep transactions are not inherently immune. Also be aware that Server-Side Request Forgery (SSRF) is also possible by tricking apps and APIs into generating arbitrary HTTP requests. Note that session cookies, source IP addresses, and other information automatically sent by the browser don’t defend against CSRF since they are included in the forged requests. OWASP’s CSRF Tester tool can help generate test cases to demonstrate the dangers of CSRF flaws. | How Do I Prevent 'Cross-Site Request Forgery (CSRF)'? The preferred option is to use an existing CSRF defense. Many frameworks now include built in CSRF defenses, such as Spring, Play, Django, and AngularJS. Some web development languages, such as .NET do so as well. OWASP’s CSRF Guard can automatically add CSRF defenses to Java apps. OWASP’s CSRFProtector does the same for PHP or as an Apache filter. Otherwise, preventing CSRF usually requires the inclusion of an unpredictable token in each HTTP request. Such tokens should, at a minimum, be unique per user session. The preferred option is to include the unique token in a hidden field. This includes the value in the body of the HTTP request, avoiding its exposure in the URL. The unique token can also be included in the URL or a parameter. However, this runs the risk that the token will be exposed to an attacker. Consider using the “SameSite=strict” flag on all cookies, which is increasingly supported in browsers.
Example Attack Scenarios The application allows a user to submit a state changing request that does not include anything secret. For example: http://example.com/app/transferFunds?amount=1500&destinationAccount=4673243243 So, the attacker constructs a request that will transfer money from the victim’s account to the attacker’s account, and then embeds this attack in an image request or iframe stored on various sites under the attacker’s control: <img src="<b>http://example.com/app/transferFunds?amount=1500&destinationAccount=attackersAcct#</b>" width="0" height="0" /> If the victim visits any of the attacker’s sites while already authenticated to example.com, these forged requests will automatically include the user’s session info, authorizing the attacker’s request. | References OWASP OWASP CSRF Article OWASP CSRF Prevention Cheat Sheet OWASP CSRFGuard - Java CSRF Defense Tool OWASP CSRFProtector - PHP and Apache CSRF Defense Tool ESAPI HTTPUtilities Class with AntiCSRF Tokens OWASP Testing Guide: Chapter on CSRF Testing OWASP CSRFTester - CSRF Testing Tool External CWE Entry 352 on CSRF Wikipedia article on CSRF

← A7-Insufficient Attack Protection | 2017 Table of Contents 2017 Top 10 List | A9-Using Components with Known Vulnerabilities →

© 2002-2017 OWASP Foundation This document is licensed under the Creative Commons Attribution-ShareAlike 3.0 license. Some rights reserved.
Retrieved from "https://www.owasp.org/index.php?title=Top_10_2017-A8-Cross-Site_Request_Forgery_(CSRF)&oldid=229059"
Categories:

- OWASP Top Ten Project
- OWASP Top Ten 2017 Project