v157 · web api · sanitizer · enabled by default
Add javascriptURLs option to SanitizerConfig and Sanitizer
A new boolean knob in the HTML standard’s Sanitizer API that makes javascript:-URL removal a developer-selectable option instead of a side effect of which method you call: SanitizerConfig gains a javascriptURLs member and Sanitizer gains a setJavascriptURLs(allow) method. Previously the API stripped javascript: URLs only via the “safe” methods (setHTML(), parseHTML()); with the option, the “unsafe” methods can remove them too — and a custom config can state the choice explicitly. MDN’s SanitizerConfig and Sanitizer pages do not document this option yet (checked 2026-11-01), so this reference covers it.
at a glance
| What it is | A boolean javascriptURLs member on SanitizerConfig plus Sanitizer.setJavascriptURLs(allow): “Sets whether the sanitizer preserves attributes containing javascript: URLs” (spec prose, quoted verbatim) |
|---|---|
| Why | javascript:-URL stripping used to be hard-wired to the “safe” methods only — “awkward if users wanted to use the ‘unsafe’ methods for some reason, but still wanted javascript:-URLs removed” (ChromeStatus motivation; discussion in whatwg/html #12686, normalized by PR #12898) |
| Milestone listing | Chrome 157 — listed under “Enabled by default” in the milestone=157 listing (fetched 2026-11-01; the listing is authoritative for filing); desktop milestone 157 on the API record |
| Runtime feature | No dedicated flag record: runtime_enabled_features.json5 has no SanitizerJavascriptURLs entry (verified 2026-11-01; that name is the record’s Finch rollout name). The umbrella SanitizerAPI feature is status: "stable" |
| Spec | HTML Standard — setJavascriptURLs() (merged into the living standard; the ChromeStatus record’s spec link is the spec PR) |
| ChromeStatus | 5169798320357376 — Add javascriptURLs option to SanitizerConfig and Sanitizer |
| Intent to Ship | blink-dev intent thread (linked from the ChromeStatus record) |
why it exists
The Sanitizer API has two families of insertion methods: the safe ones (Element.setHTML(), Document.parseHTML()), which guarantee no script can survive sanitization, and the unsafe ones (setHTMLUnsafe(), parseHTMLUnsafe()), which apply only the configuration you give them. javascript: URLs in navigating attributes (an <a href>, a <form action>, …) are a script vector, so the safe methods always stripped them — but that behavior was attached to the method, not the configuration. whatwg/html issue #12686 called this out, and PR #12898 regularized it into the explicit javascriptURLs configuration option, so an unsafe-method caller can still opt in to javascript:-URL removal, and any configuration can state its choice explicitly.
syntax
From the HTML living standard (IDL quoted verbatim, fetched 2026-11-01; Sanitizer is [Exposed=Window]):
dictionary SanitizerConfig {
// … elements, removeElements, replaceWithChildrenElements,
// attributes, removeAttributes …
boolean comments;
boolean dataAttributes;
boolean javascriptURLs; // NEW in this change
};
[Exposed=Window]
interface Sanitizer {
constructor(optional (SanitizerConfig or SanitizerPresets) configuration = "default");
SanitizerConfig get();
// … allowElement, removeElement, replaceElementWithChildren,
// allowAttribute, removeAttribute, setComments, setDataAttributes …
boolean setJavascriptURLs(boolean allow); // NEW in this change
boolean removeUnsafe();
};
Source: HTML Standard — the Sanitizer interface (elided members marked with ellipses; the two new items verbatim)
the javascriptURLs member — inputs and defaults
A plain Web IDL boolean. true means the sanitizer preserves attributes containing javascript: URLs; false means it removes them. When the member is absent, the default depends on how the configuration is used: the spec’s built-in safe default configuration carries javascriptURLs: false (remove), while canonicalization of a custom configuration fills an absent member from the permissive defaults (“If configuration["javascriptURLs"] does not exist, then set it to permissiveDefaults” — spec step, quoted) — so an unsafe-method call with a config that doesn’t mention the member keeps javascript: URLs, exactly as before this change. There is no third state.
the setJavascriptURLs(allow) method
Quoting the method steps verbatim: “Let configuration be this’s configuration. Assert: configuration is valid. If configuration["javascriptURLs"] is allow, then return false. Set configuration["javascriptURLs"] to allow. Return true.” So the boolean return value reports whether the configuration changed — false means the sanitizer was already in the requested state. The method throws no exceptions; the only input is the required allow boolean (any JS value coerces per Web IDL boolean conversion).
setJavascriptURLs() method steps
what it changes during sanitization
- Attribute filtering — in the keep-this-attribute algorithm: if
javascriptURLsistruethe attribute is kept without URL inspection; otherwise, if the (element, attribute) pair matches the spec’s built-in navigating URL attributes list (normative definitions plus a table of element/attribute pairs) and the value contains ajavascript:URL, the attribute is dropped. removeUnsafe()forces removal — its steps include: “If configuration["javascriptURLs"] is true: Set result to true. Set configuration["javascriptURLs"] to false.” An unsafe-allowing config becomes a removing one.- Method defaults are unchanged — safe methods still remove
javascript:URLs (their default configuration saysfalse); unsafe methods with a config that omits the member still keep them (permissive defaulttrue). The change is that either behavior can now be requested explicitly from either method family.
where it applies
Sanitizer is [Exposed=Window]; the option takes effect wherever a SanitizerConfig or Sanitizer is consumed: Element.setHTML() / setHTMLUnsafe(), ShadowRoot.setHTML() / setHTMLUnsafe(), and Document.parseHTML() / parseHTMLUnsafe(). No permission, secure-context restriction, or flag is recorded for it; in Chrome it ships with the stable SanitizerAPI runtime feature (milestone 157 for this option per the listing). Feature-detect the method directly:
const supported = "setJavascriptURLs" in Sanitizer.prototype;
Source: HTML Standard — Sanitizer interface; runtime_enabled_features.json5
examples
// Unsafe method, but with javascript: URLs removed — the case
// that motivated the option (previously impossible):
const sanitizer = new Sanitizer(); // "default" preset
sanitizer.setJavascriptURLs(false); // returns true if it changed
el.setHTMLUnsafe(userMarkup, { sanitizer });
// Same thing as a plain config dictionary:
el.setHTMLUnsafe(userMarkup, {
sanitizer: { javascriptURLs: false },
});
// The setter's return value reports change, not success:
const s = new Sanitizer({ javascriptURLs: false });
s.setJavascriptURLs(false); // → false (already in that state)
s.setJavascriptURLs(true); // → true (configuration changed)
// Inspect the resulting configuration:
console.log(s.get().javascriptURLs); // → true
browser compatibility
Per-version data from BCD api/Sanitizer.json (fetched 2026-11-01). BCD already has a setJavascriptURLs subfeature key, but no browser has a recorded version yet — a freshness gap against the Chrome milestone-157 listing, shown as such.
| Browser | Sanitizer (host API) | setJavascriptURLs / javascriptURLs |
|---|---|---|
| Chrome | 146 (webstatus.dev) | Milestone 157 per the ChromeStatus record; BCD version_added: false (not yet recorded) |
| Edge | 146 (mirrors Chrome) | Mirrors Chrome |
| Firefox | 148 (webstatus.dev) | “Shipped/Shipping” per the ChromeStatus vendor view; BCD version_added: false (not yet recorded) |
| Safari | Not shipped; position “Support” for the host API (WebKit/standards-positions #86) | Not shipped |
For orientation, the host Sanitizer API web-feature is Baseline limited on webstatus.dev (Chrome 146 · Firefox 148 · no Safari).
Source: BCD api/Sanitizer.json; webstatus.dev sanitizer; ChromeStatus API recordsecurity and privacy
javascript:URLs are an XSS vector — a surviving<a href="javascript:…">runs script on activation. The option only ever adds a way to remove them from unsafe-method output; the safe methods’ guarantee is unchanged, andremoveUnsafe()now forcibly flips the option tofalseas part of its make-this-config-safe contract (quoted in semantics).- The hazard is the permissive default — an unsafe-method config that omits
javascriptURLskeepsjavascript:URLs (permissive canonicalization default). Code that migrates fromsetHTML()tosetHTMLUnsafe()expecting URL stripping to follow must now sayjavascriptURLs: falseexplicitly. - No privacy surface — the option processes markup already in the page; it stores nothing and exposes no new information about the user (no spec-flagged privacy considerations in PR #12898).
specifications
| Document | Status |
|---|---|
HTML Standard — Sanitizer.setJavascriptURLs() and the SanitizerConfig dictionary | Living standard — the option is merged text (verified present 2026-11-01) |
| whatwg/html PR #12898 — the change that added the option | The ChromeStatus record’s spec link; merged into the living standard |
| whatwg/html issue #12686 — originating discussion | Motivating issue, linked from the ChromeStatus motivation |
see also
- Chrome Platform Status — Add javascriptURLs option to SanitizerConfig and Sanitizer (API record)
- MDN — Sanitizer and MDN — SanitizerConfig (neither documents the
javascriptURLsoption yet — member/method absent from both pages, checked 2026-11-01; the method URL 404s) - MDN — HTML Sanitizer API overview
- Chrome Platform Showcase — interactive demos for this feature