Skip to content
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

Merged
merged 11 commits into from
Feb 3, 2025

Conversation

cheeslide
Copy link
Contributor

Description

  • Update zh-cn translation for Web/HTTP/Headers/Content-Security-Policy
  • l10n.sourceCommit
  • some minor corrections

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

@cheeslide cheeslide requested a review from a team as a code owner January 12, 2025 07:59
@cheeslide cheeslide requested review from jasonren0403 and removed request for a team January 12, 2025 07:59
@github-actions github-actions bot added the l10n-zh Issues related to Chinese content. label Jan 12, 2025
Copy link
Contributor

github-actions bot commented Jan 12, 2025

Preview URLs

Flaws (1)

URL: /zh-CN/docs/Web/HTTP/Headers/Content-Security-Policy
Title: Content-Security-Policy (CSP)
Flaw count: 1

  • unknown:
    • No generic content config found
External URLs (2)

URL: /zh-CN/docs/Web/HTTP/Headers/Content-Security-Policy
Title: Content-Security-Policy (CSP)

(comment last updated: 2025-02-03 03:31:28)

@cheeslide
Copy link
Contributor Author

我需要把所有的<改成&lt;吗?

@jasonren0403
Copy link
Contributor

jasonren0403 commented Jan 13, 2025

我需要把所有的<改成&lt;吗?

需要进行手动转义

- [\<host-source>](#host-source)
- [\<scheme-source>](#scheme-source)

如果有什么其他格式问题,可以参考相应英语文档的源码

cheeslide added a commit to cheeslide/translated-content that referenced this pull request Jan 13, 2025
cheeslide added a commit to cheeslide/translated-content that referenced this pull request Jan 13, 2025
cheeslide added a commit to cheeslide/translated-content that referenced this pull request Jan 13, 2025
@cheeslide
Copy link
Contributor Author

@jasonren0403 谢谢您的帮助,现在文件已经通过了lint检查。

但是似乎有一个workflow需要批准,可否请您帮忙检查一下。

@yin1999 yin1999 changed the title Update zh-cn translation for Web/HTTP/Headers/Content-Security-Policy zh-cn: update the translation of the Content-Security-Policy header Jan 13, 2025
Copy link
Contributor

@jasonren0403 jasonren0403 left a 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`** 允许站点管理者控制用户代理能够为指定的页面加载哪些资源。除了少数例外情况,设置的政策主要涉及指定源服务器和脚本端点。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header -> 标头

Comment on lines 10 to 11
HTTP 响应头 **`Content-Security-Policy`** 允许站点管理者控制用户代理能够为指定的页面加载哪些资源。除了少数例外情况,设置的政策主要涉及指定源服务器和脚本端点。
这将帮助防止跨站脚本攻击(`Cross-Site Scripting`)({{Glossary("cross-site scripting")}})。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

写成一行,否则会有额外空格

Suggested change
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)。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
如需更多信息,请查阅[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>`形式。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码格式及英文与周围的中文应隔开一个空格

Suggested change
其中`<policy-directive>`应为不含标点的`<directive> <value>`形式。
其中 `<policy-directive>` 应为内部不含标点符号的 `<directive> <value>` 形式。

Comment on lines 385 to 386
此示例设置了与前一个例子相同的限制,但使用了 {{httpheader("Content-Security-Policy-Report-Only")}} 头和 {{CSP("report-to")}} 指令。
这种方法在测试期间使用,用于报告违规行为但不阻止代码执行。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
此示例设置了与前一个例子相同的限制,但使用了 {{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 响应头定义。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
报告端点(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)。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
更多示例请参阅 [内容安全策略(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`在浏览器中的支持尚未广泛。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
请注意,{{CSP("report-uri")}} {{deprecated_inline}}指令在上面的示例中也被指定,因为`report-to`在浏览器中的支持尚未广泛。
请注意,{{CSP("report-uri")}} {{deprecated_inline}} 指令在上面的示例中也被指定,因为`report-to`在浏览器中的支持尚未广泛。

@cheeslide cheeslide reopened this Jan 16, 2025
@cheeslide
Copy link
Contributor Author

非常抱歉因为错误操作自动关闭了pull request,下次不会force push了

可以检查现在的文件了

Copy link
Contributor

@jasonren0403 jasonren0403 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还有一些建议需要看看

Comment on lines 107 to 109
- 如果没有 `img-src` 而有 `default-src`,那么 `default-src` 提供的策略将应用于图片。
- 如果没有 `script-src-elem` 而有 `script-src`,那么 `script-src` 提供的策略将应用于 `<script>` 元素。
- 如果 `script-src-elem` 和 `script-src` 都没有提供,却提供了 `default-src`,那么 `default-src` 提供的策略将应用于 `<script>` 元素。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 如果没有 `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`是单独提供的端点的名字):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> 但是,在 `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)指令取代。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- : 给浏览器提供发送 CSP 违规报告的 URL。已经被[`report-to`](#report-to)指令取代。
- : 给浏览器提供发送 CSP 违规报告的 URL。已经被 [`report-to`](#report-to) 指令取代。

## 多内容安全策略
所有的 Fetch 指令可以指定为以下形式之一:

- 单独的值 `'none'`,表示应完全阻止加载特定资源类型。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 单独的值 `'none'`,表示应完全阻止加载特定资源类型。
- 单独的 `'none'`,表示应完全阻止加载特定资源类型。


- 内联 `<script>` 标签
- 内联事件属性
- `javascript:`URL。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `javascript:`URL
- `javascript:` URL

默认情况下,如果 CSP 包含 `default-src` 或 `script-src` 指令,则禁止执行内联 JavaScript。这包括:

- 内联 `<script>` 标签
- 内联事件属性
Copy link
Contributor

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

Copy link
Contributor Author

@cheeslide cheeslide Jan 17, 2025

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是否也应该一一对译成“内联事件处理器”?

Copy link
Contributor

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>`元素。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
默认情况下,如果 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()")}} 将其插入文档中。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`'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。

## 多内容安全策略
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## 多内容安全策略
## 多重内容安全策略

cheeslide and others added 3 commits January 17, 2025 18:18
format

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

@jasonren0403 jasonren0403 left a 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

@cheeslide
Copy link
Contributor Author

还有遗留的空格和 header 的翻译问题需要注意,参见部分的部分链接也需要进行翻译

我认为英文页面的链接应该保持英文,以此提醒读者。不过按照你的要求我还是翻译了。

另外注意#25396 (comment)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@jasonren0403 jasonren0403 merged commit b344e9b into mdn:main Feb 3, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
l10n-zh Issues related to Chinese content.
Projects
Development

Successfully merging this pull request may close these issues.

2 participants