Difference between revisions of "Top 10 2013-A8-Cross-Site Request Forgery (CSRF)"

From OWASP
Jump to: navigation, search
(Changed use of Template 'Top_10_2010:SubsectionAdvancedTemplate': Replace Parameter 'number' by 'subsection' and 'position')
Line 33: Line 33:
 
{{Top_10_2010:SummaryTableEndTemplate}}
 
{{Top_10_2010:SummaryTableEndTemplate}}
  
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|number=1|risk=8|year=2013}}
+
{{Top_10:SubsectionTableBeginTemplate|type=main}} {{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=vulnerableTo|position=firstLeft|risk=8|year=2013}}
 
To check whether an application is vulnerable, see if each link and form includes an unpredictable 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).
 
To check whether an application is vulnerable, see if each link and form includes an unpredictable 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.
Line 39: Line 39:
 
Note that session cookies, source IP addresses, and other information 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 automatically sent by the browser doesn’t count since this information is also included in forged requests.
 
[https://www.owasp.org/index.php/CSRFTester CSRF Tester] tool can help generate test cases to demonstrate the dangers of CSRF flaws.
 
[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}}|number=2|risk=8|year=2013}}
+
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=howPrevent|position=right|risk=8|year=2013}}
 
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 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.
Line 45: Line 45:
 
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 CSRF methods developers can use to prevent such vulnerabilities.
 
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 CSRF methods developers can use to prevent such vulnerabilities.
 
# 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}}|number=3|risk=8|year=2013}}
+
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=example|position=left|risk=8|year=2013}}
 
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}}
Line 56: Line 56:
 
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.
 
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}}|number=4|risk=8|year=2013}}
+
{{Top_10_2010:SubsectionAdvancedTemplate|type={{Top_10_2010:StyleTemplate}}|subsection=references|position=right|risk=8|year=2013}}
 
{{Top_10_2010:SubSubsectionOWASPReferencesTemplate}}
 
{{Top_10_2010:SubSubsectionOWASPReferencesTemplate}}
 
* [https://www.owasp.org/index.php/CSRFGuard  OWASP CSRF Article]
 
* [https://www.owasp.org/index.php/CSRFGuard  OWASP CSRF Article]

Revision as of 18:00, 13 April 2013

[[Top 10 {{{year}}}-Missing Function Level Access Control|← Missing Function Level Access Control]]
2013 Table of Contents

2013 Top 10 List

[[Top 10 {{{year}}}-Using Components with Known Vulnerabilities|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 of the fact that most web apps 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 other function the victim is authorized to use, including state changing requests, like logout or 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 each link and form includes an unpredictable 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 doesn’t count since this information is also included in forged requests. 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.

  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 automatically include such tokens in Java EE, .NET, or PHP apps. OWASP’s ESAPI includes CSRF methods developers can use to prevent such vulnerabilities.

  1. Requiring the user to reauthenticate, or prove they are a user (e.g., via a CAPTCHA) can also protect against CSRF.
Example Attack Scenarios

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

<img src="<span style="color: red;">http://example.com/app/transferFunds?amount=1500&destinationAccount=attackersAcct#</span>" width="0" height="0" />

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 like so: 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

[[Top 10 {{{year}}}-Missing Function Level Access Control|← Missing Function Level Access Control]]
2013 Table of Contents

2013 Top 10 List

[[Top 10 {{{year}}}-Using Components with Known Vulnerabilities|Using Components with Known Vulnerabilities →]]

© 2002-2013 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
[[Category:OWASP Top Ten {{{year}}} Project]]