This site is the archived OWASP Foundation Wiki and is no longer accepting Account Requests.
To view the new OWASP Foundation website, please visit https://owasp.org
Difference between revisions of "Top 10 2013-A8-Cross-Site Request Forgery (CSRF)"
(fixed typo) |
|||
(13 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Top_10_2013:TopTemplate | {{Top_10_2013:TopTemplate | ||
|usenext=2013NextLink | |usenext=2013NextLink | ||
− | |next={{Top_10_2010:ByTheNumbers | + | |next=A9-{{Top_10_2010:ByTheNumbers |
|9 | |9 | ||
− | |year=2013}} | + | |year=2013 |
+ | |language=en}} | ||
|useprev=2013PrevLink | |useprev=2013PrevLink | ||
− | |prev={{Top_10_2010:ByTheNumbers | + | |prev=A7-{{Top_10_2010:ByTheNumbers |
|7 | |7 | ||
− | |year=2013}} | + | |year=2013 |
+ | |language=en}} | ||
+ | |year=2013 | ||
+ | |language=en | ||
}} | }} | ||
− | {{Top_10_2010:SummaryTableHeaderBeginTemplate | + | {{Top_10_2010:SummaryTableHeaderBeginTemplate|year=2013|language=en}} |
− | + | {{Top_10:SummaryTableTemplate|exploitability=2|prevalence=2|detectability=1|impact=2|year=2013|language=en}} | |
− | {{ | + | {{Top_10_2010:SummaryTableHeaderEndTemplate|year=2013}} |
− | + | <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}> | |
− | + | Consider anyone who can load content into your users’ browsers, and thus force them to submit a request to your website. Any website or other HTML feed that your users access could do this. | |
− | {{Top_10_2010:SummaryTableHeaderEndTemplate}} | + | |
− | <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>Consider anyone who can load content into your users’ browsers, and thus force them to submit a request to your website. Any website or other HTML feed that your users access could do this. | ||
</td> | </td> | ||
− | <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>Attacker creates forged HTTP requests and tricks a victim into submitting them via image tags, XSS, or numerous other techniques. <u>If the user is authenticated</u>, the attack succeeds. | + | <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}> |
+ | Attacker creates forged HTTP requests and tricks a victim into submitting them via image tags, XSS, or numerous other techniques. <u>If the user is authenticated</u>, the attack succeeds. | ||
+ | |||
</td> | </td> | ||
− | <td colspan=2 {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>CSRF takes advantage | + | <td colspan=2 {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>[https://www.owasp.org/index.php/CSRF CSRF] takes advantage 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. | Detection of CSRF flaws is fairly easy via penetration testing or code analysis. | ||
</td> | </td> | ||
− | <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>Attackers can | + | <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}> |
+ | Attackers can trick victims into performing any state changing operation the victim is authorized to perform, e.g., updating account details, making purchases, logout and even login. | ||
+ | |||
</td> | </td> | ||
− | <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>Consider the business value of the affected data or application functions. Imagine not being sure if users intended to take these actions. | + | <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}> |
+ | 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. | ||
− | + | </td> | |
{{Top_10_2010:SummaryTableEndTemplate}} | {{Top_10_2010:SummaryTableEndTemplate}} | ||
− | {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}| | + | {{Top_10:SubsectionTableBeginTemplate|type=main}} {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=vulnerableTo|position=firstLeft|risk=8|year=2013|language=en}} |
− | To check whether an application is vulnerable, see if | + | 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, either through reauthentication, or some other proof they are a real user (e.g., a CAPTCHA). |
+ | |||
Focus on the links and forms that invoke state-changing functions, since those are the most important CSRF targets. | Focus on the links and forms that invoke state-changing functions, since those are the most important CSRF targets. | ||
+ | |||
You should check multistep transactions, as they are not inherently immune. Attackers can easily forge a series of requests by using multiple tags or possibly JavaScript. | You should check multistep transactions, as they are not inherently immune. Attackers can easily forge a series of requests by using multiple tags or possibly JavaScript. | ||
− | Note that session cookies, source IP addresses, and other information automatically sent by the browser | + | |
− | OWASP’s CSRF Tester tool can help generate test cases to demonstrate the dangers of CSRF flaws. | + | Note that session cookies, source IP addresses, and other information automatically sent by the browser don’t provide any defense against CSRF since this information is also included in forged requests. |
− | {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}| | + | |
+ | OWASP’s [https://www.owasp.org/index.php/CSRFTester CSRF Tester] tool can help generate test cases to demonstrate the dangers of CSRF flaws. | ||
+ | |||
+ | {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=howPrevent|position=right|risk=8|year=2013|language=en}} | ||
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. | 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 causes the value to be sent in the body of the HTTP request, avoiding its inclusion in the URL, which is | + | # The preferred option is to include the unique token in a hidden field. This causes the value to be sent in the body of the HTTP request, avoiding its inclusion in the URL, which is more prone to exposure. |
− | # The unique token can also be included in the URL itself, or a URL parameter. However, such placement runs | + | # The unique token can also be included in the URL itself, or a URL parameter. However, such placement runs a greater risk that the URL will be exposed to an attacker, thus compromising the secret token.<br/>OWASP’s [https://www.owasp.org/index.php/CSRFGuard CSRF Guard] can automatically include such tokens in Java EE, .NET, or PHP apps. OWASP’s [https://www.owasp.org/index.php/ESAPI ESAPI] includes methods developers can use to prevent CSRF vulnerabilities. |
− | OWASP’s CSRF Guard can automatically include such tokens in Java EE, .NET, or PHP apps. OWASP’s ESAPI includes | ||
# Requiring the user to reauthenticate, or prove they are a user (e.g., via a CAPTCHA) can also protect against CSRF. | # Requiring the user to reauthenticate, or prove they are a user (e.g., via a CAPTCHA) can also protect against CSRF. | ||
− | {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}| | + | {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=example|position=left|risk=8|year=2013|language=en}} |
The application allows a user to submit a state changing request that does not include anything secret. For example: | The application allows a user to submit a state changing request that does not include anything secret. For example: | ||
− | {{Top_10_2010:ExampleBeginTemplate}} | + | {{Top_10_2010:ExampleBeginTemplate|year=2013}} |
− | http://example.com/app/transferFunds?amount=1500&destinationAccount=4673243243 | + | <nowiki>http://</nowiki>example.com/app/transferFunds?amount=1500&destinationAccount=4673243243 |
− | {{Top_10_2010:ExampleEndTemplate}}{{Top_10_2010:ExampleBeginTemplate}} | + | {{Top_10_2010:ExampleEndTemplate}} |
− | + | 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: | |
− | + | {{Top_10_2010:ExampleBeginTemplate|year=2013}} | |
+ | <img src="<span style="color: red;"><nowiki>http://</nowiki>example.com/app/transferFunds?amount=1500&destinationAccount=attackersAcct#</span>" width="0" height="0" /> | ||
+ | {{Top_10_2010:ExampleEndTemplate}} | ||
+ | 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. | ||
− | |||
− | |||
− | {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}| | + | {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=references|position=right|risk=8|year=2013|language=en}} |
{{Top_10_2010:SubSubsectionOWASPReferencesTemplate}} | {{Top_10_2010:SubSubsectionOWASPReferencesTemplate}} | ||
− | * OWASP CSRF Article | + | * [https://www.owasp.org/index.php/CSRFGuard OWASP CSRF Article] |
− | * OWASP CSRF Prevention Cheat Sheet | + | * [https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet OWASP CSRF Prevention Cheat Sheet] |
− | * OWASP CSRFGuard - CSRF Defense Tool | + | * [https://www.owasp.org/index.php/CSRFGuard OWASP CSRFGuard - CSRF Defense Tool ] |
− | * ESAPI Project Home Page | + | * [https://www.owasp.org/index.php/ESAPI ESAPI Project Home Page] |
− | * ESAPI HTTPUtilities Class with AntiCSRF Tokens | + | * [http://owasp-esapi-java.googlecode.com/svn/trunk_doc/latest/org/owasp/esapi/HTTPUtilities.html ESAPI HTTPUtilities Class with AntiCSRF Tokens] |
− | * OWASP Testing Guide: Chapter on CSRF Testing | + | * [https://www.owasp.org/index.php/Testing_for_CSRF_(OWASP-SM-005) OWASP Testing Guide: Chapter on CSRF Testing] |
− | * OWASP CSRFTester - CSRF Testing Tool | + | * [https://www.owasp.org/index.php/CSRFTester OWASP CSRFTester - CSRF Testing Tool ] |
− | {{Top_10_2010:SubSubsectionExternalReferencesTemplate}} | + | |
− | * CWE Entry 352 on CSRF | + | {{Top_10_2010:SubSubsectionExternalReferencesTemplate|language=en}} |
+ | * [http://cwe.mitre.org/data/definitions/352.html CWE Entry 352 on CSRF] | ||
{{Top_10_2013:BottomAdvancedTemplate | {{Top_10_2013:BottomAdvancedTemplate | ||
|type={{Top_10_2010:StyleTemplate}} | |type={{Top_10_2010:StyleTemplate}} | ||
|usenext=2013NextLink | |usenext=2013NextLink | ||
− | |next={{Top_10_2010:ByTheNumbers | + | |next=A9-{{Top_10_2010:ByTheNumbers |
|9 | |9 | ||
− | |year=2013}} | + | |year=2013 |
+ | |language=en}} | ||
|useprev=2013PrevLink | |useprev=2013PrevLink | ||
− | |prev={{Top_10_2010:ByTheNumbers | + | |prev=A7-{{Top_10_2010:ByTheNumbers |
|7 | |7 | ||
− | |year=2013}}}} | + | |year=2013 |
− | + | |language=en}} | |
− | + | |year=2013 | |
+ | |language=en | ||
+ | }} |
Latest revision as of 18:13, 18 September 2013
NOTE: THIS IS NOT THE LATEST VERSION. Please visit the OWASP Top 10 project page to find the latest edition.
← A7-Missing Function Level Access Control | A9-Using Components with Known Vulnerabilities → |
Threat Agents | Attack Vectors | Security Weakness | Technical Impacts | Business Impacts | |
---|---|---|---|---|---|
Application Specific | Exploitability AVERAGE |
Prevalence COMMON |
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. Any website or other HTML feed that your users access could do this. |
Attacker creates forged HTTP requests and tricks a victim into submitting them via image tags, XSS, or numerous other techniques. If the user is authenticated, the attack succeeds. |
CSRF takes advantage 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, logout and even login. |
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, either through reauthentication, or some other proof they are a real user (e.g., a CAPTCHA). Focus on the links and forms that invoke state-changing functions, since those are the most important CSRF targets. You should check multistep transactions, as they are not inherently immune. Attackers can easily forge a series of requests by using multiple tags or possibly JavaScript. Note that session cookies, source IP addresses, and other information automatically sent by the browser don’t provide any defense against CSRF since this information is also included in 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)'?
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.
|
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="http://example.com/app/transferFunds?amount=1500&destinationAccount=attackersAcct#" 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
External |
← A7-Missing Function Level Access Control | A9-Using Components with Known Vulnerabilities → |
