【发布时间】:2020-06-17 22:06:57
【问题描述】:
为什么在 Chrome 中启用“阻止第三方 cookie”后,我的带有跨域请求和 withCredentials=true 的 cookie 不再发送?
环境:Chrome 80.0.3987.122、nodejs server、2 个域(a.com、b.com)
测试用例:
- 使用新规则
test=cookie; SameSite=None; Secure为域a.com设置 cookie - 写
<iframe src="https://b.com" />并把它放到a.com/index.html - 写
var xhr = new XMLHttpRequest(); xhr.open('GET', 'https://a.com/', true); xhr.withCredentials = true; xhr.send(null);并把它放到b.com/index.html - 将 CORS 添加到
a.com,例如:access-control-allow-origin: https://b.com和access-control-allow-credentials: true - 在 Chrome 中打开
https://a.com
结果:发送到 a.com 的 xhr 请求成功发送并获得 200,但是:启用“阻止第三方 cookie”时:cookie test=cookie请求中不存在 cookie。
为什么?这是一个第一方 cookie,因为域 a.com 是在 chrome 选项卡中打开的。
事实:
- 新的 google cookie 设计允许使用
SameSite=None; Secure(source) 制作 cookie - CORS 允许在
access-control-allow-credentials: true(source) 时发送site cookies - XMLHttpRequest 允许使用
withCredentials=true(source) 发送 cookie -
Request和Cookie用于1rd-site(不是第三个),而该选项称为block third-party cookie
铬问题:https://bugs.chromium.org/p/chromium/issues/detail?id=918322
【问题讨论】:
-
您的问题中是否包含此第 3 方 cookie?
-
@DeepKakkar 这个 cookie
test=cookie; SameSite=None; Secure设置为a.com和a.com是主站点,里面有 iframe。
标签: javascript node.js google-chrome cookies