简体   繁体   English

无法在Chrome中为“ cloudfront.net”设置Cookie?

[英]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 . 今天,我发现了一件奇怪的事情:Chrome(46.0)似乎为特定URL(例如cloudfront.net )设置了一些限制。

It can be reproduced like this: 可以这样复制:

  1. In the /etc/hosts , add two lines: /etc/hosts ,添加两行:

    127.0.0.1 cloudfront.net 127.0.0.1 cloudfront.net

    127.0.0.1 cloudfront.com 127.0.0.1 cloudfront.com

  2. Start Apache or Nginx for the local server 为本地服务器启动Apache或Nginx

  3. Open chrome and input cloudfront.net in the address bar 打开chrome并在地址栏中输入cloudfront.net

  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=/" document.cookie =“ test = test; expires = Thu,2020年1月1日星期四00:00:00 GMT; domain = cloudfront.com; path = /”

  5. And then 接着

    console.log(document.cookie) 执行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) 可以看到document.cookie为空,根本没有设置,这很奇怪(请参见下面的屏幕截图)

在此处输入图片说明

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) 但是,当我重复上述步骤,但将URL从cloudfront.net更改为cloudfront.com ,一切运行起来就像魔术一样。(请参阅下面的屏幕截图)

在此处输入图片说明

Does anyone have any ideas about this? 有人对此有任何想法吗? Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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