Are sub-domain cookies sent in a parent domain HTTP request?
For instance, say I have the cookies:
Name Value Domain (not https)
ABC 1 .example.com
XYZ 0 foo.example.com
DEF 0 bar.example.com
Would [email protected] and [email protected] be sent along in the HTTP-header cookies
on a reqeust to http://example.com/content
, and/or http://QQQ.example.com/content
Please everyone note that you can set a cookie from a subdomain on a domain. But you CAN'T set a cookie from a domain on a subdomain.
That is, if the domain name in your cookie's domain parameter doesn't start with a period, then it will not let subdomains read that cookie. If it does start with the period, then all subdomains will have full access to that cookie's value.
To share a cookie between domains, you will need two domains, for example myserver.com and slave.com . One of the domains will issue the cookies and the other domain will ask the first domain what cookie should be issued to the client.
Cookies seem to be considered 3rd party if they come from different base domains (base domains being example.com or example.co.uk ), but not if they come from different subdomains of the same base domain.
The leading dot in the domain value .example.com
means example.com and its subdomains. Without the leading dot, the cookie is only valid for this specific domain.
Note that when setting a cookie, domain values without a leading dot will be prepended with a dot. Only when the domain parameter is not set the user agent assumes the current domain for that cookie.
So in this case, if http://example.com/
is requested, only the cookie for .example.com
will be sent. But in case of http://foo.example.com/
, both cookies for .example.com
and foo.example.com
will be sent. And in case of http://bla.foo.example.com
, only the cookie for .example.com
will be sent.
No. It's the other way around: parent-domain cookies are sent in sub-domain HTTP requests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With