Hanfei Sun
Hanfei Sun

Reputation: 47101

Can't set cookie for "cloudfront.net" in Chrome?

Today I found a weird thing: it seems that Chrome(46.0) set some restrictions for specific URL such as cloudfront.net.

It can be reproduced like this:

  1. In the /etc/hosts, add two lines:

    127.0.0.1 cloudfront.net

    127.0.0.1 cloudfront.com

  2. Start Apache or Nginx for the local server

  3. Open chrome and input cloudfront.net in the address bar

  4. Run the following statement in the console:

    document.cookie = "test=test; expires=Thu, 01 Jan 2020 00:00:00 GMT;domain=cloudfront.com; path=/"

  5. And then

    console.log(document.cookie)

As can be seen the document.cookie is empty, it is not set at all, which is weird (See the screenshot below)

enter image description here

However, when I repeat the steps above but change the URL from cloudfront.net into cloudfront.com, everything works well like a magic.. (See the screenshot below)

enter image description here

Does anyone have any ideas about this? Thanks!

Upvotes: 2

Views: 1518

Answers (1)

Hanfei Sun
Hanfei Sun

Reputation: 47101

I asked the question in Google Group (https://groups.google.com/a/chromium.org/forum/#!msg/chromium-dev/Hs1838k68bw/z_h4EHVwAAAJ) . It looks that Chrome indeed set some restrictions for some sites:

https://groups.google.com/a/chromium.org/d/msg/chromium-dev/Hs1838k68bw/z_h4EHVwAAAJ

Upvotes: 3

Related Questions