Skip to content
Tyrone Software
Web Development

SameSite cookies and the embed that stopped logging in

Abstract illustration for the article SameSite cookies and the embed that stopped logging in

The symptom is always the same: a widget or a checkout embedded in another site worked, then users started getting logged out inside the frame. The server did nothing different. The browser stopped sending the session cookie.

What "same-site" means

Same-site is not the same as same-origin. Two URLs are same-site when they share the same registrable domain (the part just below the public suffix, so shop.example.com and www.example.com are same-site) and the same scheme. A request from a page on partner.com to example.com is cross-site, even if the user is logged in to example.com in another tab.

Table of SameSite values and which cross-site requests carry the cookie
Lax is the ceiling for most session cookies. None is only for cookies that must be embedded.

What browsers do when the attribute is missing

Chromium-based browsers treat a cookie without a SameSite attribute as Lax. Under Lax, the cookie is sent on top-level navigations with a safe method (clicking a link) but not on subrequests from another site: iframes, images, fetch, or form posts. So an embedded login that relied on the old default of sending everything stops working. Other browsers have their own tracking-protection rules on top of this, so the behaviour is not identical everywhere, and it is worth testing in Safari and Firefox separately.

The fix and its catch

A cookie that must travel in a cross-site context needs SameSite=None, and browsers only accept that value together with Secure. In Django:

SESSION_COOKIE_SAMESITE = 'None'
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SAMESITE = 'None'
CSRF_COOKIE_SECURE = True

That widens the attack surface, because the cookie now travels on cross-site requests, so CSRF protection matters again. Do not flip the setting site-wide because one page is embedded. Where you can, set the loose attribute only on the cookie used inside the frame, and keep the main session cookie on Lax.

Stricter is not always better

Strict also withholds the cookie on top-level navigation from another site. A user who clicks a link to your app from an email arrives looking logged out until they navigate once more. For session cookies, Lax is normally the right ceiling.

SameSite=None does not survive third-party cookie blocking

Setting SameSite=None; Secure gets the cookie past the browser's same-site rule, but it does not get it past tracking protection. Safari's Intelligent Tracking Prevention has blocked third-party cookies by default since 2020, regardless of SameSite. Firefox's Enhanced Tracking Protection blocks many third-party cookies by default as well, based on a tracker list rather than a blanket rule. Chrome has announced and then walked back full third-party cookie removal more than once, so treat its current behaviour as something to verify rather than assume, and do not build a plan that only works as long as Chrome keeps sending third-party cookies.

For an embed that genuinely needs shared state with a login on another site, the durable options are different from cookie flags: the Storage Access API lets an embedded page ask the user's browser for permission to use its cookies in that context, and some setups avoid the problem entirely by moving the embedded functionality to a subdomain of the parent site instead of a separate domain, which makes it first-party rather than third-party. Neither is a drop-in replacement for SameSite=None, and both need testing per browser before you rely on them.

Keep reading

Technologies

  • Python
  • PHP
  • Laravel
  • Django
  • PostgreSQL
  • MySQL
  • HTML5
  • CSS3
  • Bootstrap