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 2010-A5-Cross-Site Request Forgery (CSRF)"

From OWASP
Jump to: navigation, search
m (grammar)
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Top_10_2010:TopTemplate|usenext=NextLink|next=-Broken Authentication and Session Management|useprev=PrevLink|prev=-Cross Site Request Forgery|usemain=MainLink|main=}}  
+
{{Top_10_2010:TopTemplate|useprev=2010PrevLink|usenext=2010NextLink|prev=A4-Insecure Direct Object References|next=A6-Security Misconfiguration}}
  
<center>
+
{{Top_10_2010:SummaryTableHeaderBeginTemplate}}
{| style="align:center; text-align:center; border:2px solid #4F81BD; background-color:#F2F2F2; padding=2;"
+
{{Top_10_2010:SummaryTableValue-2-Template|Exploitability|AVERAGE}}
|- style="background-color: #4F81Bd; color: #000000;"
+
{{Top_10_2010:SummaryTableValue-1-Template|Prevalence|WIDESPREAD}}
! Threat Agents !! Attack Vectors
+
{{Top_10_2010:SummaryTableValue-1-Template|Detectability|EASY}}
! colspan="2" | Security Weakness
+
{{Top_10_2010:SummaryTableValue-2-Template|Impact|MODERATE}}
! Technical Impact
+
{{Top_10_2010:SummaryTableHeaderEndTemplate}}
! Business Impacts
+
    <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>Consider anyone who can trick your users into submitting a request to your website. Any website or other HTML feed that your users access could do this.</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. If the <u>user is authenticated</u>, the attack succeeds.</td>
| style="background-color: #D9D9D9; color: #000000;" | ______
+
    <td colspan=2 {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>[[CSRF]] takes advantage of web applications that allow attackers to predict all the details of a particular action.<br/><br/>Since browsers send credentials like session cookies automatically, attackers can create malicious web pages which generate forged requests that are indistinguishable from legitimate ones.<br/><br/>Detection of CSRF flaws is fairly easy via penetration testing or code analysis.</td>
| style="background-color: #FFB200; color: #000000;" | Exploitability<br>AVERAGE
+
    <td {{Template:Top 10 2010:SummaryTableRowStyleTemplate}}>Attackers can cause victims to change any data the victim is allowed to change or perform any function the victim is authorized to use</td>
| style="background-color: #FF00FF; color: #000000;" | Prevalence<br>WIDESPREAD
+
    <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.<br/><br/>Consider the impact to your reputation.</td>
| style="background-color: #FF0000; color: #000000;" | Detectability<br>EASY
+
{{Top_10_2010:SummaryTableEndTemplate}}
| style="background-color: #FFB200; color: #000000;" | Impact<br>MODERATE
 
| style="background-color: #D9D9D9; color: #000000;" | ______
 
|-
 
| style="text-align: left; border: 2px solid #FFFFFF;" | Consider anyone who can trick your users into submitting a request to your website. Any website or other HTML feed that your users access could do this.
 
| style="text-align: left; border: 2px solid #FFFFFF;" | Attacker creates forged HTTP requests and tricks a victim into submitting them via image tags, XSS, or numerous other techniques. If the <u>user is authenticated</u>, the attack succeeds.
 
| colspan="2" style="text-align: left;border: 2px solid #FFFFFF;" | [http://www.owasp.org/index.php/CSRF CSRF] takes advantage of web applications that allow attackers to predict all the details of a particular action.
 
  
Since browsers send credentials like session cookies automatically, attackers can create malicious web pages which generate forged requests that are indistinguishable from legitimate ones.
+
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|number=1|risk=5}}
 
 
Detection of CSRF flaws is fairly easy via penetration testing or code analysis.
 
| style="text-align: left; border: 2px solid #FFFFFF;" | Attackers can cause victims to change any data the victim is allowed to change or perform any function the victim is authorized to use.
 
| style="text-align: left; border: 2px solid #FFFFFF;" | 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.
 
|}
 
</center>
 
 
 
{{Top_10_2010:SubsectionVulnerableTemplate|CSRF|
 
 
The easiest way to check whether an application is vulnerable is to see if each link and form contains an unpredictable token for each user. Without such an unpredictable token, attackers can forge malicious requests. Focus on the links and forms that invoke state-changing functions, since those are the most important CSRF targets.
 
The easiest way to check whether an application is vulnerable is to see if each link and form contains an unpredictable token for each user. Without such an unpredictable token, attackers can forge malicious requests. 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 multi-step 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 that is automatically sent by the browser doesn’t count since this information is also included in forged requests.
 
Note that session cookies, source IP addresses, and other information that is automatically sent by the browser doesn’t count since this information is also included in forged requests.
  
OWASP’s [http://www.owasp.org/index.php/CSRFTester CSRF Tester] tool can help generate test cases to demonstrate the dangers of CSRF flaws.
+
OWASP’s [[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}}|number=2|risk=5}}
 
+
Preventing CSRF requires the inclusion of an unpredictable token in the body or URL of each HTTP request. Such tokens should at a minimum be unique per user session, but can also be unique per request.
{{Top_10_2010:SubsectionPreventionTemplate|CSRF|
 
Preventing CSRF requires the inclusion of a unpredictable token in the body or URL of each HTTP request. Such tokens should at a minimum be unique per user session, but can also be unique per request.
 
 
#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 subject to exposure.
 
#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 subject to exposure.
 
#The unique token can also be included in the URL itself, or a URL parameter. However, such placement runs the risk that the URL will be exposed to an attacker, thus compromising the secret token.
 
#The unique token can also be included in the URL itself, or a URL parameter. However, such placement runs the risk that the URL will be exposed to an attacker, thus compromising the secret token.
  
OWASP’s [http://www.owasp.org/index.php/CSRFGuard CSRF Guard] can be used to automatically include such tokens in your Java EE, .NET, or PHP application. OWASP’s [http://owasp-esapi-java.googlecode.com/svn/trunk_doc/latest/org/owasp/esapi/HTTPUtilities.html ESAPI] includes token generators and validators that developers can use to protect their transactions.
+
OWASP’s [[CSRFGuard | CSRF Guard]] can be used to automatically include such tokens in your Java EE, .NET, or PHP application. OWASP’s [http://owasp-esapi-java.googlecode.com/svn/trunk_doc/latest/org/owasp/esapi/HTTPUtilities.html ESAPI] includes token generators and validators that developers can use to protect their transactions.
}}
+
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|number=3|risk=5}}
 
 
{{Top_10_2010:SubsectionExampleTemplate|CSRF|}}
 
 
The application allows a user to submit a state changing request that does not include anything secret. Like so:
 
The application allows a user to submit a state changing request that does not include anything secret. Like so:
:<b><nowiki>http://example.com/app/transferFunds?amount=1500&</nowiki>destinationAccount=4673243243</b>
+
{{Top_10_2010:ExampleBeginTemplate}}<nowiki>http://example.com/app/transferFunds?amount=1500&amp;destinationAccount=4673243243</nowiki>{{Top_10_2010:ExampleEndTemplate}}
 
So, the attacker constructs a request that will transfer money from the victim’s account to their account, and then embeds this attack in an image request or iframe stored on various sites under the attacker’s control.
 
So, the attacker constructs a request that will transfer money from the victim’s account to their account, and then embeds this attack in an image request or iframe stored on various sites under the attacker’s control.
:<b>TODO: <nowiki>&lt;img src="</nowiki><span style="color: red;"><nowiki>http://example.com/app/transferFunds?amount=1500&destinationAccount=attackersAcct#“width="0" height="0" /&gt;</nowiki></span></b>
+
{{Top_10_2010:ExampleBeginTemplate}}<nowiki>&lt;img src="http://example.com/app/transferFunds?amount=1500&destinationAccount=attackersAcct#" width="0" height="0" /&gt;</nowiki>{{Top_10_2010:ExampleEndTemplate}}
 
If the victim visits any of these sites while already authenticated to example.com, any forged requests will include the user’s session info, inadvertently authorizing the request.
 
If the victim visits any of these sites while already authenticated to example.com, any forged requests will include the user’s session info, inadvertently authorizing the request.
{{Top_10_2010:SubsectionReferencesTemplate|CSRF}}
+
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|number=4|risk=5}}
 
{{Top_10_2010:SubSubsectionOWASPReferencesTemplate}}
 
{{Top_10_2010:SubSubsectionOWASPReferencesTemplate}}
*[http://www.owasp.org/index.php/CSRF OWASP CSRF Article]
+
*[[CSRF | OWASP CSRF Article]]
*[http://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet OWASP CSRF Prevention Cheat Sheet]
+
*[[Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet | OWASP CSRF Prevention Cheat Sheet]]
*[http://www.owasp.org/index.php/CSRFGuard OWASP CSRFGuard - CSRF Defense Tool]
+
*[[CSRFGuard | OWASP CSRFGuard - CSRF Defense Tool]]
*[http://www.owasp.org/index.php/ESAPI ESAPI Project Home Page]
+
*[[ESAPI | ESAPI Project Home Page]]
 
*[http://owasp-esapi-java.googlecode.com/svn/trunk_doc/latest/org/owasp/esapi/HTTPUtilities.html 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]
*[http://www.owasp.org/index.php/Testing_for_CSRF_(OWASP-SM-005) OWASP Testing Guide: Chapter on CSRF Testing]
+
*[[Testing_for_CSRF_(OWASP-SM-005) | OWASP Testing Guide: Chapter on CSRF Testing]]
*[http://www.owasp.org/index.php/CSRFTester OWASP CSRFTester - CSRF Testing Tool]
+
*[[CSRFTester | OWASP CSRFTester - CSRF Testing Tool]]
 
{{Top_10_2010:SubSubsectionExternalReferencesTemplate}}
 
{{Top_10_2010:SubSubsectionExternalReferencesTemplate}}
 
*[http://cwe.mitre.org/data/definitions/352.html CWE Entry 352 on CSRF]
 
*[http://cwe.mitre.org/data/definitions/352.html CWE Entry 352 on CSRF]
 +
{{Top_10_2010:BottomAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|useprev=2010PrevLink|usenext=2010NextLink|prev=A4-Insecure Direct Object References|next=A6-Security Misconfiguration}}
  
<br> {{Top_10_2010:BottomTemplate|usenext=NextLink|next=-Broken Authentication and Session Management|useprev=PrevLink|prev=-Cross Site Request Forgery|usemain=MainLink|main=}}
+
[[Category:OWASP Top Ten Project]]

Latest revision as of 13:29, 19 March 2012

NOTE: THIS IS NOT THE LATEST VERSION. Please visit the OWASP Top 10 project page to find the latest edition.

← A4-Insecure Direct Object References
Top 10 Introduction
Top 10 Risks
A6-Security Misconfiguration →
Threat Agents Attack Vectors Security Weakness Technical Impacts Business Impacts
Application Specific Exploitability
AVERAGE
Prevalence
WIDESPREAD
Detectability
EASY
Impact
MODERATE
Application / Business Specific
Consider anyone who can trick your users into submitting 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 of web applications that allow attackers to predict all the details of a particular action.

Since 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 cause victims to change any data the victim is allowed to change or perform any function the victim is authorized to use 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)'?

The easiest way to check whether an application is vulnerable is to see if each link and form contains an unpredictable token for each user. Without such an unpredictable token, attackers can forge malicious requests. Focus on the links and forms that invoke state-changing functions, since those are the most important CSRF targets.

You should check multi-step 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 that is automatically sent by the browser doesn’t count 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 requires the inclusion of an unpredictable token in the body or URL of each HTTP request. Such tokens should at a minimum be unique per user session, but can also be unique per request.

  1. 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 subject to exposure.
  2. The unique token can also be included in the URL itself, or a URL parameter. However, such placement runs the risk that the URL will be exposed to an attacker, thus compromising the secret token.

OWASP’s CSRF Guard can be used to automatically include such tokens in your Java EE, .NET, or PHP application. OWASP’s ESAPI includes token generators and validators that developers can use to protect their transactions.

Example Attack Scenarios

The application allows a user to submit a state changing request that does not include anything secret. Like so:

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 their 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 these sites while already authenticated to example.com, any forged requests will include the user’s session info, inadvertently authorizing the request.

References

OWASP

External

← A4-Insecure Direct Object References
Top 10 Introduction
Top 10 Risks
A6-Security Misconfiguration →

© 2002-2010 OWASP Foundation This document is licensed under the Creative Commons Attribution-ShareAlike 3.0 license. Some rights reserved. CC-by-sa-3 0-88x31.png