SameSite=Lax cookie 和 iframe 内的 GET 请求的规则是什么?

Cop*_*ick 6 cookies google-chrome web samesite

用户位于 site-a.com 上,并且有一个带有 site-b.com 的 iframe。site-b.com 向 site-a.com 发出 GET 请求(在 iframe 内)。用于跨站点 GET 到 site-a.com 的 Lax cookie 是否会随请求一起发送?

更清楚地说:

  • 在 GET 请求之前:site-b.com 在 site-a.com 中进行 iframe 处理
  • GET 请求后:site-a.com 在 site-a.com 中进行 iframe 处理

根据我在 Chrome 91 canary 中的观察,此 cookie 被阻止,而在 Chrome 88 中则未被阻止。我认为只有Lax+POST是有问题的,但看起来在某些情况下 Lax+GET 现在也被阻止了。有任何信息/规格吗?关于跨站点 GET+Lax cookie?

chl*_*ily 9

首先,从site-b.com到site-a.com的请求是一个跨站请求。无论是 GET 还是 POST,它位于两个不同的可注册域(又名 eTLD+1)之间,这一事实意味着它是跨站点的。

规范允许 Lax cookie 与跨站点请求一起发送,前提是它们是顶级请求并且具有安全方法(GET,但不是 POST):

   *  If the cookie's same-site-flag is not "None", and the HTTP
      request is cross-site (as defined in Section 5.2) then exclude
      the cookie unless all of the following statements hold:

      1.  The same-site-flag is "Lax" or "Default".

      2.  The HTTP request's method is "safe".

      3.  The HTTP request's target browsing context is a top-level
          browsing context.
Run Code Online (Sandbox Code Playgroud)

iframe 内的请求不是顶级请求,因此 Lax cookie 不会与 iframe 上的跨站点请求一起发送,无论请求方法是什么。

Chrome 曾经在这种行为中存在一个错误,即没有严格遵循顶级要求。(过去,如果 iframe 及其所有祖先都与顶级相匹配,Chrome 就会发送 Lax cookie。这是有问题的,因为规范说它实际上需要成为顶级。)您看到的是正确的行为该错误在 Chrome 90 中修复后。