Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

set cookie on parent domain but from sub-domain website

When I visit a sub-domain website ex: https://sub2.example.com, from a browser console I can set a cookie for parent domain.

document.cookie = "nameCookie=HelloWorld; domain=.example.com;"

as per Cookie RFC this works! and this cookie should be available to all sub-domains.
ex:

But my problem, this concept is not working on some websites.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

for ex:

  • Go to https://square.github.io/

  • open browser console

    document.cookie = "nameCookie=HelloWorld; domain=.github.io;"
    console.log(document.cookie)
    

check that nameCookie is not available.

Why it is not working here? any Http header/rule setup on those websites?

>Solution :

Because github.io is on the list of effective top-level domains (eTLDs) (raw list here), so each github.io subdomain is treated like a subdomain of a top-level domain (that is, _______.github.io is treated just like _______.com or _______.co.uk).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading