# 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. No matter how. 2. The page has a harmlessly-looking link on it (like "get rich now" or "click here, very funny" and so on). 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 Server-side header `X-Frame-Options` can allow or forbid showing the page inside a frame. It must be sent by the server: browser ignore it if found in `` tags. So `` won't do anything. The header may have 3 values: `DENY` : Never ever show the page inside an iframe. `SAMEORIGIN` : Allow to show inside an iframe if the parent document comes from the same origin. `ALLOW-FROM domain` : Allows to show inside an iframe if the parent document is from the given domain. For instance, Twitter uses `X-Frame-Options: SAMEORIGIN`. Here's the result: ```html ``` Depending on the browser, `iframe` above is either empty or it has a message telling that "the browser can't show it". ## Showing with disabled functionality The protecting `X-Frame-Options` header has a side-effect. Other sites can't show our page in an `iframe`, even if they have "legal" 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 handles all clicks. That `
` should disappear if `window == top` or we figure out that we don't need protection. Like this: ```html ``` The demo: [codetabs src="protector"] ## Summary Clickjacking is a way to "trick" users into a clicking on a victim site without even knowing what happens. 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 other means. There are many variants. From one side -- the attack is "not deep": all a hacker can do is one click. But from another side, if the hacker knows that after the click another control appears, then it may use cunning messages to make the user to click on it as well. The attack is quite dangerous, because when we engineer the UI we usually don't think that a hacker can click on behalf of the visitor. So vulnerabilities can be found in totally unexpeced places. - It's recommended to use `X-Frame-Options: SAMEORIGIN` on pages that are totally not meant to be shown inside iframes (or just for the whole site). - Use a covering `
` if we want to allow our pages to be shown in iframes, and still stay safe.