gpt4 book ai didi

javascript - Chrome 扩展内容安全策略在设置为 * 时抛出错误

转载 作者:行者123 更新时间:2023-12-01 00:49:21 25 4
gpt4 key购买 nike

我已经在我的manifest.json中尝试了所有可能的CSP设置,这是我当前的(我知道非常开放且不安全)。

当我打开扩展程序的后台检查时,第一次重新加载后一切都很好,有时直到第五次,然后突然下面的错误开始涌入..

"content_security_policy": "default-src * 'unsafe-inline' 'unsafe-eval'; script-src * 'unsafe-inline' 'unsafe-eval'; connect-src * 'unsafe-inline'; img-src * data: blob: 'unsafe-inline'; frame-src *; style-src * 'unsafe-inline';"

但我仍然收到以下错误

Refused to load the script 'https://myapp-12345.firebaseio.com/.lp?start=t&ser=1234567&cb=15&v=5' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.

我尝试过的

  • 更改 manifest.json 时删除 chrome 扩展

我有什么遗漏的吗?

最佳答案

您只能在一定程度上放宽 Chrome 扩展程序中的 CSP

"content_security_policy" Chrome 扩展 list 中的条目仅允许开发人员在一定程度上放宽 CSP。 style-src 允许的值子集非常有限,引用自official documentation :

Currently, developers can allowlist origins with the following schemes: blob, filesystem, https, and chrome-extension. The host part of the origin must explicitly be specified for the https and chrome-extension schemes. Generic wildcards such as https:, https://* and https://*.com are not allowed; ...

CSP 中指定的许多值(例如 *'unsafe-inline'script-src )在 "content_security_policy" 中无效Chrome 在解析 manifest.json 时会忽略它们(并发出警告) .

为什么您没有看到有关无效 CSP 值的警告或错误

我怀疑您可能正在后台页面的 JavaScript 控制台中检查错误。您需要检查为您的 manifest.json 生成的错误和警告第一的。前往chrome://extensions/然后单击您的扩展程序的“错误”按钮。将会出现几个警告,例如:

content_security_policy': Ignored insecure CSP value "*" in directive 'script-src'.

编辑:我刚刚注意到错误页面 ( chrome://extensions/?errors=<extension-id> ) 的行为不一致。似乎存在一个错误,导致有关被忽略的 CSP 值的警告仅在重新加载扩展后才显示。

文档链接:

"content_security_policy" in Chrome

"content_security_policy" in Firefox
(规范基本相同,但我发现 MDN 上的文档更好、更容易理解。)

关于javascript - Chrome 扩展内容安全策略在设置为 * 时抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57113000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com