What Is Clickjacking?

On this page
  1. How does the attack work?
  2. How do you prevent clickjacking?

Clickjacking — also called UI redress — tricks a user into clicking something different from what they think they are clicking. The attacker overlays the real, sensitive site in an invisible frame on top of decoy content, so a click meant for a harmless button actually activates a control on the hidden page. The user’s genuine click does the attacker’s bidding.

How does the attack work?#

The mechanics are pure browser layering:

  1. The attacker builds a page with tempting bait (“Click to win”).
  2. They load the target site (say, a settings page) in an <iframe>, made invisible with CSS opacity, and position it precisely over the bait.
  3. The victim clicks the visible bait — but the click lands on the invisible framed control.
  4. Because the victim is logged in, the action executes with their authority.

Note the overlap with CSRF: both cause an unwanted authenticated action. CSRF forges the request directly; clickjacking borrows a real user click.

How do you prevent clickjacking?#

Deny framing by other origins:

DefenseNotes
CSP frame-ancestors 'none'Modern, preferred; also supports an allowlist
X-Frame-Options: DENYLegacy fallback for old browsers
Framebusting JavaScriptFragile; not a substitute for headers
Content-Security-Policy: frame-ancestors 'none'
X-Frame-Options: DENY

If your site legitimately needs to be embedded by specific partners, use frame-ancestors https://partner.example rather than opening it to everyone.

Clickjacking is defeated at the header layer. More at the Web Security hub.

Frequently asked questions#

What is clickjacking?

Clickjacking, or UI redress, tricks a user into clicking something different from what they perceive. The attacker loads a target site in an invisible frame over their own page, so a click the user thinks lands on a harmless button actually lands on a sensitive control — approving a payment, changing a setting, or granting a permission.

How do you prevent clickjacking?

Tell the browser your site may not be framed by others. The modern way is the Content-Security-Policy frame-ancestors directive (frame-ancestors 'none' or a specific allowlist); the legacy header X-Frame-Options: DENY covers older browsers. Together they stop your pages being embedded in an attacker’s frame.

Sources & further reading