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 "Clickjacking"

From OWASP
Jump to: navigation, search
(References: added Mozilla's CSP/frame-ancestors)
 
(45 intermediate revisions by 10 users not shown)
Line 1: Line 1:
Clickjacking, also known as a "UI redress attack", is when an attacker uses multiple transparent or opaque layers to trick a user into clicking on a button or link on another page when they were intending to click on the the top level page. Thus, the attacker is "hijacking" clicks meant for their page and routing them to other another page, most likely owned by another application, domain, or both.
+
Clickjacking, also known as a "UI redress attack", is when an attacker uses multiple transparent or opaque layers to trick a user into clicking on a button or link on another page when they were intending to click on the the top level page. Thus, the attacker is "hijacking" clicks meant for their page and routing them to another page, most likely owned by another application, domain, or both.
  
 
Using a similar technique, keystrokes can also be hijacked. With a carefully crafted combination of stylesheets, iframes, and text boxes, a user can be led to believe they are typing in the password to their email or bank account, but are instead typing into an invisible frame controlled by the attacker.
 
Using a similar technique, keystrokes can also be hijacked. With a carefully crafted combination of stylesheets, iframes, and text boxes, a user can be led to believe they are typing in the password to their email or bank account, but are instead typing into an invisible frame controlled by the attacker.
Line 11: Line 11:
 
Clickjacking also made the news in the form of a [http://shiflett.org/blog/2009/feb/twitter-dont-click-exploit Twitter worm]. This clickjacking attack convinced users to click on a button which caused them to re-tweet the location of the malicious page, and propagated massively.
 
Clickjacking also made the news in the form of a [http://shiflett.org/blog/2009/feb/twitter-dont-click-exploit Twitter worm]. This clickjacking attack convinced users to click on a button which caused them to re-tweet the location of the malicious page, and propagated massively.
  
Recently, clickjacking attacks abusing Facebook's "Like" functionality has grown significantly. [http://threatpost.com/en_us/blogs/facebook-jacking-scams-expand-060310 Attackers can trick logged-in Facebook users to arbitrarily like fan pages, links, groups, etc]  
+
There have also been clickjacking attacks abusing Facebook's "Like" functionality. [http://threatpost.com/en_us/blogs/facebook-jacking-scams-expand-060310 Attackers can trick logged-in Facebook users to arbitrarily like fan pages, links, groups, etc]
  
=Defending against Clickjacking=
+
= Defending against Clickjacking =
There are three main ways to prevent clickjacking: employing defensive code in the UI to ensure that the current frame is the most top level window, and by sending the browser response headers that indicate an unwillingness to be framed.
+
There are two main ways to prevent clickjacking:
 +
# Sending the proper Content Security Policy (CSP) frame-ancestors directive response headers that instruct the browser to not allow framing from other domains. (This replaces the older X-Frame-Options HTTP headers.)
 +
# Employing defensive code in the UI to ensure that the current frame is the most top level window
  
==Defending with frame breaking scripts==
+
For more information on Clickjacking defense, please see the the [[Clickjacking Defense Cheat Sheet]].
===Specifics===
 
The most popular way to defend against clickjacking is to include a "frame-breaker" script in each page that should not be framed. Consider the following:
 
  
<pre><script>if (top!=self) top.location.href=self.location.href</script></pre>
+
= References =
 +
* [https://www.linkedin.com/pulse/20141202104842-120953718-why-am-i-anxious-about-clickjacking Why am I anxious about Clickjacking?]
 +
:  A Basic understanding of Clickjacking Attack
  
===Limitation===
+
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors
This simple frame breaking script attempts to prevent the page from being incorporated into a frame or iframe by forcing the parent window to load the current frame's URL. Unfortunately, multiple ways of defeating this type of script have been made public. We outline some here.
+
: Mozilla developer resource on Content-Security-Policy frame-ancestors response header.
  
====Double Framing====
+
* https://developer.mozilla.org/en-US/docs/The_X-FRAME-OPTIONS_response_header
 +
: Mozilla developer resource on the X-Frame-Options response header.
  
====The onBeforeUnload Event====
 
 
====No-Content Flushing====
 
 
====Exploiting XSS filters====
 
 
 
====Referrer checking issues====
 
 
 
====Clobbering top.location====
 
 
====Restricted zones====
 
 
 
 
===Best-for-now implementation===
 
<pre>
 
<head>
 
<style> body { display : none;} </style>
 
</head>
 
<body>
 
 
<script>
 
if (self == top) {
 
  var theBody = document.getElementsByTagName('body')[0];
 
  theBody.style.display = "block";
 
} else {
 
  top.location = self.location;
 
}
 
</script>
 
</pre>
 
==Defending with response headers==
 
 
===X-FRAME-OPTIONS===
 
====Specifics====
 
Recently, Microsoft introduced a non-standard header that may be simpler to implement in some applications.  However, there's an alternative approach that may be simpler to implement. Microsoft has now included a [http://blogs.msdn.com/ie/archive/2009/01/27/ie8-security-part-vii-clickjacking-defenses.aspx defense] in IE8 that allows developers to specify that pages should not be framed. They use a new (nonstandard) X-FRAME-OPTIONS header to mark responses that shouldn't be framed. There are two options with X-FRAME-OPTIONS. The first is DENY, which prevents everyone from framing the content. The other option is SAMEORIGIN, which only allows the current site to frame the content. X-FRAME-OPTIONS has seen good adoption by major browsers, unfortunately studies have shown the header [http://blogs.sans.org/appsecstreetfighter/2009/10/15/adoption-of-x-frame-options-header/ not to be widely deployed by sites].
 
 
====Limitations====
 
 
* '''Per-page policy specifcation'''
 
The policy needs to be specifed for every page,  which can complicate deployment. Providing the ability to enforce it for the entire site, at login time for instance, could simplify adoption.
 
 
* '''Problems with multi-domain sites'''
 
The current implementation does not allow the webmaster to provide a whitelist of domains that are allowed to frame the page. While whitelisting can be dangerous , in some cases a webmaster might have no choice but to use more than one hostname.
 
 
* '''Proxies'''
 
Web proxies are notorious for adding and stripping headers. If a web proxy strips the X-FRAME-OPTIONS header then the site loses its framing protection.
 
 
====Implementation====
 
To implement this protection, you need to add the header to any page that you want to protect from being clickjacked. One way to do this is to add the header manually to every page.  A possibly simpler way is to implement a filter that automatically adds the header to every page.
 
 
OWASP has an [[ClickjackFilter for Java EE|article and some code]] that provides all the details for implementing this in the Java EE environment.
 
 
The SDL blog has posted an [http://blogs.msdn.com/sdl/archive/2009/02/05/clickjacking-defense-in-ie8.aspx article] covering how to implement this in a .NET environment.
 
 
== References ==
 
 
* [http://w2spconf.com/2010/papers/p27.pdf Busting Frame Busting: A study of clickjacking vulnerabilites on top sites]
 
* [http://w2spconf.com/2010/papers/p27.pdf Busting Frame Busting: A study of clickjacking vulnerabilites on top sites]
 
: A study by the Stanford Web Security Group outlining problems with deployed frame busting code.
 
: A study by the Stanford Web Security Group outlining problems with deployed frame busting code.
Line 89: Line 35:
 
* [http://www.sectheory.com/clickjacking.htm Clickjacking, Sec Theory]
 
* [http://www.sectheory.com/clickjacking.htm Clickjacking, Sec Theory]
 
: A paper by Robert Hansen defining the term, its implications against Flash at the time of writing, and a disclosure timeline.
 
: A paper by Robert Hansen defining the term, its implications against Flash at the time of writing, and a disclosure timeline.
 +
 +
* [https://www.codemagi.com/blog/post/194 https://www.codemagi.com/blog/post/194]
 +
: Framebreaking defense for legacy browsers that do not support X-Frame-Option headers.
  
 
* [[ClickjackFilter_for_Java_EE|Anti-clickjacking J2EE filter]]
 
* [[ClickjackFilter_for_Java_EE|Anti-clickjacking J2EE filter]]
 
: A simple J2EE servlet filter that sends anti-framing headers to the browser.
 
: A simple J2EE servlet filter that sends anti-framing headers to the browser.

Latest revision as of 21:16, 21 December 2017

Clickjacking, also known as a "UI redress attack", is when an attacker uses multiple transparent or opaque layers to trick a user into clicking on a button or link on another page when they were intending to click on the the top level page. Thus, the attacker is "hijacking" clicks meant for their page and routing them to another page, most likely owned by another application, domain, or both.

Using a similar technique, keystrokes can also be hijacked. With a carefully crafted combination of stylesheets, iframes, and text boxes, a user can be led to believe they are typing in the password to their email or bank account, but are instead typing into an invisible frame controlled by the attacker.

Examples

For example, imagine an attacker who builds a web site that has a button on it that says "click here for a free iPod". However, on top of that web page, the attacker has loaded an iframe with your mail account, and lined up exactly the "delete all messages" button directly on top of the "free iPod" button. The victim tries to click on the "free iPod" button but instead actually clicked on the invisible "delete all messages" button. In essence, the attacker has "hijacked" the user's click, hence the name "Clickjacking".

One of the most notorious examples of Clickjacking was an attack against the Adobe Flash plugin settings page. By loading this page into an invisible iframe, an attacker could trick a user into altering the security settings of Flash, giving permission for any Flash animation to utilize the computer's microphone and camera.

Clickjacking also made the news in the form of a Twitter worm. This clickjacking attack convinced users to click on a button which caused them to re-tweet the location of the malicious page, and propagated massively.

There have also been clickjacking attacks abusing Facebook's "Like" functionality. Attackers can trick logged-in Facebook users to arbitrarily like fan pages, links, groups, etc

Defending against Clickjacking

There are two main ways to prevent clickjacking:

  1. Sending the proper Content Security Policy (CSP) frame-ancestors directive response headers that instruct the browser to not allow framing from other domains. (This replaces the older X-Frame-Options HTTP headers.)
  2. Employing defensive code in the UI to ensure that the current frame is the most top level window

For more information on Clickjacking defense, please see the the Clickjacking Defense Cheat Sheet.

References

A Basic understanding of Clickjacking Attack
Mozilla developer resource on Content-Security-Policy frame-ancestors response header.
Mozilla developer resource on the X-Frame-Options response header.
A study by the Stanford Web Security Group outlining problems with deployed frame busting code.
A paper by Robert Hansen defining the term, its implications against Flash at the time of writing, and a disclosure timeline.
Framebreaking defense for legacy browsers that do not support X-Frame-Option headers.
A simple J2EE servlet filter that sends anti-framing headers to the browser.