Clickjacking attacks attempt to trick the user into unintentionally clicking an unexpected web page element. Most clickjacking methods exploit vulnerabilities related to HTML iframes and prevention centers around preventing page framing. In this blog post, we will see how clickjacking works, how it can be prevented, and why this threat to application security is not going away any time soon.
Clickjacking refers to any attack where the user is tricked into unintentionally clicking an unexpected web page element. The name was coined from click hijacking, and the technique is most often applied to web pages by overlaying malicious content over a trusted page or by placing a transparent page on top of a visible one. When the user clicks an innocent-looking item on the visible page, they are actually clicking the corresponding location on the overlaid page and the click triggers a malicious action – anything from faking a like or follow on social media to siphoning money from the user’s bank account.
The majority of clickjacking attacks exploit vulnerabilities related to HTML iframes and protection methods center around preventing page framing. In this blog post, we will see how clickjacking works, how it can be prevented, and why this threat to application security is not going away any time soon.
By far the most common approach to clickjacking involves presenting the user with a mix of two overlaid web pages in the browser window and some kind of incentive to click in specified places. The attacker starts by loading the vulnerable target website into an iframe, sets it to full transparency, and places the frame in front of a malicious web page created to elicit clicks in suitable places.For example, imagine a fun browser-based game displayed in a popup window, perhaps offering prizes or attractive content for winners. The game could be shown as the background page, and the targeted web application, such as a banking or e-commerce site, overlaid on top of it in a completely transparent frame. The attacker crafts the game page so that clickable items are in the same position as selected controls on the targeted site. When attempting to click in-game items, the user is actually clicking invisible controls on the vulnerable web page with potentially serious consequences.Depending on the site used, the victim might be unwittingly sending 5-star reviews, liking dubious Facebook pages, giving permissions to Facebook applications, logging in using SSO schemes, or using 1-click shopping to ship expensive items to the attacker. If combined with drag-and-drop techniques, the attack might also trick the user into completing text fields in a web form or filling CAPTCHAs. In this case, carefully prepared interactions with the game cause the user to unknowingly drag text on the invisible page and drop it on a form field.
Clickjacking is not one specific attack, but a broad family of attack vectors and techniques, broadly termed UI redress attacks. Attacks can be divided into two general categories, based on the use of overlaid content. Overlay-based attacks are by far the most popular, and embedding pages in invisible iframes is the most common technical approach here. Again, there are several main categories of overlay-based clickjacking:
Even without exploiting clickjacking vulnerabilities to insert overlays, attackers have many options for tricking users into clicking unexpected controls:
The majority of popular clickjacking attacks involve framing the targeted web page in an iframe at some stage, so all the main prevention methods aim to disallow framing. Legacy solutions used client-side scripts to break pages out of frames, while more modern and secure approaches rely on setting HTTP security headers to specify framing policy:
top.location
to make sure this was the current page – if not, top.location
was set to self. However, these scripts could easily be blocked from the outer frame or otherwise bypassed, and more elaborate solutions were developed. Even so, numerous ways of bypassing even the most elaborate framebreakers exist, and such scripts should only be used to provide rudimentary protection for legacy browsers. The approach currently recommended by OWASP is to hide the entire body of the HTML document and only show it after verifying that the page is not framed.X-Frame-Options
(XFO) HTTP response header in server responses. Originally introduced by Microsoft in Internet Explorer 8 and later formalized in RFC 7034, the X-Frame-Options
header is used to specify whether a page can be embedded in a <frame>
, <iframe>
, <embed>
or <object>
element. The header supports three possible directives: deny to block all framing attempts, sameorigin
to allow framing only by pages of the same origin, or allow-from
to allow framing by pages from specified URIs. However, allow-from
is unsupported by several browsers (including Chrome and Safari), so if you need to specify sources, you are better off using CSP (see below). For general anti-framing protection, you only need to specify X-Frame-Options: deny
or X-Frame-Options: sameorigin
in your server’s headers.frame-ancestors
directive for specifying sources that are permitted to embed a page (in a <frame>
, <iframe>
, <object>
, <embed>
, or <applet>
element). The syntax is simple:Content-Security-Policy: frame-ancestors <source1> <source2> ... <sourceN>;
You can specify any number of sources, and supported source values include host IPs or addresses, scheme types, 'self
' to specify the current document’s origin, and 'none
' to disallow all embedding. This gives you a lot of flexibility for defining sources, especially in complex deployments, but for basic protection, the last two options are usually sufficient: frame-ancestors
'self
' is equivalent to XFO’s sameorigin
directive, while frame-ancestors
'none
' corresponds to deny
in XFO.
While still not a guarantee of absolute clickjacking safety, the X-Frame-Options
HTTP header is still the most universal way of increasing general website resilience, eliminating not just typical clickjacking attempts, but also a host of other vulnerabilities – see this article for a detailed discussion of its benefits. Although the CSP frame-ancestors
directive should provide equivalent protection to X-Frame-Options
, in practice XFO is still more widely and uniformly supported, even if it’s officially deprecated. If both headers are specified, the CSP spec indicates that frame-ancestors should take precedence and X-Frame-Options
should be rejected – but some older browsers (such as Google Chrome 40 and Mozilla Firefox 35) do the reverse. Whichever solution you choose, you can use Netsparker to check your websites both for X-Frame-Options
and Content-Security-Policy
headers and ensure that your chosen security policies are applied consistently across all pages.Apart from anti-framing schemes on the server side and client side, users are also protected from clickjacking by security features built into modern browsers. The web page rendering process involves multiple layers of checks to ensure that UIs behave as expected by the user, including anti-clickjacking algorithms to counter repositioning and scrolling attacks. Browsers can also block pop-ups and other unusual web page behaviors or warn the user when suspicious operations are attempted.
X-Frame-Options
was an interim solution that was widely adopted by browser vendors and CSP’s frame-ancestors
directive provides a more standardized and flexible version of the same approach. Both headers can currently provide effective protection against framing and frame-based clickjacking attacks and in the future, frame-ancestors
should see universal adoption to prevent iframe abuse. But remember that clickjacking is not about iframes – it’s about deceiving the user and exploiting their trust in what they see in the browser window. With the majority of web browsing traffic now coming from mobile devices, the potential for creating misleading user interfaces is enormous and securing traditional web browser access is no longer enough.