Home / Knowledge hub / Cookie tossing
Knowledge hub
Cookie tossing
A sibling subdomain planting cookies that your main site then trusts.
What it means
Cookie tossing is a trick where one subdomain sets a cookie for the parent domain. A page on blog.example.com can write a cookie scoped to .example.com, and the browser will then send it to app.example.com as if the app had set it. The browser decides which cookies to send by domain and path, not by who wrote them.
The app cannot tell who wrote a cookie from the cookie alone. It sees a name and a value arrive, so a value planted by a weaker sibling can end up trusted by a stronger one. That gap, between who wrote a cookie and who reads it, is the entire attack.
Why it matters
The weakest subdomain sets the security level for all of them. A forgotten marketing site, a staging host or a taken-over subdomain can plant cookies that touch your main product, even though the main product itself has no flaw. Nothing needs to be broken on the main app itself for the attack to work against it.
What gets planted matters. A chosen session token is session fixation. A forged CSRF token can defeat a cross-site request protection. A bad preference or feature flag can change what a signed-in customer sees. Each of these is quiet, and none shows up as a server error.
How it shows up
You meet it where several subdomains share one registered domain and cookies are set with a Domain attribute. Cookies set without it stay on the host that wrote them. Also check whether any subdomain runs third-party code or user content, since that is how an attacker gets to set a cookie in the first place. See cookie scope.
The defences are narrow scope and checks that do not rely on cookies alone. Use the __Host- prefix, which forces a cookie to be host-only and rules out a sibling overwriting it. Bind sessions to something the server holds, and keep untrusted content on a separate registered domain.
Questions people ask
Cookie tossing, answered
Can a subdomain really set a cookie for its parent?
Yes. A page may set a cookie for its own host or for a parent domain above it, as long as the parent is not a public suffix such as a country code. That is how single sign-on across subdomains works, and it is also what makes tossing possible.
How does the __Host- prefix help?
A cookie named with __Host- must be set from a secure page, with no Domain attribute and with the path set to the root. That makes it host-only, so a sibling subdomain cannot overwrite it. Browsers enforce this rule.
Is it the same as session fixation?
Related. Session fixation is the goal of giving a victim a session identifier the attacker knows. Cookie tossing is one way of delivering it, from a subdomain rather than a link or a script on the main site.
Does HttpOnly stop it?
No. HttpOnly stops scripts reading a cookie. A page on a sibling subdomain does not need to read yours, it just needs to write one with the same name, which the browser allows.
Does the SameSite attribute help?
Not directly. Sibling subdomains count as the same site, so a request between them is not blocked by SameSite. It remains useful against cross-site requests, but it is not the answer to a planted cookie.
Related
Terms that sit next to this one
Cookie scope
The domain and path settings that decide which sites and pages receive a cookie.
Cookie prefix
A name prefix such as __Host- that makes browsers enforce stricter cookie rules.
Session fixation
An attacker sets your session id before login, then waits for it to work.
Subdomain takeover
Claiming an abandoned cloud resource that one of your DNS names still points to.
SameSite cookie
A cookie setting that limits when a browser sends it on requests from other sites.
Who else can write your cookies?
Session handling is tested on the running app, including whether a value set from the wrong place is accepted, and each finding carries the request and response. Book a pilot on one app.
Or start with a $199 pilot on one application: thirty days, success criteria agreed before day one, credited against the annual if you convert.