Path: blob/main/files/en-us/web/http/headers/content-security-policy/base-uri/index.md
6561 views
------{{HTTPSidebar}}
The HTTP {{HTTPHeader("Content-Security-Policy")}} base-uri directive restricts the URLs which can be used in a document's {{HTMLElement("base")}} element. If this value is absent, then any URI is allowed. If this directive is absent, the user agent will use the value in the {{HTMLElement("base")}} element.
| CSP version | 2 |
|---|---|
| Directive type | {{Glossary("Document directive")}} |
| {{CSP("default-src")}} fallback | No. Not setting this allows any URL. |
Syntax
One or more sources can be allowed for the base-uri policy:
Sources
This directive uses most of the same source values for arguments as other CSP directives: CSP Source Values.
Note however that some of the values don't make sense for base-uri, such as the keywords 'unsafe-inline' and 'strict-dynamic'.
Examples
Meta tag configuration
Apache configuration
Nginx configuration
Violation case
Since your domain isn't example.com, a {{HTMLElement("base")}} element with its href set to https://example.com will result in a CSP violation.
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
{{HTTPheader("Content-Security-Policy")}}
{{HTMLElement("base")}}
{{domxref("Node.baseURI")}}