Difference between revisions of "Clickjacking Defense Cheat Sheet"

Jump to: navigation, search
m (X-FRAME-OPTION Header Types)
(Browser Support)
Line 18: Line 18:
=== Browser Support ===
=== Browser Support ===
* The following browsers support X-FRAME-OPTIONS headers. from [http://blogs.msdn.com/b/ieinternals/archive/2010/03/30/combating-clickjacking-with-x-frame-options.aspx http://blogs.msdn.com/b/ieinternals/archive/2010/03/30/combating-clickjacking-with-x-frame-options.aspx])
The following browsers support X-FRAME-OPTIONS headers.
** IE8+
** Opera 10.50+
<table border="1">
** Safari 4+
<tr> <th>Browser</th> <th>Lowest version</th></tr>
** Chrome
<tr> <td>Internet Explorer</td> <td>8.0</td></tr>
** Firefox 3.6.9 (or earlier with NoScript)
<tr> <td>Firefox (Gecko)</td> <td>3.6.9 (</td></tr>
<tr> <td>Opera</td> <td>10.50</td> </tr> <tr> <td>Safari</td> <td>4.0</td></tr>
<tr> <td>Chrome</td> <td></td> </tr>
Reference: [https://developer.mozilla.org/en-US/docs/The_X-FRAME-OPTIONS_response_header https://developer.mozilla.org/en-US/docs/The_X-FRAME-OPTIONS_response_header]
=== Implementation ===
=== Implementation ===

Revision as of 20:43, 1 December 2012

Clickjacking Defense Introduction

This cheat sheet is focused on providing developer guidance on Clickjack/UI Redress attack prevention. For more information on the risk of Clickjacking, please visit this page.

The most popular way to defend against clickjacking is to include some sort of "frame-breaking" functionality which prevents other web pages from framing the site you wish to defend. This cheat sheet will discuss two methods of implementing frame-braking; via X-FRAME-OPTIONS headers (if the browser or browsers in question support it) and via javascript "frame-breaking" code.

Defending with X-FRAME-OPTIONS response headers

The X-FRAME-OPTIONS header is used to mark responses that should not be framed.


There are three types of X-FRAME-OPTIONS headers.

  • The first is X-FRAME-OPTIONS DENY, which prevents any domain from framing the content.
  • The second option is X-FRAME-OPTIONS SAMEORIGIN, which only allows the current site to frame the content.
  • The third, is the X-FRAME-OPTIONS ALLOW-FROM 'sitename' header, which permits the specified 'sitename' to frame this page. (e.g., ALLOW-FROM http://www.foo.com) The ALLOW-FROM option is a relatively recent addition (circa 2012) and may not be supported by all browsers yet.

Browser Support

The following browsers support X-FRAME-OPTIONS headers.

Browser Lowest version
Internet Explorer 8.0
Firefox (Gecko) 3.6.9 (
Opera 10.50
Safari 4.0

Reference: https://developer.mozilla.org/en-US/docs/The_X-FRAME-OPTIONS_response_header


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.

Defending legacy browsers

The following methodology will prevent a webpage from being framed even in legacy browsers.

In the document HEAD element, add the following:

First apply an ID to the style element itself:

<style id="antiClickjack">body{display:none !important;}</style>

And then delete that style by its ID immediately after in the script:

<script type="text/javascript">
   if (self === top) {
       var antiClickjack = document.getElementById("antiClickjack");
   } else {
       top.location = self.location;

This way, everything can be in the document HEAD and you only need one method/taglib in your API.


OWASP Cheat Sheets Project Homepage