在使用SameSite=Lax
的iframe中设置cookie时,我看到了一些无法解释的行为。
我有两个web服务器,一个在your.example.com
上,另一个在my.example.com
上。your.example.com
在iframe中加载my.example.com
,其中my.example.com
设置cookie。这在实际的远程web服务器上运行良好,cookie设置没有任何问题。
在本地环境中,我在localhost
中加载一个,然后在iframe中加载my.localhost
。当my.localhost
返回cookie时,我在Chrome网络选项卡中看到以下错误:The set-cookie had the "SameSite=Lax" attribute but came from a cross-origin response.
如果我在自己的选项卡上加载my.localhost
地址,cookie会被正确设置,但当我返回localhost
时,除了之前的错误消息外,我还会看到以下错误:This cookie had the "SameSite=Lax" attribute and the request was made on a different site. This does not include navigation requests initiated by other sites.
我使用的是Chrome版本80.0.3987.162(官方版本((64位(。有人能解释一下这种行为以及如何在本地实现这种行为吗?
我认为如果你把所有东西都降低一个级别,你会得到你想要的行为。我的意思是,将dev.localhost
或类似的子域视为您的顶级域。从dev.localhost
域设置cookie,您应该会看到my.dev.locahost
和your.dev.localhost
被视为同一站点。换句话说,您的SameSite=Lax
cookie应该是允许的。
注意:我需要回去再次检查,但我有理由相信,当我测试类似的设置时,这是有效的!因此,请您自己尝试并验证。