【发布时间】:2021-08-19 04:42:41
【问题描述】:
使用 yarn create electron-app my-new-app --template=typescript-webpack 使用 Typescript/Webpack 启动了一个新的 Electron 应用程序,并按照 Electron Forge's directions 添加了 React。
我的文件树是这样的:
-src
--app.tsx
--index.html
--index.ts
--renderer.ts
-webpack.main.config.js
-webpack.renderer.config.js
-webpack.rules.js
-webpack.plugins.js
我在第一次启动时收到了编译警告。
Electron Security Warning (Insecure Content-Security-Policy) This renderer process has either no Content Security
Policy set or a policy with "unsafe-eval" enabled. This exposes users of
this app to unnecessary security risks.
React 渲染时出现此警告。
查看此警告后,我浏览了 Electron Security Responsibility 页面以了解有关 CSP 的更多信息。
我将推荐的 <meta http-equiv="Content-Security-Policy" content="script-src 'self'"> 标签添加到我的 index.html 头中,但随后出现错误提示:
Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self'".
React 停止渲染。
我按照 Webpack/CSP 的指示更改编译器以更改 webpack.main.config.js 中的开发工具,但没有更改。
如何配置它以呈现 React,同时为应用程序提供标准 CSP 保护?
【问题讨论】:
标签: typescript webpack electron xss content-security-policy