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

Source: https://junglewise.ai/threats/cve-2026-41239-dompurify-has-a-safe-for-templates-bypass-in-return-dom-mode  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2026-04-23. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

CVE-2026-41239 · Severity: medium · CVSS 6.8 · Published 2026-04-23

DOMPurify is a widely-used HTML sanitizer that removes potentially malicious code from user-supplied content. When configured with SAFE_FOR_TEMPLATES and RETURN_DOM modes, it fails to strip template expressions (like {{...}}) from certain HTML structures, allowing attackers to inject XSS code that executes in template-evaluating frameworks like Vue 2. This can lead to arbitrary JavaScript execution and compromise of user sessions or data.

Technologies: [dompurify (npm)](https://junglewise.ai/threats/technologies/dompurify). Vendors: [npm](https://junglewise.ai/threats/vendors/npm).

## Quick answers

**Is CVE-2026-41239 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2026-41239 being exploited in the wild.

**How severe is CVE-2026-41239?** Medium severity, with a CVSS score of 6.8, published 23 April 2026.

**Which products and versions are affected?** dompurify (npm) >= 1.0.10, < 3.4.0, SEMVER:introduced=1.0.10,fixed=3.4.0.

**Is there a fix for CVE-2026-41239?** Yes. dompurify (npm): upgrade to 3.4.0 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2026-41239 attacked?** It is attacked over the network.

**Am I affected by CVE-2026-41239?** Check whether you run dompurify (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- dompurify (npm): upgrade to 3.4.0 or later

  ```sh
  npm install dompurify@3.4.0
  ```


## Technical details

DOMPurify has a two-pass sanitization strategy: per-node filtering during DOM traversal and a final string scrub after serialization. However, in RETURN_DOM and RETURN_DOM_FRAGMENT modes, the function returns early before the second pass runs. An attacker can exploit this by splitting template expression delimiters across multiple text nodes (e.g., { &lt;disallowed-tag&gt; } {payload} &lt;/disallowed-tag&gt; }) so that no single node contains the complete {{ pattern; the per-node pass misses it. When DOMPurify removes the disallowed tags, adjacent text nodes merge, reconstituting the template expression. The resulting DOM is then mounted into a framework like Vue 2 which compiles and executes the injected code. The fix normalizes text nodes before returning in RETURN_DOM mode, ensuring the final string scrub catches reconstructed expressions.

## Affected products

- Cure53 DOMPurify <3.4.0

## Identifiers

- CVE-2026-41239
- GHSA-crv5-9vww-q3g8

## Timeline

- 2026-04-22: disclosed
- 2026-04-20: patched: Patched in version 3.4.0

## References

- [https://github.com/cure53/DOMPurify/security/advisories/GHSA-crv5-9vww-q3g8](https://github.com/cure53/DOMPurify/security/advisories/GHSA-crv5-9vww-q3g8)

## Related threats

- [DOMPurify SAFE_FOR_TEMPLATES bypass in shadow root content](https://junglewise.ai/threats/dompurify-safe-for-templates-bypass-split-template-expressions-survive-c23665cf)
- [DOMPurify IN_PLACE event handler bypass when hook removes parent or sibling](https://junglewise.ai/threats/dompurify-in-place-hook-that-removes-a-parent-or-sibling-leaves-the-3ea5d18f)
- [DOMPurify SMIL attributeName=href guard bypass in XHTML mode](https://junglewise.ai/threats/dompurify-smil-attributename-href-guard-is-skipped-when-parser-media-15a5efd2)
- [DOMPurify IN_PLACE mode XSS via rawtext element text content](https://junglewise.ai/threats/dompurify-in-place-returns-a-force-removed-rawtext-root-whose-text-16d9ac9e)
- [DOMPurify DOM XSS in IN_PLACE mode with afterSanitize hooks](https://junglewise.ai/threats/dompurify-in-place-node-removing-aftersanitize-hook-leaves-detached-3087e7fd)
