SameSite=Lax可以远程工作,但不能在本地工作



在使用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.locahostyour.dev.localhost被视为同一站点。换句话说,您的SameSite=Laxcookie应该是允许的。

注意:我需要回去再次检查,但我有理由相信,当我测试类似的设置时,这是有效的!因此,请您自己尝试并验证。

相关内容

最新更新