Chrome extension 如何包含 chrome-extension:// 的内容安全策略
Chrome extension how to include content security policy for chrome-extension://
我对我的 chrome 扩展进行了测试 运行,我从 chrome-extension://extensionid/tests.html[=13= 执行它们]
我收到不允许内联脚本的内容安全策略错误。有什么办法可以在测试时删除这些? (添加一个元标记以禁用它 html 或其他不会降低扩展安全性的方式?)
我在 test.html 页面的头部添加了以下内容
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'sha256-jynp9uOEMlgu3tR4l2Dr3s2aDinAZ60XBJB90peqSiY=' 'sha256-15MCFd4+StoldY1/R3pkitrT0zw4gNvsPZieV/QiqRE=' 'sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=' 'sha256-PnGpdwmF8gaODbB6epAipygkpV6GFPS46JZtI9veRzU=' 'sha256-J4clsEh5/6tMX7sob7FXvQGfQUYKmTGqi2iPvj3P6n4=' https://apis.google.com/ https://www.gstatic.com/ https://*.firebaseio.com https://www.googleapis.com https://ajax.googleapis.com; object-src 'self'">
但我仍然在控制台中收到有关内容安全策略的错误消息。该错误仍然显示我的 manifest.json.
中的旧政策
- 实际上 wOxxOm 回答了问题的第一部分 - 额外的 headers/ 只会使生成的 CSP 更具限制性。
当存在多个 CSP 时,要应用所有 sources/tokens 应该通过所有 CSP(通过所有策略过滤)未被破坏 - 本节在 CSP spec, but the test shows that Chrome and Firefox follow it. It does not matter how CSPs where delivered to the page via HTTP header, <meta>
-tag or even HTTP header + meta 中不规范。
正如您所写 The error shows still the old policy from my manifest.json
- 这表明此 CSP 对您的情况更具限制性。
- 如果您不想降低扩展的安全性 - 只需将
sha256-values
从 meta-tag 移动到 manifest.json 中的 CSP。这将只允许使用这些哈希值的内联脚本,不允许使用其他脚本。
负面时刻 - 您需要在每个脚本更改后重新计算哈希值,但 Chrome 会为您完成
我对我的 chrome 扩展进行了测试 运行,我从 chrome-extension://extensionid/tests.html[=13= 执行它们]
我收到不允许内联脚本的内容安全策略错误。有什么办法可以在测试时删除这些? (添加一个元标记以禁用它 html 或其他不会降低扩展安全性的方式?)
我在 test.html 页面的头部添加了以下内容
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'sha256-jynp9uOEMlgu3tR4l2Dr3s2aDinAZ60XBJB90peqSiY=' 'sha256-15MCFd4+StoldY1/R3pkitrT0zw4gNvsPZieV/QiqRE=' 'sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=' 'sha256-PnGpdwmF8gaODbB6epAipygkpV6GFPS46JZtI9veRzU=' 'sha256-J4clsEh5/6tMX7sob7FXvQGfQUYKmTGqi2iPvj3P6n4=' https://apis.google.com/ https://www.gstatic.com/ https://*.firebaseio.com https://www.googleapis.com https://ajax.googleapis.com; object-src 'self'">
但我仍然在控制台中收到有关内容安全策略的错误消息。该错误仍然显示我的 manifest.json.
中的旧政策- 实际上 wOxxOm 回答了问题的第一部分 - 额外的 headers/ 只会使生成的 CSP 更具限制性。
当存在多个 CSP 时,要应用所有 sources/tokens 应该通过所有 CSP(通过所有策略过滤)未被破坏 - 本节在 CSP spec, but the test shows that Chrome and Firefox follow it. It does not matter how CSPs where delivered to the page via HTTP header, <meta>
-tag or even HTTP header + meta 中不规范。
正如您所写 The error shows still the old policy from my manifest.json
- 这表明此 CSP 对您的情况更具限制性。
- 如果您不想降低扩展的安全性 - 只需将
sha256-values
从 meta-tag 移动到 manifest.json 中的 CSP。这将只允许使用这些哈希值的内联脚本,不允许使用其他脚本。
负面时刻 - 您需要在每个脚本更改后重新计算哈希值,但 Chrome 会为您完成