--- title: 'CSP: base-uri' slug: Web/HTTP/Headers/Content-Security-Policy/base-uri tags: - CSP - Directive - Document directive - HTTP - Security translation_of: Web/HTTP/Headers/Content-Security-Policy/base-uri ---
HTTP {{HTTPHeader("Content-Security-Policy")}} の base-uri
ディレクティブは、ドキュメントの要素 {{HTMLElement("base")}} で、使用できる URL を制限します。この値が存在しない場合は、任意の URI が許可されます。このディレクティブが存在しない場合、ユーザーエージェントは、{{HTMLElement("base")}} 要素の値を使用します。
CSP version | 2 |
---|---|
Directive type | {{Glossary("Document directive")}} |
{{CSP("default-src")}} fallback | 設定しないと、任意の URL が許可されます。 |
1 つまたは複数のソースを base-uri ポリシーに使用:
Content-Security-Policy: base-uri <source>; Content-Security-Policy: base-uri <source> <source>;
このディレクティブは他の CSP ディレクティブと同じ引数を使用しますが、キーワードの 'unsafe-inline'
や 'strict-dynamic'
などは意味がありません。
{{page("ja/docs/Web/HTTP/Headers/Content-Security-Policy/default-src", "Sources")}}
<meta http-equiv="Content-Security-Policy" content="base-uri 'self'">
<IfModule mod_headers.c> Header set Content-Security-Policy "base-uri 'self'"; </IfModule>
add_header Content-Security-Policy "base-uri 'self';"
ドメインが example.com
でないので、https://example.com
に設定された {{HTMLElement("base")}} 要素の href
が CSP 違反になります。
<meta http-equiv="Content-Security-Policy" content="base-uri 'self'"> <base href="https://example.com/"> // Error: Refused to set the document's base URI to 'https://example.com/' // because it violates the following Content Security Policy // directive: "base-uri 'self'"
仕様書 | 状態 | 備考 |
---|---|---|
{{specName("CSP 3.0", "#directive-base-uri", "base-uri")}} | {{Spec2('CSP 3.0')}} | 変更無し |
{{specName("CSP 1.1", "#directive-base-uri", "base-uri")}} | {{Spec2('CSP 1.1')}} | 初回定義 |
{{Compat("http.headers.csp.base-uri")}}