[我看到使用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。
注意:我需要返回并再次仔细检查一次,但是我有理由确信,当我测试类似的设置时,这种方法是可行的!因此,请自己尝试并验证。