CSP:img-src
HTTP Content-Security-Policy 的 img-src 指令指定了图像和网站图标的有效来源。
| CSP 版本 | 1 |
|---|---|
| 指令类型 | 获取指令 |
default-src 回退 |
是。如果此指令不存在,则用户代理将查找default-src指令。 |
语法
可以为img-src策略允许一个或多个来源
http
Content-Security-Policy: img-src <source>;
Content-Security-Policy: img-src <source> <source>;
来源
示例
违规案例
给定此 CSP 标头
http
Content-Security-Policy: img-src https://example.com/
以下<img> 将被阻止,并且不会加载
html
<img src="https://not-example.com/foo.jpg" alt="example picture" />
规范
| 规范 |
|---|
| 内容安全策略级别 3 # directive-img-src |
浏览器兼容性
BCD 表格仅在启用 JavaScript 的浏览器中加载。