在 HTML `meta` 标签中使用 `report-to` 配置 Content-Security-Policy (CSP) 报告
Configuration of the Content-Security-Policy (CSP) reporting with `report-to` in the HTML `meta`-tag
我已经通过 meta
-标签为我的 SPA-application 定义了内容安全策略 (CSP):
<meta content = "default-src https: 'self' https://%SOME_DOMAIN%.com 'unsafe-eval' 'unsafe-inline'; child-src 'none'; object-src 'none';"
http-equiv = "Content-Security-Policy" />
一切正常,如果出现违规情况,我会在控制台中看到警告。
现在,我想使用 report-to
指令向 back-end 发送自动报告。
我是否理解正确,出于安全原因,我只能在后端配置 report-to
并将其作为 HTTP-header 发送到 client-side,并且我可以不只是在 meta
标签中声明它,就像我在 content-security-policy 规则中所做的那样吗?
是的,你没看错。 Reporting API 只能通过 HTTP header.
此外 report-to
/report-uri
CSP 指令在 meta
-tag 中不受支持。
如果您希望获得违规报告,CSP 应作为 HTTP header 从服务器传送。
如果使用 report-uri
指令,你不需要任何特殊的东西,但如果使用 report-to
指令,你还需要从服务器发布一个特殊的 Report-to
HTTP header .
PS: 目前只有 Chrome 支持 Reporting API
/report-to
指令。
我已经通过 meta
-标签为我的 SPA-application 定义了内容安全策略 (CSP):
<meta content = "default-src https: 'self' https://%SOME_DOMAIN%.com 'unsafe-eval' 'unsafe-inline'; child-src 'none'; object-src 'none';"
http-equiv = "Content-Security-Policy" />
一切正常,如果出现违规情况,我会在控制台中看到警告。
现在,我想使用 report-to
指令向 back-end 发送自动报告。
我是否理解正确,出于安全原因,我只能在后端配置 report-to
并将其作为 HTTP-header 发送到 client-side,并且我可以不只是在 meta
标签中声明它,就像我在 content-security-policy 规则中所做的那样吗?
是的,你没看错。 Reporting API 只能通过 HTTP header.
此外 report-to
/report-uri
CSP 指令在 meta
-tag 中不受支持。
如果您希望获得违规报告,CSP 应作为 HTTP header 从服务器传送。
如果使用 report-uri
指令,你不需要任何特殊的东西,但如果使用 report-to
指令,你还需要从服务器发布一个特殊的 Report-to
HTTP header .
PS: 目前只有 Chrome 支持 Reporting API
/report-to
指令。