# Clickjacking

What is clickjacking?

Clickjacking is an attack in which another site loads your page inside an invisible frame and places it over its own content. The visitor thinks they are clicking something on the attacker's page, but the click lands on your page, where they may be logged in.

## How it works

The attacker's page embeds yours in an `<iframe>`, makes it transparent with CSS, and lines up one of your buttons (delete account, confirm a payment, change a setting) under something worth clicking, such as a play button. Because the frame is your real page, the click runs with whatever session the visitor's browser sends to it.

The defense is to tell the browser not to show your page in frames on other sites. Two headers do this:

```http
X-Frame-Options: DENY
Content-Security-Policy: frame-ancestors 'none'
```

`X-Frame-Options` is the older header and takes `DENY` or `SAMEORIGIN`. The [Content Security Policy](/glossary/content-security-policy) directive `frame-ancestors` is the newer one, and it can also list the specific sites that may embed the page. Sending both covers older browsers that only understand the first. Session cookies set with `SameSite=Lax` or `SameSite=Strict` add a second layer, because the browser does not send them to a page framed by another site.

## Why it matters

Any page that does something with a single click while the visitor is logged in can be a target: account settings, admin panels, payment confirmations, follow or like buttons. The attack needs no bug in your code, only a page that allows itself to be framed.

## What can go wrong

- Neither header is sent, so any site can frame any page.
- `X-Frame-Options: ALLOW-FROM` is used to allow one partner site, but modern browsers ignore the whole header when it has that directive, which leaves the page unprotected.
- The protection is set in an HTML `<meta>` tag, where browsers ignore both `X-Frame-Options` and `frame-ancestors`.
- A page that has to be embedded, such as a widget, is left with no protection at all instead of a `frame-ancestors` list naming the sites allowed to embed it.

## Check it

The [Security headers checker](/tools/security-headers) shows whether a URL sends X-Frame-Options and a Content-Security-Policy, alongside the other [security headers](/glossary/security-headers). It gives a one-time reading, so it is worth running again after a deploy or a server change.

Read this definition in a browser: https://ranetrace.com/glossary/clickjacking
