CSP Missing base-uri Restriction: Hardening Guide
Technical guidance and AI-prompt disclaimer: These explanations and fix directions are for general technical reference only and are not a security audit, professional advice, or a compliance guarantee. AI coding tools can produce wrong, incomplete, or insecure code; before changing security settings (such as headers, cookies, CSP, or HSTS), back up your site and test in staging. You remain solely responsible for reviewing, testing, and deploying all changes.
Content notice: Drafted by AI and cross-checked by another AI model family (no human sign-off), version 1.0, updated 2026-11-27. Have a human check and test in staging before changing production settings. About Meowdit
Within a Content-Security-Policy (CSP), the base-uri directive controls which base addresses an HTML <base> element is allowed to set for a document. Even when a site enforces a strict policy for scripts, browsers do not fall back to default rules for base-uri. If markup injection ever occurs, an injected <base> tag can rewrite relative paths across the page. Because this check highlights an optional defensive hardening improvement rather than an observed attack, always confirm your site's routing needs, back up your configuration, and test in staging before updating production CSP.
What it is
Your site already sends a Content-Security-Policy, yet it does not include a base-uri directive to restrict which origins a page's <base> element may target.
Why it matters
If an attacker can inject HTML markup into a page, an unrestricted <base> element can redirect relative script, stylesheet, and form URLs to an external host. Adding base-uri is an optional defensive hardening step and is not proof of an active exploit.
Meowdit rates this medium risk.
How to tell if your site has it
- Open browser developer tools, navigate to the Network tab, select the main HTML document response, and read the Content-Security-Policy header to see whether base-uri is declared.
- If your application also outputs CSP through a document meta tag, inspect that tag as well and make sure multiple policies do not conflict.
- Search your templates and client routing setup to confirm whether any page legitimately relies on a <base> element for relative links or asset paths.
- Check key routes such as sign-in, checkout, and public landing pages because different edge rules or frameworks sometimes emit different security headers per route.
Fix direction
Treat this as an optional defensive hardening step: verify whether your templates rely on a base element, then add a base-uri restriction to your existing enforced policy without loosening other rules. Always back up your configuration and validate key user flows in staging before changing production CSP.
A scan gives you the steps specific to your site, plus a fix prompt you can paste into an AI tool. See what a report looks like: View the public example report
FAQ
- Does missing base-uri mean my website is currently compromised?
- No. Missing base-uri is an optional hardening observation, not evidence of an active exploit or existing injection bug. Adding it simply reduces blast radius if an HTML injection issue ever slips into a page.
- My policy already restricts scripts and default sources. Why is base-uri checked separately?
- In the CSP specification, base-uri does not inherit from default fallback directives. Unless base-uri is stated explicitly, browsers allow any <base> element injected into the document to alter relative URL resolution.
- What should I check before changing CSP in production?
- Verify whether single-page app routers, nested subpaths, or third-party widgets depend on a base element. Back up your current header configuration and test navigation, forms, and asset loading in staging before deploying changes to production.