DOMPurify Template XSS Bypass, Fixed in 3.5.0 (CVE-2026-144292)
DOMPurify before 3.5.0 can return markup that becomes a live template expression when reparsed, allowing XSS in apps using SAFE_FOR_TEMPLATES.
TL;DR
- A DOMPurify bypass lets brace fragments survive sanitization as separate text nodes, then join into a live template expression when the browser reparses the output. CVE-2026-144292 carries CVSS v4.0 7.6 High.
- Every DOMPurify release before 3.5.0 is affected when an application enables
SAFE_FOR_TEMPLATESand a template engine compiles the sanitized DOM. - The advisory includes a public proof of concept, and CISA's SSVC assessment records exploitation as
poc. No in-the-wild exploitation is reported, and the CVE is not in CISA KEV as of 2026-12-04. - Upgrade to 3.5.1 or later. "How do I fix it?" gives the npm, yarn and pnpm commands and a workaround for applications that cannot reparse safely.
Am I affected?
You are affected if your application sanitizes attacker-controlled markup with SAFE_FOR_TEMPLATES and then lets a client-side template engine compile the result. All of these must hold:
- The application calls
DOMPurify.sanitize()withSAFE_FOR_TEMPLATES: true. - It assigns the returned string to an HTML sink such as
innerHTML. - A client-side template engine compiles that DOM after the assignment. The advisory verified Vue 3 in-DOM templates and AngularJS 1.8.3.
- The attacker controls part of the markup passed to
sanitize(), for example a comment, a profile field or a rich-text message. - The DOMPurify version is earlier than 3.5.0.
An application that never enables SAFE_FOR_TEMPLATES does not use the affected protection. An application that sanitizes but renders the result as text, or that never compiles the result as a template, does not expose the template evaluation path. The version alone is not enough to decide exposure.
| Release line | Affected versions | Fixed version |
|---|---|---|
| DOMPurify 3.x | every release before 3.5.0, including 3.4.18 | 3.5.0; 3.5.1 is current |
Check the installed version in the project:
npm ls dompurify
yarn why dompurify
pnpm why dompurify
Read the lockfile entry when the package is a transitive dependency:
grep -A2 '"node_modules/dompurify"' package-lock.json
grep -A2 '^dompurify@' yarn.lock
grep -A2 'dompurify' pnpm-lock.yaml
Check whether the application enables the option:
grep -rn "SAFE_FOR_TEMPLATES" src/
A match in application code, or a wrapper that sets the option globally, means the project uses the affected path. A bundled copy inside a widget or an embedded script also needs its own version check.
How do I fix it?
Upgrade DOMPurify to 3.5.1 or later, rebuild the bundle and confirm the version the application actually loads.
- Install the fixed release with the package manager the project uses.
- Rebuild the front-end bundle and any vendored copy.
- Confirm the resolved version with
npm ls dompurify. - If the library is loaded from a CDN, change the pinned URL to 3.5.1 and clear the cached copy.
npm install dompurify@3.5.1
yarn add dompurify@3.5.1
pnpm add dompurify@3.5.1
If you cannot upgrade yet, stop compiling sanitized output as a template. Render the sanitized string as text, or sanitize the final DOM with a parser that does not hand the output to a template engine. Disabling SAFE_FOR_TEMPLATES removes the protection against template expressions, so only do that when the output is never compiled as a template. The workaround changes the rendering design and does not repair the library.
The 3.4.18 release does not fix this variant. The advisory reproduced the payload on 3.4.18, so a project that pinned the November release still needs the upgrade.
What is the root cause?
The sanitizer checks for template expressions in each text node and in the serialized string. The output is not stable under a second parse, so a nested <form> can rejoin three separate brace fragments into one expression. The check runs in two places in src/purify.ts at 3.4.18. Neither place accounts for how the consumer parses the returned string.
The first check walks each text node:
if (SAFE_FOR_TEMPLATES && nodeType === NODE_TYPE.text) {
const text = currentNode.textContent;
const content = _stripTemplateExpressions(text);
if (text !== content) {
arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() });
currentNode.textContent = content;
}
}
The second check runs after serialization, and only when the serialized string contains a marker:
if (
SAFE_FOR_TEMPLATES &&
regExpTest(EXPRESSIONS.TMPL_MARKER_SERIALIZED, serializedHTML)
) {
_scrubOwnCharacterData(body);
serializedHTML = serialize();
}
TMPL_MARKER_SERIALIZED is /{{|}}|\${|<%|%>|<%|%>/ in src/regexp.ts. The payload uses the nested <form> shape from the advisory:
<form><div>{</form><form>{constructor.constructor('alert(1)')()}</form>}
On the first parse, </form> clears the parser's form element pointer while the <div> is still open. The second <form> is accepted as a child of the <div>. The tree holds three separate text nodes, {, {constructor.constructor('alert(1)')()} and }, with an element between them. No single text node contains {{ or }}, so the per-node check does nothing.
Serialization produces this string:
<form><div>{<form>{constructor.constructor('alert(1)')()}</form>}</div></form>
The string contains no {{ or }}, because a <form> tag sits between the braces. TMPL_MARKER_SERIALIZED does not match, so the post-serialization scrub never runs. Even if it ran, it works on the same tree, where the fragments are still separate text nodes.
When the consumer assigns the string to innerHTML, the HTML parser ignores the inner <form> start tag because a form is already open. The three fragments become adjacent and merge into one text node:
{{constructor.constructor('alert(1)')()}}
A template engine that compiles the DOM then evaluates the expression. The guarantee the caller needs is "no expression after the output is parsed again", but the library checks "no expression in my tree and no marker in my string".
How is it exploited?
An attacker submits the nested <form> markup, the application sanitizes it, and the consumer's template engine runs the reconstructed expression in the page origin. The advisory publishes a working proof of concept, so the steps that follow use that code.
- The attacker submits markup with a split brace pair around a nested
<form>, using that payload. - The application passes the markup to
DOMPurify.sanitize()withSAFE_FOR_TEMPLATES: true. - DOMPurify returns a string that contains no
{{or}}, because the inner<form>tag separates the braces. - The application assigns the string to
innerHTML. - The browser ignores the nested
<form>start tag and merges the three text fragments into one. - A template engine compiles the DOM and evaluates the attacker's expression as JavaScript.
The minimal check from the advisory:
const clean = DOMPurify.sanitize(
"<form><div>{</form><form>{constructor.constructor('alert(1)')()}</form>}",
{ SAFE_FOR_TEMPLATES: true }
);
// clean === "<form><div>{<form>{constructor.constructor('alert(1)')()}</form>}</div></form>"
const div = document.createElement('div');
div.innerHTML = clean;
// div.textContent === "{{constructor.constructor('alert(1)')()}}"
The end-to-end proof of concept loads DOMPurify 3.4.18, Vue 3.5.45 and AngularJS 1.8.3, writes the sanitized string into each host, and mounts the template engine. Both engines executed the expression in Chromium 156, Firefox 157 and WebKit 27.2. The advisory links the full page.
How does the attack flow?
Three brace fragments survive as separate text nodes. A nested <form> tag keeps the serialized marker check from firing, and the reparse merges the fragments into an expression that the template engine evaluates.
What can an attacker do?
An attacker can run JavaScript in the origin of the page that renders the sanitized content, for every user who views it. That covers session theft, actions taken as the victim, and changes to the page content. The advisory demonstrates script execution in Vue 3 in-DOM templates and AngularJS 1.8.3, and it says other mustache-style engines that compile existing DOM are likely affected.
The impact needs all of these conditions:
- The application enables
SAFE_FOR_TEMPLATES. - The attacker can submit markup that reaches
sanitize(). - The sanitized output is assigned to an HTML sink and then compiled by a template engine.
- A victim loads the page after the content is stored or reflected.
The flaw is a sanitizer bypass, not a DOMPurify memory-safety issue. It does not give server-side code execution by itself, and it does not affect an application that never compiles the sanitized DOM as a template.
The CVSS v4.0 vector is CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:H/VI:H/VA:L/SC:N/SI:N/SA:N. It records the passive user interaction and the prerequisite that the consumer reparses and compiles the output.
Why does the fix work?
The fix always scrubs the sanitized tree. It treats the boundary between two text nodes as if the tags between them were gone, so the nested <form> fragments are caught before serialization. The 3.5.0 release also removed the marker gate that skipped the scrub.
--- a/src/purify.ts
+++ b/src/purify.ts
@@
- const serialize = (): string =>
- WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
- let serializedHTML = serialize();
-
- /* Scrub our tree, not the markup: a regex over markup cuts through
- tags. Only needed if the output holds a marker pair. Template
- content was already scrubbed by _sanitizeShadowDOM. */
- if (
- SAFE_FOR_TEMPLATES &&
- regExpTest(EXPRESSIONS.TMPL_MARKER_SERIALIZED, serializedHTML)
- ) {
+ /* Scrub our tree, not the markup: a regex over markup cuts through
+ tags. Template content was already scrubbed by _sanitizeShadowDOM. */
+ if (SAFE_FOR_TEMPLATES) {
_scrubOwnCharacterData(body);
- serializedHTML = serialize();
}
+
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
The scrub itself now checks the join between consecutive text nodes:
/* A reparse can drop the tags between two text nodes, e.g. those of a
nested form. If their boundary completes a marker, scrub the previous
text as if the next character belonged to it. */
if (data && _readNodeType(currentNode) === NODE_TYPE.text) {
if (previousText) {
const tail = previousText.data;
const boundary = tail[tail.length - 1] + data[0];
if (regExpTest(EXPRESSIONS.TMPL_MARKER, boundary)) {
previousText.data = _stripTemplateExpressions(tail + data[0]);
}
}
previousText = currentNode;
}
The boundary check catches the case where the last character of one text node and the first character of the next form {{ or }}, even when an element sits between them. For the nested <form> payload, the scrub removes the expression before the string is returned, so the reparse has nothing to merge.
The 3.5.0 release notes limit the guarantee. SAFE_FOR_TEMPLATES is guaranteed for string input. For DOM node input and IN_PLACE, it is best effort, because a tree the HTML parser did not build can change shape when it is parsed again. This advisory covers string input, and the fix is complete for that case.
How do I check if I was compromised?
No indicators of compromise are published for CVE-2026-144292, and client-side template execution leaves no server log by default. A successful attack looks like a normal page view to the application.
You can search stored content for the payload shape from the advisory and for the expression text. A hit is a lead, not proof, because benign content can contain the same strings.
grep -rn --include='*.html' --include='*.json' --include='*.md' \
-e '</form><form>' -e 'constructor.constructor' .
If the search finds a match in a field that the application renders as HTML and compiles as a template, review the rendered page. Check the browser console for script execution. Check the browser's Content Security Policy reports for blocked inline script if a policy is deployed. An attempt that fails may leave no trace at all.
Timeline
- 2026-11-14: DOMPurify 3.4.18 shipped a fix for an earlier
SAFE_FOR_TEMPLATESreparse advisory. The nested<form>variant still reproduced on that release. - 2026-11-22: DOMPurify 3.5.0 shipped with the complete fix for string input.
- 2026-11-23: The vendor advisory GHSA-hrxw-jjj6-2g2j was published.
- 2026-12-02: DOMPurify 3.5.1 shipped and became the current release.
- 2026-12-03: CVE-2026-144292 was published.
The gap from the 3.4.18 release to the CVE record was 19 days. The complete fix shipped 8 days after 3.4.18.
FAQ
Does DOMPurify 3.4.18 fix this?
No. The advisory reproduced the nested <form> payload on 3.4.18. That release fixed an earlier variant, but the marker-gated scrub still skipped this shape. 3.5.0 is the first fixed release, and 3.5.1 is current.
Is SAFE_FOR_TEMPLATES enabled by default?
No. The option defaults to false. An application has to enable it, usually because it renders user content inside a client-side template. A project that never sets the option is outside this bypass.
Does this affect server-side DOMPurify?
It can affect a server that sanitizes with jsdom and then sends the output to a client that compiles it as a template. The advisory reproduced the same output string on jsdom 27.0.1. The script execution happens in the browser when the template engine compiles the reparsed DOM, not inside the sanitizer call.
Is there a public proof of concept?
Yes. The vendor advisory includes a minimal sanitize call and a full HTML page that executes the expression in Vue 3 and AngularJS 1.8.3. The page was tested in Chromium 156, Firefox 157 and WebKit 27.2.
Is CVE-2026-144292 in CISA KEV?
No. The CISA KEV catalog was at version 2026.11.30 with 1,810 records on 2026-12-04, and this CVE is not in it. CISA's SSVC assessment records exploitation as poc, not active.
What if I cannot upgrade yet?
Do not assign sanitized output to innerHTML and then compile it as a template. Render the content as text, or sanitize the final DOM with a parser that does not pass it to a template engine. Disabling SAFE_FOR_TEMPLATES only helps when the output is never compiled, because it removes the protection against template expressions.
Track vulnerable JavaScript dependencies with Ostorlab
Ostorlab's software composition analysis inventories the JavaScript packages and versions in your applications and produces an SBOM. It finds every bundle that still carries a DOMPurify release before 3.5.0. It shows the dependency; the upgrade and the rendering review remain yours.
References
- DOMPurify, "SAFE_FOR_TEMPLATES bypass: nested
<form>makes a template expression reassemble when sanitized output is reparsed", GHSA-hrxw-jjj6-2g2j, published 2026-11-23 (checked December 4, 2026): https://github.com/cure53/DOMPurify/security/advisories/GHSA-hrxw-jjj6-2g2j - CVE Program, "CVE-2026-144292" record, published 2026-12-03 (checked December 4, 2026): https://www.cve.org/CVERecord?id=CVE-2026-144292
- DOMPurify, "3.5.0" release notes, published 2026-11-22 (checked December 4, 2026): https://github.com/cure53/DOMPurify/releases/tag/3.5.0
- DOMPurify, "3.5.1" release notes, published 2026-12-02 (checked December 4, 2026): https://github.com/cure53/DOMPurify/releases/tag/3.5.1
- DOMPurify, "3.4.18" release, published 2026-11-14 (checked December 4, 2026): https://github.com/cure53/DOMPurify/releases/tag/3.4.18
- DOMPurify, earlier
SAFE_FOR_TEMPLATESreparse advisory GHSA-qm7q-q8h9-jg8q, published 2026-11-14 (checked December 4, 2026): https://github.com/cure53/DOMPurify/security/advisories/GHSA-qm7q-q8h9-jg8q - DOMPurify source at 3.4.18,
src/purify.ts(checked December 4, 2026): https://github.com/cure53/DOMPurify/blob/3.4.18/src/purify.ts - DOMPurify source at 3.5.0,
src/purify.ts(checked December 4, 2026): https://github.com/cure53/DOMPurify/blob/3.5.0/src/purify.ts - npm,
dompurifypackage page with weekly download count, 102,408,890 for 2026-11-26 to 2026-12-02 (checked December 4, 2026): https://www.npmjs.com/package/dompurify - CISA, Known Exploited Vulnerabilities catalog, version 2026.11.30, 1,810 records (checked December 4, 2026): https://www.cisa.gov/known-exploited-vulnerabilities-catalog
Keep reading
