【问题标题】:The Content-Security-Policy directive 'frame-ancestors' does not support the source expression ''unsafe-inline'' for allowed siteContent-Security-Policy 指令“frame-ancestors”不支持允许站点的源表达式“unsafe-inline”
【发布时间】:2021-08-20 19:54:53
【问题描述】:

我正在开发一个带有自定义扩展的 Magento 2 站点,以向 Magento 的 CSP 添加白名单。我遇到了以下错误:“Content-Security-Policy 指令 'frame-ancestors' 不支持源表达式 ''unsafe-inline''”

这个问题的来源是以下文件:https://translate.googleapis.com/element/TE_20210503_00/e/js/element/element_main.js

问题是,我将这个网站列入了框架祖先的白名单,但它仍然被阻止。这是我到目前为止的政策:

<policy id="frame-ancestors">
    <values>
        <value id="google-apis" type="host">*.googleapis.com</value>
    </values>
</policy>

这与我对所有其他政策的格式相同,并且所有这些政策都已正确列入白名单。这是唯一不受影响的。

我已按照本教程制作我的 CSP 扩展,供参考:https://magento.stackexchange.com/a/312350/73083

我不确定自己做错了什么,这是在将 CSP 添加到站点之前我需要解决的最后一个问题。

【问题讨论】:

  • 埃里克,你是怎么解决这个问题的?您能否分享解决方案,因为我有确切的问题?

标签: magento2 content-security-policy


【解决方案1】:
  1. frame-ancestors 指令确实不支持 'unsafe-inline' 令牌。仅script-srcstyle-srcdefaulr-src 指令支持此令牌。

如果您遇到错误:“Content-Security-Policy 指令 'frame-ancestors' 不支持源表达式 ''unsafe-inline''”,这意味着您在 CSP 中有一条规则:frame-ancestors ... 'unsafe-inline' ...;
您可能错误地使用此规则在某处发布了第二个 CSP。或者此错误发生在第三方 iframe 中,但不在您的网络应用中。

  1. 如果你希望允许类似&lt;frame src='https://accounts.googleapis.com/auth/...' 的东西,你必须使用不是frame-ancestors 而是frame-src 指令。因为frame-ancestors *.googleapis.com 控制将您的网站嵌入*.googleapis.com 网页。而frame-src 控制允许在您的页面上嵌入哪些网站。

【讨论】:

    猜你喜欢
    • 2023-03-19
    • 1970-01-01
    • 2019-09-05
    • 2018-09-05
    • 2021-09-04
    • 1970-01-01
    • 2015-09-09
    • 1970-01-01
    • 2018-03-06
    相关资源
    最近更新 更多