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.

Lesson 21 of 69 · 10 min read · practice only with authorization

Diagram

A click landing on a hidden frame

Follow the path. One example at a time.

Step 1 of 4

Frame

Another site embeds your settings page in a transparent iframe.

Illustration: Frame
# 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.

  1. 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.
  2. 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.
  3. 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.

1 / 3

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.

  1. MapHow web applications work: requests, sessions, and where trust is decidedA browser request from DNS to database and back, the parts of an HTTP exchange a tester reads first, and the server-side decisions that most web vulnerabilities come down to.

Practice

  1. LabSecurity headers graderEdit a real-looking HTTP response until it scores an A: HSTS, CSP, framing, cookies, CORS, and the version banners an attacker reads first.

Glossary

  1. CardClickjackingA transparent frame places your site's buttons under a decoy page so a click does something else.