---
title: "Clickjacking"
section: "Web Pentesting"
sectionSlug: "pentesting-web"
sourcePath: "src/pentesting-web/clickjacking.md"
sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/pentesting-web/clickjacking.md"
sha: "188de82beb54e70956b2952367a0af91d26758b8"
isIndex: false
modified: true
license: "CC-BY-NC-4.0"
---
# Clickjacking
## What is Clickjacking
In a clickjacking attack, a **user** is **tricked** into **clicking** an **element** on a webpage that is either **invisible** or disguised as a different element. This manipulation can lead to unintended consequences for the user, such as the downloading of malware, redirection to malicious web pages, provision of credentials or sensitive information, money transfers, or the online purchasing of products.[[1]](#references)
### Prepopulate forms trick
Sometimes it is possible to **prepopulate form fields with query parameters when loading a page**. An attacker may combine this behavior with clickjacking so the victim only has to press the submit button.
### Populate form with Drag\&Drop
If a victim must **fill a form** with attacker-chosen data, a drag-and-drop interaction can write controlled text into the framed form without asking the victim to type it directly.[[9]](#references)
### Basic Payload
```css
Click me
```
### Multistep Payload
```css
Click me first
Click me next
```
### Drag\&Drop + Click payload
```css
.
1. Click and press delete button
3.Click me
2.DRAG ME TO THE RED BOX
```
### XSS + Clickjacking
If you have identified an **XSS attack that requires a user to click** on some element to **trigger** the XSS and the page is **vulnerable to clickjacking**, you could abuse it to trick the user into clicking the button/link.\
Example:\
You found a **self XSS** in some private details of the account (details that **only you can set and read**). The page with the **form** to set these details is **vulnerable** to **Clickjacking** and you can **prepopulate** the **form** with the GET parameters.\
An attacker could prepare a **Clickjacking** attack to that page **prepopulating** the **form** with the **XSS payload** and **tricking** the **user** into **Submit** the form. So, **when the form is submitted** and the values are modified, the **user will execute the XSS**.
### DoubleClickjacking
DoubleClickjacking asks the victim to double-click an attacker-controlled button, then uses the timing gap between `mousedown` and `click` to place the target page under the pointer so the second click lands on a legitimate target control.[[11]](#references)[[12]](#references)
An example could be seen in this video: [https://www.youtube.com/watch?v=4rGvRRMrD18](https://www.youtube.com/watch?v=4rGvRRMrD18)
A code example can be found in [this page](https://www.paulosyibelo.com/2024/12/doubleclickjacking-what.html).[[10]](#references)
> [!WARNING]
> This technique allows to trick the user to click on 1 place in the victim page bypassing every protection against clickjacking. So the attacker needs to find **sensitive actions that can be done with just 1 click, like OAuth prompts accepting permissions**.
#### Popup-based DoubleClickjacking (no iframes)
Some PoCs abandon iframes entirely and keep a **background popup** aligned under the cursor. The attacker page tracks `mousemove` and uses a small popup (`window.open`) that is moved with `moveTo()` while it is **same-origin**; once aligned, it is redirected back to the **target origin** so the next click lands on the real button. Because cross‑origin `moveTo()` is blocked, the popup is briefly navigated to an attacker origin for repositioning, then `location`/`history.back()` returns to the target. To surface the target at click time, the attacker can re‑open the popup **with the same window name** to bring it to the foreground without changing the URL.[[10]](#references)
```html
```
### SVG Filters / Cross-Origin Iframe UI Redressing
Modern Chromium/WebKit/Gecko builds let CSS `filter:url(#id)` be applied to cross-origin iframes. The iframe’s rasterized pixels are exposed to the SVG filter graph as `SourceGraphic`, so primitives such as `feDisplacementMap`, `feBlend`, `feComposite`, `feColorMatrix`, `feTile`, `feMorphology`, etc. can arbitrarily warp the victim UI before the user sees it, even though the attacker never touches the DOM.[[4]](#references) A simple Liquid-Glass style filter looks like:
```html
```
* Useful primitives: `feImage` loads attacker bitmaps (e.g., overlays, displacement maps); `feFlood` builds constant-color mattes; `feOffset/feGaussianBlur` refine highlights; `feDisplacementMap` refracts/warps text; `feComposite operator="arithmetic"` implements arbitrary per-channel math (`r = k1*i1*i2 + k2*i1 + k3*i2 + k4`), which is enough for contrast boosting, masking, and AND/OR operations; `feTile` crops and replicates pixel probes; `feMorphology` grows/shrinks strokes; `feColorMatrix` moves luma into alpha to build precise masks.
#### Distorting secrets into CAPTCHA-style prompts
If a framable endpoint renders secrets (tokens, reset codes, API keys), the attacker can distort them so they resemble a CAPTCHA and coerce manual transcription:
```html
```
The distorted pixels fool the user into “solving” the captcha inside the attacker-controlled `` whose `pattern` enforces the real victim secret.
#### Recontextualizing victim inputs
Filters can surgically delete placeholder/validation text while keeping user keystrokes. One workflow:
1. `feComposite operator="arithmetic" k2≈4` amplifies brightness so grey helper text saturates to white.
2. `feTile` limits the working area to the input rectangle.
3. `feMorphology operator="erode"` thickens the dark glyphs typed by the victim and stores them via `result="thick"`.
4. `feFlood` creates a white plate, `feBlend mode="difference"` with `thick`, and a second `feComposite k2≈100` turns it into a stark luma matte.
5. `feColorMatrix` moves that luma into alpha, and `feComposite in="SourceGraphic" operator="in"` keeps only user-entered glyphs.
6. Another `feBlend in2="white"` plus a thin crop gives a clean textbox, after which the attacker overlays their own HTML labels (e.g., “Enter your email”) while the hidden iframe still enforces the victim origin’s password policy.
Safari struggles with `feTile`; the same effect can be reproduced with spatial mattes built from `feFlood` + `feColorMatrix` + `feComposite` for WebKit-only payloads.
#### Pixel probes, logic and state machines
By cropping a 2–4 px region with `feTile` and tiling it to `100%` of the viewport, the attacker transforms the sampled color into a full-frame texture that can be thresholded into a boolean mask:
```html
```
For arbitrary colors, a `feFlood` reference (e.g., `#0B57D0`) plus `feBlend mode="difference"` and another arithmetic composite (`k2≈100`, `k4` as tolerance) outputs white only when the sampled pixel matches the target shade. Feeding these masks into `feComposite` with tuned `k1..k4` yields logic gates: `AND` via `k1=1`, `OR` via `k2=k3=1`, `XOR` via `feBlend mode="difference"`, `NOT` via blending against white. Chaining gates makes a full adder inside the filter graph, proving the pipeline is functionally complete.
Attackers can therefore read UI state without JavaScript. Example booleans from a modal workflow:
- **D** (dialog visible): probe a darkened corner and test against white.
- **L** (dialog loaded): probe the coordinates where the button appears once ready.
- **C** (checkbox checked): compare the checkbox pixel against the active blue `#0B57D0`.
- **R** (red success/failure banner): use `feMorphology` and red thresholds inside the banner rectangle.
Each detected state gates a different overlay bitmap embedded via `feImage xlink:href="data:..."`. Masking those bitmaps with `D`, `L`, `C`, `R` keeps the overlays synchronized with the real dialog and walks the victim through multi-step workflows (password resets, approvals, destructive confirmations) without ever exposing the DOM.
### Sandboxed iframe Basic Auth dialog (no allow-popups)
A sandboxed iframe without `allow-popups` can still surface a browser-controlled **HTTP Basic Authentication modal** when a load returns `401` with `WWW-Authenticate`. The dialog is spawned by the browser’s networking/auth layer (not JS `alert/prompt/confirm`), so popup restrictions in the sandbox do **not** suppress it. If you can script the iframe (e.g., `sandbox="allow-scripts"`) you can navigate it to any endpoint issuing a Basic Auth challenge:
```html
```
Once the response arrives, the browser prompts for credentials even though popups are disallowed. Framing a trusted origin with this trick enables UI redress/phishing: unexpected modal prompts inside a "sandboxed" widget can confuse users or trigger password managers to offer stored credentials.[[5]](#references)[[6]](#references)[[7]](#references)
### Browser extensions: DOM-based autofill clickjacking
Aside from iframing victim pages, attackers can target browser extension UI elements that are injected into the page. Password managers render autofill dropdowns near focused inputs; by focusing an attacker-controlled field and hiding/occluding the extension’s dropdown (opacity/overlay/top-layer tricks), a coerced user click can select a stored item and fill sensitive data into attacker-controlled inputs. This variant requires no iframe exposure and works entirely via DOM/CSS manipulation.[[3]](#references)
A real-world case: Dashlane disclosed a passkey dialog clickjacking issue (Aug 2025) where **XSS on the relying-party domain** allowed an attacker to overlay HTML over the extension’s passkey dialog. A click on the attacker’s element would proceed with the legitimate passkey login (the passkey itself isn’t exposed), effectively turning a UI-redress into account access if the RP is already vulnerable to script injection.[[8]](#references)
- For concrete techniques and PoCs see:
[Browext Clickjacking](/hacktricks/pentesting-web/browser-extension-pentesting-methodology/browext-clickjacking)
## Strategies to Mitigate Clickjacking
### Client-Side Defenses
Scripts executed on the client side can perform actions to prevent Clickjacking:
- Ensuring the application window is the main or top window.
- Making all frames visible.
- Preventing clicks on invisible frames.
- Detecting and alerting users to potential Clickjacking attempts.
However, these frame-busting scripts may be circumvented:
- **Browsers' Security Settings:** Some browsers might block these scripts based on their security settings or lack of JavaScript support.
- **HTML5 iframe `sandbox` Attribute:** An attacker can neutralize frame buster scripts by setting the `sandbox` attribute with `allow-forms` or `allow-scripts` values without `allow-top-navigation`. This prevents the iframe from verifying if it is the top window, e.g.,
```html
```
The `allow-forms` and `allow-scripts` values enable actions within the iframe while disabling top-level navigation. To ensure the intended functionality of the targeted site, additional permissions like `allow-same-origin` and `allow-modals` might be necessary, depending on the attack type. Browser console messages can guide which permissions to allow.[[2]](#references)
### Server-Side Defenses
#### X-Frame-Options
The **`X-Frame-Options` HTTP response header** informs browsers about the legitimacy of rendering a page in a `` or `