【问题标题】:Why are iframe requests not sending cookies?为什么 iframe 请求不发送 cookie?
【发布时间】:2019-05-19 09:41:23
【问题描述】:

一个兄弟部门创建了一个 HTML 文件,它实际上是少数 iframe 的支架。每个 iframe 调用一个报告,该报告托管在 Web 服务器上,参数略有不同。调用的报告会向未认证的用户显示登录表单,或向已认证的用户显示报告内容。

脚手架.html:

<html>
   <head>
      <title>I just show the output from a bunch of report calls</title>
   </head>
   <body>
      <iframe src="https://somesite.com/useful_report.html?parameter1=a&parameter2=1" id="iframe1"></iframe>
      <iframe src="https://somesite.com/useful_report.html?parameter1=b&parameter2=2" id="iframe2"></iframe>
      <iframe src="https://somesite.com/useful_report.html?parameter1=c&parameter2=3" id="iframe3"></iframe>
      <iframe src="https://somesite.com/useful_report.html?parameter1=d&parameter2=4" id="iframe4"></iframe>
   </body>
</html>

兄弟组织向我们解释说,如果用户登录到 https://somesite.com,上述设置效果很好 - 每个 iframe 都会显示有用的报告.html 内容...直到几天前。

当我

  1. 登录https://somesite.com,然后
  2. 将 file:///C:/Users/me/Desktop/scaffold.html 加载到 Chrome 中

每个 iframe 都会返回 https://somesite.com 登录表单。如果我随后在单独的选项卡中打开有用报告.html,报告内容会加载(证明 somesite.com 知道我仍然登录‡)。

使用开发人员工具,我可以看到到有用报告.html 的请求标头不包含“Cookie:”属性,因此这解释了为什么有用报告.html 返回登录表单。

我的问题是为什么 iframe 请求不发送 cookie? 什么 Chrome 和/或服务器设置/策略/指令阻止它?

‡ - 现在它知道我知道它知道。

【问题讨论】:

  • somesite.com 是否在其 cookie 中设置了 SameSitechromestatus.com/feature/4672634709082112
  • @cody 我正在查看 cookie,但我没有看到该名称(或类似名称)的任何属性。 SameSite 属性是我可以在开发者工具中看到的吗?
  • 是的,您会在开发者工具中的 cookie 中将其视为名称/值对,例如会话 ID 或其他任何内容。我猜想将其从列表中删除
  • 你能快速启动一个本地 http 服务器,通过它使用 iframe 提供文件,看看它是否有所作为?
  • @cody 是的,它确实有所作为;当托管在 somesite.com 上时,scaffold.html iframe 会加载报告内容(请求标头包括 cookie)。

标签: google-chrome security iframe cross-domain content-security-policy


【解决方案1】:

这是因为Chrome defaults to LaxSameSite cookie 政策,这意味着除非用户可以看到不包括 iframe 的 URL,否则不会发送 cookie。

如果您拥有 somesite.com,您可以通过将 SameSite 政策设置为“无”来选择退出此政策,并通过 Double Submit Cookie 处理 CSRF 攻击的风险。

【讨论】:

    猜你喜欢
    • 2012-02-10
    • 1970-01-01
    • 2018-11-16
    • 2015-08-29
    • 2018-10-28
    • 1970-01-01
    • 2021-02-11
    • 1970-01-01
    相关资源
    最近更新 更多