Surprising fact: nearly 28% of U.S. websites were vulnerable to this trick in 2022, leaving many sites open to real fraud and brand damage.
Clickjacking hides a real page inside an invisible frame while a decoy interface steers the user to click where they did not intend. An attacker can make you think you tapped a harmless button while the click lands on a payment or permission control on your website.
This guide explains how the attack works, shows a clear example, and walks through server-side headers like X-Frame-Options and Content Security Policy that offer strong protection. It also covers cookie flags such as SameSite and why simple client-side frame-busting scripts often fail.
Fraud concerns are rising, and even major platforms have seen flaws patched quickly. Learn what to log, test, and deploy so your pages and users stay safe. For more technical background, see the detailed resource on UI redressing and defenses.
Key Takeaways
- Attackers overlay invisible frames to trick a user into acting on another page.
- About 27.9% of U.S. sites were exposed in 2022, so treat this as a real risk.
- Use browser-enforced headers (X-Frame-Options, CSP frame-ancestors) first.
- SameSite cookie flags reduce dangerous session-backed actions when framed.
- Client-side frame-busters are bypassable; favor server-side controls and testing.
- Log, pentest, and monitor pages regularly to maintain ongoing protection.
What is clickjacking and why it matters now
Short answer:A hidden frame places a real page beneath a visible decoy so a single tap triggers an unintended action on the framed site. This technique needs only basic HTML/CSS and exploits normal browser behavior.
A simple overlay can turn a trusted page into a trap that captures an unwitting click. In this clickjacking attack, a transparent or near-transparent iframe loads a target website and aligns real controls beneath a decoy UI. The user sees the decoy but the framed content receives the click.
The method has many names: UI redressing, click abduction, and tapjacking on mobile. It matters now because social engineering and embedded media have increased attack surfaces. In 2022 nearly 27.9% of U.S. websites remained frameable, and even major platforms have seen issues patched after public reports.
“An attacker needs only a few lines of CSS to hide an iframe; the browser still makes legitimate requests to the framed site.”
Detection is tough. The browser sends on-domain requests that look normal to network tools. Any site that allows framing—e-commerce, finance, SaaS—exposes its users to this low-effort attack.
- Minimal effort: CSS opacity and positioning often suffice.
- Hard to flag: requests originate from the framed domain.
- Platform-agnostic: legacy or modern SPAs are both in scope.
For a technical overview and mitigation guidance, see the OWASP resource on frame-based UI attacks. The next sections break down mechanics and show the fastest ways to block framing on your websites.

| Aspect | What attackers do | Why it matters |
|---|---|---|
| Technique | Transparent iframe overlays target pages | Hidden actions execute without user intent |
| Effort | Simple HTML/CSS/JS, no server access | Low barrier increases real-world attacks |
| Detection | Browser-originated requests look normal | Network tools and logs may not show anomalies |
| Who’s at risk | E‑commerce, SaaS, finance, legacy apps | Any framed site can expose sensitive actions |
How clickjacking attacks work in practice
Hidden frames and tiny layout tricks let attackers convert an ordinary tap into an unintended action on a remote page. The following examples show how little code and predictable UI sizes let an attacker build a working exploit fast.
Under a polished decoy, an invisible iframe can capture clicks and execute unintended requests. A typical overlay sets opacity near zero, raises z-index, and aligns the iframe so a decoy button sits over a real actionable element.
Classic invisible overlay: UI redressing in action
A framed page receives the user’s click, the browser sends a legitimate request, and the user stays unaware. Attackers sometimes use a 1×1 pixel iframe under the cursor or CSS pointer-events to seize events.
Common variants you should know
- Likejacking: stealth “likes” on social widgets.
- Cursorjacking: pointer misalignment moves the visible cursor away from the true target.
- Drag-and-drop / cookiejacking: steal data or session tokens via UI tricks.
- Cropping & filejacking: hide parts of a page or expose local files.
Modern twists and PoC tools
Advanced attacker tactics avoid frames altogether. They use rapid content replacement, repositioning, or scrolling to swap UI elements just before a click. Tools like Burp’s Clickbandit can record interactions and spit out overlay code as a quick proof-of-concept.

| Variant | Method | Impact |
|---|---|---|
| Invisible iframe | Opacity ~0, z-index above decoy, precise alignment | Unauthorized clicks, valid requests sent |
| Cursorjacking | CSS transforms shift pointer vs. visuals | User clicks wrong element, exposes actions |
| Rapid swap | Replace UI right before click; no iframe needed | Dialogs confirmed or purchases authorized |
“A few lines of CSS and predictable UI sizing can let an attacker capture many small but costly actions.”
For a hands-on technical guide on blocking framing and related risks, see this resource on preventing clickjacking attacks.
Clickjacking vs. CSRF: key differences that shape your defenses
In short: if a real person must click, think of a visual attack; if no visible interaction occurs, suspect a forged request. Both look similar in logs, but their origins differ.
Why it matters: a framed target page runs inside the browser and the user triggers the action. The server then receives a normal, on‑domain request with valid cookies and any CSRF token present. That is why tokens alone do not stop this kind of attack.
- Flow control: CSRF fabricates a request; a clickjacking attack coaxes a real user into a real action on a framed website.
- Token handling: CSRF tokens are read and sent by the legitimate page, so they do not block actions initiated inside a hidden frame.
- Server view: everything looks normal—same origin, expected parameters, and valid state.
- Different defenses: stop CSRF with tokens and SameSite cookies; stop framing with header-and-policy controls that tell the browser where a page may be embedded.
“If the user must click, think visual attack; if no visible interaction occurs, suspect CSRF.”

Clickjacking prevention with server-side controls
Quick answer: Use browser-enforced headers and cookie rules from the server to block framing, limit session reuse, and reduce attack surface. Configure these at the origin, CDN, or middleware and test critical flows before rollout.
Start by sending a clear response header that tells browsers where your pages may appear.
What X-Frame-Options should you set?
Set X-Frame-Options to deny to block all framing or sameorigin to allow only your own domain. Avoid relying on ALLOW-FROM; support is inconsistent across modern browsers.
Why prefer Content Security Policy?
Use a content security policy with the frame-ancestors directive. For example:
Content-Security-Policy: frame-ancestors 'self';
CSP lets you list exact origins and, in current browsers, takes precedence if both CSP and X-Frame-Options are present.

Cookie and patching strategies
Harden cookies with SameSite=’Strict’ or ‘Lax’ and HttpOnly to reduce session-backed risks. This helps prevent session use inside an iframe when actions require authentication.
- Scope allow-lists to exact domains (protocol + host).
- Deploy via server or CDN and keep framework plugins patched to shrink exploit vectors.
- Test after changes so legitimate embeds still work.
“Set headers at the source and keep systems updated — server controls stop many visual attacks before they reach users.”
For hands-on hardening examples, see how to harden your Apache server and apply these header rules across your website.
Client-side measures and UX considerations
Quick answer: Client-side scripts and clear UX cues help users notice anomalies, but they cannot be your only line of defense. Pair them with server headers and policy controls for durable protection.
Simple frame-buster code checks if the current page runs at the top window and, if not, attempts to break out with something like:
if (top !== window) top.location = location;.
This can stop basic framing attempts and restore visible context for the user.
Attackers can neutralize that logic. They set window.onbeforeunload handlers or host the site inside a sandboxed iframe that forbids top navigation. Modern browsers honor sandbox flags, so many client-only tricks fail quietly.
How to use UX and education without blaming users
Teach users what trusted site cues look like, but do not rely on warnings alone. Pixel-perfect overlays hide beneath legitimate content, so telling a user to “be careful” is not enough.
- Trust signals: consistent branding, verified badges, and integrity checks help users confirm a website.
- Minimal prompts: show rare, clear alerts to avoid click fatigue and keep security prompts meaningful.
- Document framed options: if a flow must allow a frame, keep CSP allow-lists narrow and published.
Instrument client-side telemetry to detect odd framing contexts and report them as secondary signals to security teams. This gives operations extra visibility without shifting blame to the end user.
“Client-side guards are useful UX tools — treat them as complements, not substitutes, for server-enforced controls.”
For a deeper technical primer on UI redressing and related concepts, see this technical primer.
Detect, test, and monitor: building operational resilience
Real-time detection starts with logs: aggregate HTTP access data, CSP violation reports, and referrer signals to build a baseline. Use that baseline to flag spikes against high‑risk endpoints like purchases or transfers.

How do server logs reveal suspicious requests?
Look for repeated identical user agents, synchronized request bursts, and odd referrers. Those patterns often point to an external decoy hosting an exploit.
How should you pentest embedding and overlays?
Create a local page that frames your site and confirm CSP/XFO block it. Escalate with tools like Burp’s Clickbandit to record interactions and produce a PoC example overlay.
Why combine headers, policies, and monitoring?
Defense‑in‑depth matters. Ensure every response across the website sends the required header and CSP rules. Track missing responses; attackers exploit those gaps first.
- Baseline: aggregate access logs and flag anomalous request spikes.
- Test: frame your pages and generate Clickbandit PoCs.
- Monitor: watch CSP violation reports and unusual referrers.
- Audit: scan the web app regularly for new vulnerabilities and test across browsers.
“Document incidents and map signals to playbooks so your team can triage fast when an attacker campaign hits.”
For a hands-on primer on real exploit examples and mitigations, read this resource at clickjacking attacks guide.
Implementation examples: secure response headers for your site
A short set of HTTP rules can stop most framing risks on your pages. Apply these at the app, server, or CDN layer and verify every response carries the intended policy.
A short set of HTTP headers can lock down where your pages may appear. Below are ready-to-copy strings and rollout notes you can use today.

Set X-Frame-Options at the origin or edge
Send this header to block framing:
- X-Frame-Options: deny — stop all embeds.
- X-Frame-Options: sameorigin — allow only your domain when you need internal framing.
Define a robust Content-Security-Policy with frame-ancestors
Prefer modern standards. Example strings:
- Content-Security-Policy: frame-ancestors ‘none’;
- Content-Security-Policy: frame-ancestors ‘self’;
- Or list exact origins: frame-ancestors https://payments.example.com https://admin.example.com;
Configure cookies with SameSite and HttpOnly
Harden session cookies to reduce cross-site iframe risks:
- Set SameSite=Strict or SameSite=Lax plus HttpOnly.
- Test all embeds and important actions after changes.
“Deploy headers at the edge, crawl your pages to confirm coverage, and keep allow-lists tight so only intended domains can embed elements of your website.”
| Control | Header / Cookie | Purpose |
|---|---|---|
| X-Frame-Options | X-Frame-Options: deny / sameorigin | Block or restrict framing of a website or page |
| Content Security Policy | Content-Security-Policy: frame-ancestors ‘self’ / ‘none’ | Declare allowed embedding domains with a directive |
| Cookie hardening | Set-Cookie: session=…; SameSite=Strict; HttpOnly | Reduce session-backed actions from framed iframes |
Conclusion
Make browser-enforced controls your first line of defense. Ship exact headers, harden cookies, and test critical flows so your pages stop being framed by unknown sites.
Recap the playbook: set X-Frame-Options or a strict Content-Security-Policy frame-ancestors, configure SameSite cookies, and keep your stack patched to narrow vulnerabilities.
Treat client-side frame-busters as a small part of protection. They help UX checks but are bypassable by modern attackers and sandbox tricks.
Monitor logs, run periodic tests (including overlay PoCs), and publish a living security policy that lists which websites may embed your content. Verify your top five flows cannot be framed by untrusted sites.
Checklist: set headers, configure SameSite, confirm iframe blocks, test across browsers, and alert on odd referrers. Do this regularly and you will prevent clickjacking and build durable protection for every user and page on your site.