-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zh-cn: update the translation of the Content-Security-Policy
header
#25396
Conversation
Preview URLs Flaws (1)URL:
External URLs (2)URL:
(comment last updated: 2025-02-03 03:31:28) |
我需要把所有的 |
需要进行手动转义 - [\<host-source>](#host-source)
- [\<scheme-source>](#scheme-source) 如果有什么其他格式问题,可以参考相应英语文档的源码 |
@jasonren0403 谢谢您的帮助,现在文件已经通过了lint检查。 但是似乎有一个workflow需要批准,可否请您帮忙检查一下。 |
Content-Security-Policy
header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要注意一些格式问题,如代码格式两侧的空格
{{HTTPSidebar}}HTTP 响应头 **`Content-Security-Policy`** 允许站点管理者控制用户代理能够为指定的页面加载哪些资源。除了少数例外情况,设置的政策主要涉及指定服务器的源和脚本结束点。这将帮助防止跨站脚本攻击(`Cross-Site Script`)({{Glossary("XSS")}})。 | ||
{{HTTPSidebar}} | ||
|
||
HTTP 响应头 **`Content-Security-Policy`** 允许站点管理者控制用户代理能够为指定的页面加载哪些资源。除了少数例外情况,设置的政策主要涉及指定源服务器和脚本端点。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
header -> 标头
HTTP 响应头 **`Content-Security-Policy`** 允许站点管理者控制用户代理能够为指定的页面加载哪些资源。除了少数例外情况,设置的政策主要涉及指定源服务器和脚本端点。 | ||
这将帮助防止跨站脚本攻击(`Cross-Site Scripting`)({{Glossary("cross-site scripting")}})。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
写成一行,否则会有额外空格
HTTP 响应头 **`Content-Security-Policy`** 允许站点管理者控制用户代理能够为指定的页面加载哪些资源。除了少数例外情况,设置的政策主要涉及指定源服务器和脚本端点。 | |
这将帮助防止跨站脚本攻击(`Cross-Site Scripting`)({{Glossary("cross-site scripting")}})。 | |
HTTP 响应标头 **`Content-Security-Policy`** 允许站点管理者控制用户代理能够为指定的页面加载哪些资源。除了少数例外情况,设置的策略主要涉及指定服务器的源和脚本端点。这有助于防止{{Glossary("cross-site scripting", "跨站脚本攻击")}}。 |
{{HTTPSidebar}} | ||
|
||
HTTP 响应头 **`Content-Security-Policy`** 允许站点管理者控制用户代理能够为指定的页面加载哪些资源。除了少数例外情况,设置的政策主要涉及指定源服务器和脚本端点。 | ||
这将帮助防止跨站脚本攻击(`Cross-Site Scripting`)({{Glossary("cross-site scripting")}})。 | ||
|
||
如需更多信息,请查阅[Content Security Policy (CSP)](/zh-CN/docs/Web/HTTP/CSP)。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如需更多信息,请查阅[Content Security Policy (CSP)](/zh-CN/docs/Web/HTTP/CSP)。 | |
如需更多信息,请查阅[内容安全策略(CSP)](/zh-CN/docs/Web/HTTP/CSP)。 |
Content-Security-Policy: <policy-directive>; <policy-directive> | ||
``` | ||
|
||
其中`<policy-directive>`应为不含标点的`<directive> <value>`形式。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其中`<policy-directive>`应为不含标点的`<directive> <value>`形式。 | |
其中 `<policy-directive>` 应为内部不含标点符号的 `<directive> <value>` 形式。 |
此示例设置了与前一个例子相同的限制,但使用了 {{httpheader("Content-Security-Policy-Report-Only")}} 头和 {{CSP("report-to")}} 指令。 | ||
这种方法在测试期间使用,用于报告违规行为但不阻止代码执行。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
此示例设置了与前一个例子相同的限制,但使用了 {{httpheader("Content-Security-Policy-Report-Only")}} 头和 {{CSP("report-to")}} 指令。 | |
这种方法在测试期间使用,用于报告违规行为但不阻止代码执行。 | |
此示例设置了与前一个例子相同的限制,但使用了 {{httpheader("Content-Security-Policy-Report-Only")}} 头和 {{CSP("report-to")}} 指令。这种方法在测试期间使用,用于报告违规行为但不阻止代码执行。 |
此示例设置了与前一个例子相同的限制,但使用了 {{httpheader("Content-Security-Policy-Report-Only")}} 头和 {{CSP("report-to")}} 指令。 | ||
这种方法在测试期间使用,用于报告违规行为但不阻止代码执行。 | ||
|
||
报告端点(URL)使用 {{HTTPHeader("Reporting-Endpoints")}} HTTP 响应头定义。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
报告端点(URL)使用 {{HTTPHeader("Reporting-Endpoints")}} HTTP 响应头定义。 | |
报告端点(URL)使用 {{HTTPHeader("Reporting-Endpoints")}} HTTP 响应标头定义。 |
|
||
请注意,{{CSP("report-uri")}} {{deprecated_inline}}指令在上面的示例中也被指定,因为`report-to`在浏览器中的支持尚未广泛。 | ||
|
||
更多示例请参阅 [内容安全策略(CSP)实现](/zh-CN/docs/Web/Security/Practical_implementation_guides/CSP)。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
更多示例请参阅 [内容安全策略(CSP)实现](/zh-CN/docs/Web/Security/Practical_implementation_guides/CSP)。 | |
更多示例请参阅[内容安全策略(CSP)实现](/zh-CN/docs/Web/Security/Practical_implementation_guides/CSP)。 |
Content-Security-Policy-Report-Only: default-src https:; report-uri /csp-violation-report-url/; report-to csp-endpoint | ||
``` | ||
|
||
请注意,{{CSP("report-uri")}} {{deprecated_inline}}指令在上面的示例中也被指定,因为`report-to`在浏览器中的支持尚未广泛。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请注意,{{CSP("report-uri")}} {{deprecated_inline}}指令在上面的示例中也被指定,因为`report-to`在浏览器中的支持尚未广泛。 | |
请注意,{{CSP("report-uri")}} {{deprecated_inline}} 指令在上面的示例中也被指定,因为`report-to`在浏览器中的支持尚未广泛。 |
9f52a5e
to
b309084
Compare
非常抱歉因为错误操作自动关闭了pull request,下次不会force push了 可以检查现在的文件了 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还有一些建议需要看看
- 如果没有 `img-src` 而有 `default-src`,那么 `default-src` 提供的策略将应用于图片。 | ||
- 如果没有 `script-src-elem` 而有 `script-src`,那么 `script-src` 提供的策略将应用于 `<script>` 元素。 | ||
- 如果 `script-src-elem` 和 `script-src` 都没有提供,却提供了 `default-src`,那么 `default-src` 提供的策略将应用于 `<script>` 元素。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 如果没有 `img-src` 而有 `default-src`,那么 `default-src` 提供的策略将应用于图片。 | |
- 如果没有 `script-src-elem` 而有 `script-src`,那么 `script-src` 提供的策略将应用于 `<script>` 元素。 | |
- 如果 `script-src-elem` 和 `script-src` 都没有提供,却提供了 `default-src`,那么 `default-src` 提供的策略将应用于 `<script>` 元素。 | |
- 如果没有提供 `img-src`,但包含了 `default-src`,那么 `default-src` 定义的策略将应用于图像。 | |
- 如果没有提供 `script-src-elem`,但包含了 `script-src`,那么 `script-src` 定义的策略将应用于 `<script>` 元素。 | |
- 如果 `script-src-elem` 和 `script-src` 都没有提供,但包含了 `default-src`,那么 `default-src` 定义的策略将应用于 `<script>` 元素。 |
|
||
> [!WARNING] | ||
> 此指令意图替换 [`report-uri`](#report-uri);在支持 `report-to` 的浏览器,`report-uri` 会被忽略。 | ||
> 但是,在 `report-to` 被广泛支持前,你应该两者均指定(其中`endpoint_name`是单独提供的端点的名字): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> 但是,在 `report-to` 被广泛支持前,你应该两者均指定(其中`endpoint_name`是单独提供的端点的名字): | |
> 但是,在 `report-to` 被广泛支持前,你应该两者均指定(其中 `endpoint_name` 是单独提供的端点的名字): |
- {{CSP("block-all-mixed-content")}} {{deprecated_inline}} | ||
- : 当页面使用 HTTPS 时,阻止使用 HTTP 的资源加载。 | ||
- {{CSP("report-uri")}} {{deprecated_inline}} | ||
- : 给浏览器提供发送 CSP 违规报告的 URL。已经被[`report-to`](#report-to)指令取代。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- : 给浏览器提供发送 CSP 违规报告的 URL。已经被[`report-to`](#report-to)指令取代。 | |
- : 给浏览器提供发送 CSP 违规报告的 URL。已经被 [`report-to`](#report-to) 指令取代。 |
## 多内容安全策略 | ||
所有的 Fetch 指令可以指定为以下形式之一: | ||
|
||
- 单独的值 `'none'`,表示应完全阻止加载特定资源类型。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 单独的值 `'none'`,表示应完全阻止加载特定资源类型。 | |
- 单独的 `'none'` 值,表示应完全阻止加载特定资源类型。 |
|
||
- 内联 `<script>` 标签 | ||
- 内联事件属性 | ||
- `javascript:`URL。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `javascript:`URL。 | |
- `javascript:` URL |
默认情况下,如果 CSP 包含 `default-src` 或 `script-src` 指令,则禁止执行内联 JavaScript。这包括: | ||
|
||
- 内联 `<script>` 标签 | ||
- 内联事件属性 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event handler attributes,不仅仅是 event attributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasonren0403 那么86行的JavaScript inline event handlers是否也应该一一对译成“内联事件处理器”?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasonren0403 那么86行的JavaScript inline event handlers是否也应该一一对译成“内联事件处理器”?
对
|
||
### 'inline-speculation-rules' | ||
|
||
默认情况下,如果 CSP 包含 `default-src` 或 `script-src` 指令,则不允许执行内联 JavaScript。`'inline-speculation-rules'`允许浏览器加载 [`type`](/zh-CN/docs/Web/HTML/Element/script/type) 属性为 [`speculationrules`](/zh-CN/docs/Web/HTML/Element/script/type/speculationrules) 的内联`<script>`元素。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
默认情况下,如果 CSP 包含 `default-src` 或 `script-src` 指令,则不允许执行内联 JavaScript。`'inline-speculation-rules'`允许浏览器加载 [`type`](/zh-CN/docs/Web/HTML/Element/script/type) 属性为 [`speculationrules`](/zh-CN/docs/Web/HTML/Element/script/type/speculationrules) 的内联`<script>`元素。 | |
默认情况下,如果 CSP 包含 `default-src` 或 `script-src` 指令,则不允许执行内联 JavaScript。`'inline-speculation-rules'` 允许浏览器加载 [`type`](/zh-CN/docs/Web/HTML/Element/script/type) 属性为 [`speculationrules`](/zh-CN/docs/Web/HTML/Element/script/type/speculationrules) 的内联 `<script>` 元素。 |
|
||
### 'strict-dynamic' | ||
|
||
`'strict-dynamic'`关键字使得通过 [nonce](#nonce-nonce_value) 或 [hash](#hash_algorithm-hash_value) 信任的脚本扩展到此脚本动态加载的脚本,例如通过使用 {{domxref("Document.createElement()")}} 创建新的`<script>`标签,然后通过 {{domxref("Node.appendChild()")}} 将其插入文档中。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`'strict-dynamic'`关键字使得通过 [nonce](#nonce-nonce_value) 或 [hash](#hash_algorithm-hash_value) 信任的脚本扩展到此脚本动态加载的脚本,例如通过使用 {{domxref("Document.createElement()")}} 创建新的`<script>`标签,然后通过 {{domxref("Node.appendChild()")}} 将其插入文档中。 | |
`'strict-dynamic'` 关键字使得通过 [nonce](#nonce-nonce_value) 或 [hash](#hash_algorithm-hash_value) 信任的脚本扩展到此脚本动态加载的脚本,例如通过使用 {{domxref("Document.createElement()")}} 创建新的 `<script>` 标签,然后通过 {{domxref("Node.appendChild()")}} 将其插入文档中。 |
|
||
例外的情况是,如果 Worker 脚本的来源是一个全局唯一 ID(比如,它的 URL 是一个结构化的数据或者 blob)。在这种情况下,这个 Worker 会继承它所属的文档或者创建它的 Worker 的 CSP。 | ||
|
||
## 多内容安全策略 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## 多内容安全策略 | |
## 多重内容安全策略 |
Co-authored-by: Jason Ren <[email protected]>
format Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还有遗留的空格和 header 的翻译问题需要注意,参见部分的部分链接也需要进行翻译
https://github.com/mdn/translated-content/pull/25396/files#r1919473932
Apply suggestions from code review Co-authored-by: Jason Ren <[email protected]>
我认为英文页面的链接应该保持英文,以此提醒读者。不过按照你的要求我还是翻译了。 另外注意#25396 (comment) |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Description
I am not familiar with the syntax, please check if anything wrong.
Motivation
The current page is out of date.
Additional details
Related issues and pull requests
None