简体   繁体   中英

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)

在此处输入图片说明

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)

在此处输入图片说明

Does anyone have any ideas about this? Thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM