Clickjacking: framing a real page under a fake one
How a hostile page loads your site in an invisible frame to capture clicks on real buttons, which actions are worth the trouble, and how frame-ancestors and X-Frame-Options stop it.
Diagram
A click landing on a hidden frame
Step 1 of 4
Frame
Another site embeds your settings page in a transparent iframe.
# Frame # Another site embeds your settings page in a transparent # iframe.
The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
One-click actions
- What fails
- Actions that complete with a single click, such as granting access or deleting data, are the targets.
- Who is affected
- Users with sessions on the framed site.
- What you would notice
- Sensitive actions with no confirmation step.
- What you change
- Add frame-ancestors and require re-authentication or a typed confirmation for high-impact actions.
Headers on every response
- What fails
- Protection must be on the pages with the actions, including error and embedded views.
- Who is affected
- Users of the unprotected pages.
- What you would notice
- Headers set on the home page but missing on /settings.
- What you change
- Set the header at the edge for all HTML responses.
OAuth and payment prompts
- What fails
- Consent and payment confirmations are high-value framing targets.
- Who is affected
- Users granting access or money.
- What you would notice
- An authorization page that can be framed.
- What you change
- Identity providers and payment pages must deny framing.
Testing
Create a local HTML file that iframes the target page of an application you are authorized to test and open it in a browser. If the page renders inside the frame, framing is allowed. Check the response headers to see which rule is missing.
<!-- frame-test.html, opened from your own machine --> <iframe src="https://app.example.test/settings" width="800" height="600"></iframe> $ curl -sI https://app.example.test/settings | grep -iE "frame-ancestors|x-frame-options" (no output -> the page can be framed)
Notes
frame-ancestors in CSP supersedes X-Frame-Options in modern browsers; send both for older clients. SameSite cookies reduce clickjacking impact because the framed page may load without the session in cross-site contexts, but do not rely on that alone.
Check yourself
Recognition and the fix. Nothing here is a procedure.
Which CSP directive controls who may frame a page?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.