CSP: base-uri
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
HTTP Content-Security-Policy
(内容安全策略)中的 base-uri
指令限制了可以应用于一个文档的
元素的 URL。假如指令值为空,那么任何 URL 都是允许的。如果指令不存在,那么用户代理会使用
元素中的值。
CSP 版本 | 2 |
---|---|
指令类型 | 文档指令 |
default-src 回落 |
无。没有设置则允许任何 URL。 |
语法
base-uri 安全策略可以设置一个或多个源:
Content-Security-Policy: base-uri; Content-Security-Policy: base-uri ;
源
此指令与其他 CSP 指令一样,使用大部分与参数相同的源值:CSP 源值。
然而,请注意,一些值对 base-uri
没有意义,例如关键字 'unsafe-inline'
和 'strict-dynamic'
。
示例
Meta tag 配置
html
Apache 配置
bash
Header set Content-Security-Policy "base-uri 'self';
Nginx 配置
bash
add_header Content-Security-Policy "base-uri 'self';"
违规的案列
规范
Specification |
---|
Content Security Policy Level 3 # directive-base-uri |