内容安全策略default-src如何:React应用程序无法修复?

问题描述 投票:0回答:1

我试图用我自己的webpack设置和配置来重新创建一个用create-react-app完成的React应用。一切正常,直到我遇到“内容安全策略”问题,如下所示:

Refused to execute inline script because it violates the following Content Security Policy directive: "default-src 'none'". Either the 'unsafe-inline' keyword, a hash ('sha256-ThhI8UaSFEbbl6cISiZpnJ4Z44uNSq2tPKgyRTD3LyU='), or a nonce ('nonce-...') is required to enable inline execution. Note also that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.

我试图在项目public / index / html中使用不同参数的元标记中设置CSP标头,但没有结果。有时页面甚至没有显示。

reactjs express content-security-policy
1个回答
0
投票

最有可能出现两个问题:

  1. 内容安全策略值'none'表示允许no资源被加载。您需要将应用程序所需的所有资源都包含在内容安全策略中。有一些工具,例如这些firefox / chrome扩展名,用于自动构建策略。

  2. 您需要将所有内联内容(嵌入到任何HTML中)移动到其自己的javascript文件中。可以找到指南here

© www.soinside.com 2019 - 2024. All rights reserved.