# The clickjacking attack The "clickjacking" attack allows an evil page to click on a "victim site" *on behalf of the visitor*. Many sites were hacked this way, including Twitter, Facebook, Paypal and other sites. They are all fixed, of course. [cut] ## The idea The idea is very simple. Here's how clickjacking was done with Facebook: 1. A visitor is lured to the evil page. It doesn't matter how. 2. The page has a harmless-looking link on it (like "get rich now" or "click here, very funny"). 3. Over that link the evil page positions a transparent ` */!*
...And you're cool (I'm a cool hacker actually)!
``` The full demo of the attack: [codetabs src="clickjacking-visible" height=160] Here we have a half-transparent ` ``` There are other ways to work around that simple protection too. ## X-Frame-Options The server-side header `X-Frame-Options` can permit or forbid displaying the page inside a frame. It must be sent *by the server*: the browser will ignore it if found in a `` tag. So, `` won't do anything. The header may have 3 values: `DENY` : Never ever show the page inside a frame. `SAMEORIGIN` : Allow inside a frame if the parent document comes from the same origin. `ALLOW-FROM domain` : Allow inside a frame if the parent document is from the given domain. For instance, Twitter uses `X-Frame-Options: SAMEORIGIN`. Here's the result: ```html ``` Depending on your browser, the `iframe` above is either empty or alerting you that the browser won't permit that page to be navigating in this way. ## Showing with disabled functionality The `X-Frame-Options` header has a side-effect. Other sites won't be able to show our page in a frame, even if they have good reasons to do so. So there are other solutions... For instance, we can "cover" the page with a `
` with `height: 100%; width: 100%;`, so that it intercepts all clicks. That `
` should disappear if `window == top` or if we figure out that we don't need the protection. Something like this: ```html ``` The demo: [codetabs src="protector"] ## Summary Clickjacking is a way to "trick" users into clicking on a malicious site without even knowing what's happening. That's dangerous if there are important click-activated actions. A hacker can post a link to his evil page in a message, or lure visitors to his page by some other means. There are many variations. From one perspective -- the attack is "not deep": all a hacker is doing is intercepting a single click. But from another perspective, if the hacker knows that after the click another control will appear, then he may use cunning messages to coerce the user into clicking on them as well. The attack is quite dangerous, because when we engineer the UI we usually don't anticipate that a hacker may click on behalf of the visitor. So vulnerabilities can be found in totally unexpected places. - It is recommended to use `X-Frame-Options: SAMEORIGIN` on pages (or whole websites) which are not intended to be viewed inside frames. - Use a covering `
` if we want to allow our pages to be shown in iframes, but still stay safe.