File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change 11---
2- title : 内容安全策略
2+ title : 内容安全策略(CSP)
33sort : 10
44contributors :
55 - EugeneHlushko
@@ -9,6 +9,7 @@ contributors:
99translators :
1010 - QC-L
1111 - jacob-lcs
12+ - Yucohny
1213related :
1314 - title : 解释 nonce 设计目的
1415 url : https://stackoverflow.com/questions/42922784/what-s-the-purpose-of-the-html-nonce-attribute-for-script-and-style-elements
@@ -22,11 +23,11 @@ related:
2223 url : https://web.dev/trusted-types
2324---
2425
25- Webpack 能够为其加载的所有脚本添加 ` nonce ` 。要启用此功能,需要在引入的入口脚本中设置一个 ` __webpack_nonce__ ` 变量。应该为每个唯一的页面视图生成和提供一个唯一的基于 hash 的 ` nonce ` ,这就是为什么 ` __webpack_nonce__ ` 要在入口文件中指定,而不是在配置中指定的原因。注意 ,` __webpack_nonce__ ` 应该是一个 base64 编码的字符串。
26+ webpack 能够为其加载的所有脚本添加 ` nonce ` ,即一次性随机数。在入口文件中设置一个 ` __webpack_nonce__ ` 变量以激活此功能。然后为每个唯一的页面视图生成和提供一个唯一的基于哈希的 ` nonce ` 。这就是为什么应该在入口文件中指定 ` __webpack_nonce__ ` 而非在配置中指定的原因。请注意 ,` __webpack_nonce__ ` 应该是一个 base64 编码的字符串。
2627
2728## 示例 $#examples$
2829
29- 在 entry 文件中 :
30+ 在入口文件中 :
3031
3132``` js
3233// ...
@@ -36,15 +37,15 @@ __webpack_nonce__ = 'c29tZSBjb29sIHN0cmluZyB3aWxsIHBvcCB1cCAxMjM=';
3637
3738## 启用 CSP $#enabling-csp$
3839
39- 注意,默认情况下不启用 CSP。需要与文档(document)一起发送相应的 ` CSP ` header 或 meta 标签 ` <meta http-equiv="Content-Security-Policy" ...> ` ,以告知浏览器启用 CSP。以下是一个包含 CDN 白名单 URL 的 CSP header 的示例 :
40+ 注意,默认情况下不启用 CSP。需要与文档一同发送相应的 ` CSP ` 响应头 ` <Content-Security-Policy ` 或元标签 ` <meta http-equiv="Content-Security-Policy" ...> ` 以告知浏览器需要启用 CSP。以下是一个包含 CDN 白名单 URL 的 CSP 头部示例 :
4041
4142``` html
4243Content-Security-Policy: default-src 'self'; script-src 'self'
4344https://trusted.cdn.com;
4445```
4546
46- 有关 CSP 和 ` nonce ` 属性的更多信息,请查看页面底部的 ** 延伸阅读 ** 部分 。
47+ 参阅页面底部的 ** 延伸阅读 ** 以了解更多关于 CSP 与 ` nonce ` 属性的信息 。
4748
48- ## Trusted Types $#trustedtypes$
49+ ## 信任类型 $#trustedtypes$
4950
50- webpack 还能够使用 Trusted Types 来加载动态构建的脚本,遵守 CSP [ ` require-trusted-types-for ` ] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/require-trusted-types-for ) 指令的限制。可查看 [ ` output.trustedTypes ` ] ( /configuration/output/#outputtrustedtypes ) 配置项 。
51+ 只需遵守 CSP [ ` require-trusted-types-for ` ] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/require-trusted-types-for ) 指令的限制,webpack 便能够使用信任类型加载动态构建的脚本。参阅 [ ` output.trustedTypes ` ] ( /configuration/output/#outputtrustedtypes ) 配置项了解更多 。
You can’t perform that action at this time.
0 commit comments