CSP: child-src
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2017年4月.
HTTP Content-Security-Policy(CSP 内容安全策略)中的 child-src 指令定义了使用如 <frame> 和 <iframe> 等元素在加载 web worker 和嵌套浏览上下文时的有效来源。对于 worker 来说,不合规的请求会被用户代理当作致命的网络错误处理。
| CSP 版本 | 2 |
|---|---|
| 指令类型 | fetch 指令 |
default-src 回落 |
是。如果该指令不存在,用户代理将查找 default-src 指令。
|
Syntax
child-src 策略可以允许一个或者多个源:
http
Content-Security-Policy: child-src <source>;
Content-Security-Policy: child-src <source> <source>;
源
<source> 可以是 CSP 源值中的任意一个。
示例
>违规的策略
给定此 CSP 标头:
http
Content-Security-Policy: child-src https://example.com/
这个 <iframe> 和 worker 被禁止并且不会加载:
html
<iframe src="https://not-example.com"></iframe>
<script>
const blockedWorker = new Worker("data:application/javascript,…");
</script>
规范
| Specification |
|---|
| Content Security Policy Level 3> # directive-child-src> |
浏览器兼容性
Loading…