Search code examples
cookiesdnsmozilla

What's the difference between "domain" and "non-domain" cookies?


I'm reading the MDC entry for nsICookieManager2.add and it talks about domain and non-domain cookies. What are the differences between the two types of cookies?


Solution

  • From RFC2109:

    Host A's name domain-matches host B's if [...] A is a FQDN string and has the form NB, where N is a non-empty name string, B has the form .B', and B' is a FQDN string. (So, x.y.com domain-matches .y.com but not y.com.)

    So, if I understand it right, a domain cookie has a domain like .y.com and a non-domain cookie has a domain like x.y.com. A domain cookie is visible for all subdomains, and non-domain cookie is only visible for it's specific subdomain.

    A cookie with the domain .y.com is visible when visiting subdomains like www.y.com and test.y.com (but not y.com), while a cookie with the domain x.y.com only is visible when visiting the subdomain x.y.com but not any other subdomain.