Integrity-Policy-Report-Only header
HTTP Integrity-Policy-Report-Only
响应头允许网站管理员报告用户代理加载的资源,如果强制执行完整性策略(使用 Integrity-Policy
头),这些资源将违反 子资源完整性 保证。
报告可能针对指定 请求目的地 中缺少完整性元数据或以 no-cors 模式发出的请求生成。为了将报告发送到报告端点,Integrity-Policy-Report-Only
头必须指定一个有效的报告端点名称,该名称与使用 Reporting-Endpoints
头声明的端点匹配。报告使用 Reporting API 生成,也可以在报告完整性策略的页面中通过 ReportingObserver
观察。报告主体的格式由 IntegrityViolationReportBody
字典给出(此主体的 JSON 序列化形式通过 POST 请求发送到报告服务器端点)。
该头允许开发人员测试 完整性策略 并在最终部署 Integrity-Policy
头以强制执行策略之前修复任何内容问题。
语法
Integrity-Policy-Report-Only: blocked-destinations=(<destination>),sources=(<source>),endpoints=(<endpoint>)
头值被定义为具有以下键的结构化字段字典
blocked-destinations
-
必须包含有效完整性元数据的 请求目的地 列表。允许的值是
sources
可选-
必须包含完整性元数据的完整性源列表。允许的值是
inline
-
完整性元数据源是内容中内联的,例如 integrity 属性。这是默认值。
由于这是默认值和唯一值,因此省略
sources
等同于指定sources=(inline)
。
endpoints
可选-
报告将发送到的 报告端点名称 列表。报告端点必须在
Reporting-Endpoints
头中定义。
示例
当脚本缺少完整性元数据时报告
此示例显示了一个文档,当任何 <script>
(或 HTMLScriptElement
)未指定 integrity
属性,或者当脚本资源以 no-cors 模式请求时,它会生成报告。
请注意,Integrity-Policy-Report-Only
中使用的 integrity-endpoint
是在 Reporting-Endpoints
头中定义的。
Reporting-Endpoints: integrity-endpoint=https://example.com/integrity, backup-integrity-endpoint=https://report-provider.example/integrity
Integrity-Policy-Report-Only: blocked-destinations=(script), endpoints=(integrity-endpoint, backup-integrity-endpoint)
报告负载 可能如下所示。
{
"type": "integrity-violation",
"url": "https://example.com",
"body": {
"documentURL": "https://example.com",
"blockedURL": "https://example.com/main.js",
"destination": "script",
"reportOnly": false
}
}
规范
规范 |
---|
子资源完整性 # integrity-policy-section |
浏览器兼容性
加载中…