Course contentsShow
← Security
Lesson 1139 of 3,05223. Web Security - Modern Web AttacksFree lesson

SameSite Cookies as Clickjacking Mitigation

How SameSite cookie attributes complement framing protections by preventing cross-site request forgery in embedded contexts.

SameSite Cookies as Clickjacking Mitigation

You'll learn how the SameSite cookie attribute adds a layer of defense against clickjacking by preventing cookies from being sent in cross-site embedded contexts.

The Core Idea

While X-Frame-Options and CSP's frame-ancestors control whether your page can be framed, SameSite cookies control what credentials are sent when your page is embedded. Even if an attacker successfully embeds your site in an iframe, SameSite attributes can prevent the victim's authentication cookies from being included with requests, rendering many clickjacking attacks ineffective.

Think of it like this: framing protections are locks on your door, but SameSite is removing the keys from the attacker's hands even if they break in.

How It Works

The SameSite attribute has three values:

  • Strict: Cookies never sent in cross-site contexts (including iframes from other origins)
  • Lax: Cookies sent only for top-level navigations, not embedded frames
  • None: Cookies sent everywhere (requires Secure flag)

When you set SameSite=Strict or SameSite=Lax on your session cookies, an attacker who iframes your site won't receive the victim's authentication cookies. The framed page loads, but the user appears logged out. This breaks clickjacking attacks that rely on authenticated state—like tricking users into clicking "Delete Account" or "Transfer Funds."

Complementary Defense

SameSite doesn't prevent framing itself—the attacker can still embed your page. But without valid session cookies, the framed page can't perform sensitive authenticated actions. This makes SameSite a powerful complementary control alongside framing headers, providing defense-in-depth.

Key Takeaway: SameSite cookies prevent authentication tokens from being sent in cross-site embedded contexts, neutralizing clickjacking attacks that depend on the victim's logged-in session, even when framing protections fail or are bypassed.