javascript - 我可以在 Google Chrome 的 iframe 中允许使用 CORS 的第一方 cookie 吗?
问题描述
withCredentials=true
为什么在 Chrome 中启用“阻止第三方 cookie”时,我的跨域请求 cookie不再发送?
环境:Chrome 80.0.3987.122
, nodejs server
, 2 域 ( a.com
, b.com
)
测试用例:
test=cookie; SameSite=None; Secure
使用域的新规则设置 cookiea.com
- 写
<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
https://a.com
在 Chrome 中打开
结果:发送成功的 xhr 请求并获得 200,但是:启用a.com
“阻止第三方 cookie”时:请求中不存在cookie cookie。test=cookie
为什么?这是第一方 cookie,因为域a.com
是在 chrome 选项卡中打开的。
事实:
- 新的 google cookie 设计允许使用
SameSite=None; Secure
( source )制作 cookie - CORS 允许在
site cookies
何时发送access-control-allow-credentials: true
(来源) - XMLHttpRequest 允许使用
withCredentials=true
( source )发送 cookie Request
和Cookie
for1rd-site
(not 3rd) 而选项被称为 ablock third-party cookie
铬问题:https ://bugs.chromium.org/p/chromium/issues/detail?id=918322
解决方案
为什么?这是第一方 cookie,因为域 a.com 是在 chrome 选项卡中打开的。
这是一个第三方 cookie,因为请求是由 触发的,b.com
即使b.com
是由a.com
.
我想您可以通过使用postMessage
向window.parent
(即a.com
)发送消息并通过发出 XHR 请求本身来响应那里的页面来解决此问题。
推荐阅读
- python - 清理亚马逊链接的正则表达式
- c# - 我如何发送消息选项卡和向上箭头发送到 winform?C#
- sql - SQL - 一行中有多个记录
- python - 通过 PRESTO 连接器选择随机数据样本
- python - urllib.error.URLError:
代码:
import os import tarfile from urllib.request import urlretrieve
- python - 元编程 - 更改 SIMD 计算的表示
- javascript - 当我修改取决于我的父状态的变量时,我不想修改初始状态
- c# - 在 Entity Framework Core 中出现错误
- python - 我可以在函数内多次返回一个变量吗?
- node.js - Node Sequelize Postgres - BulkCreate 忽略自定义字段的重复值