【问题标题】:Need help understanding a CSP Report and set the right frame-ancestor url需要帮助了解 CSP 报告并设置正确的框架祖先 url
【发布时间】:2021-05-22 17:48:39
【问题描述】:

我正在尝试将我的 Web 应用程序作为 Office 加载项包含在内。加载项包含使用 iframe 的应用程序,因此我需要调整应用程序的“内容安全策略”标头以使其正常工作。

当前标头的值为content-security-policy: frame-src 'self' ; frame-ancestors 'self'; object-src 'none';。如果我将标头设置为 content-security-policy: frame-src 'self' * ; frame-ancestors 'self' *; object-src 'none'; 一切正常,但我不想让每个人都使用 iframe 包含我的应用程序。

所以我尝试限制使用 content-security-policy: frame-src 'self' https://outlook.live.com; frame-ancestors 'self' https://outlook.live.com ; object-src 'none'; 之类的东西,但这不起作用。 Chrome 的 JS 控制台说:Refused to frame 'https://auth-recette-broc.kinexo.fr/' 因为祖先违反了以下内容安全策略指令:“frame-ancestors 'self' https://outlook .live.com”。

“csp 报告”是:

{
  "document-uri": "https://auth-mywebsite.xx/",
  "referrer": "https://yy-mywebsite.xx/",
  "violated-directive": "frame-ancestors",
  "effective-directive": "frame-ancestors",
  "original-policy": "frame-src 'self'  https://outlook.live.com; frame-ancestors 'self' https://outlook.live.com ; object-src 'none';",
  "disposition": "report",
  "blocked-uri": "https://auth-mywebsite.xx/",
  "status-code": 0,
  "script-sample": ""
}

我不明白这个 csp 报告

  1. 为什么父框架URI(https://outlook.live.com)的url不显示为document-uri
  2. 为什么当document-uriblocked-uri 属性相同并且允许self 帧时帧被拒绝?
  3. 如何知道预期的 url 作为框架祖先以允许框架?

【问题讨论】:

    标签: security iframe outlook http-headers content-security-policy


    【解决方案1】:

    为什么父框架URI(https://outlook.live.com)的url没有显示为document-uri?

    frame-ancestors 指令很特殊 - 它作用于父页面,而其他指令作用于页面本身(发布 CSP)。
    因此,在frame-ancestors 违规的情况下,document-uriframe itself 的Url(它发布CSP)。

    为什么当document-uri和blocked-uri属性相同并且允许self帧时帧被拒绝?

    blocked-uri 如果frame-ancestors 是浏览器依赖:

    • Chrome 显示为 blocked-uri 锁定容器 (iframe) 本身的 URI。
    • Firefox 从顶级窗口获取blocked-uri(但对于嵌套级别>1 Firefox 有一个错误并发送一个空的blocked-uri)。

    因此,在 Chrome 中,blocked-uri 将等于 document-uri

    据我了解,您有一个嵌入 https://auth-mywebsite.xx/https://yy-mywebsite.xx 页面。
    https://auth-mywebsite.xx/ 页面发布 CSP frame-ancestors 'self'; object-src 'none';
    在这种情况下,'self' 表示https://auth-mywebsite.xx/,因此不允许嵌入到https://yy-mywebsite.xx。你必须至少有frame-ancestors 'self' https://yy-mywebsite.xx; object-src 'none';

    如何知道预期的 url 作为框架祖先以允许框架?

    frame-ancestors 指令检查所有祖先(父母的整个上游链),而不仅仅是最近的父母。因此,您必须指定允许嵌入 iframe 的所有主机。

    【讨论】:

    • 非常感谢这个准确的答案。实际上,我必须使用这个 CSP 值 frame-ancestors 'self' https: //yy-mywebsite.xx https://outlook.live.com; object-src 'none'; 才能使其工作。这是有道理的,但我错过了这一点
    猜你喜欢
    • 2021-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-31
    相关资源
    最近更新 更多