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 的瀏覽器中載入。