HTTP Content-Security-Policy(CSP 内容安全策略)中的 child-src 指令定义了使用如 frame 和 iframe 等元素在加载 web worker 和嵌套浏览上下文时的有效来源。对于 worker 来说,不合规的请求会被用户代理当作致命的网络错误处理。
<table class="properties"> <tbody> <tr> <th scope="row">CSP 版本</th> <td>2</td> </tr> <tr> <th scope="row">指令类型</th> <td>Fetch directive</td> </tr> <tr> <th scope="row">default-src 回落</th> <td> 是。如果该指令不存在,用户代理将查找 <code>default-src</code> 指令。 </td> </tr> </tbody> </table>
Syntax
child-src 策略可以允许一个或者多个源:
Content-Security-Policy: child-src <source>;
Content-Security-Policy: child-src <source> <source>;
源
<source> 可以是 CSP 源值中的任意一个。
请注意,这套相同的值可以用于所有 fetch directive(以及许多其他的指令)。
示例
违规的策略
给定此 CSP 标头:
Content-Security-Policy: child-src https://example.com/
这个 iframe 和 worker 被禁止并且不会加载:
<iframe src="https://not-example.com"></iframe>
<script>
const blockedWorker = new Worker("data:application/javascript,…");
</script>
规范
浏览器兼容性
参见
- Content-Security-Policy(内容安全策略)
- frame 和 iframe
- Worker、SharedWorker、ServiceWorker
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
