# DOMPurify SAFE_FOR_TEMPLATES bypass in shadow root content

Source: https://junglewise.ai/threats/dompurify-safe-for-templates-bypass-split-template-expressions-survive-c23665cf  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2026-10-22. Updated: 2026-10-22  
License: CC BY 4.0 with a link back

Severity: critical · CVSS 4 · Published 2026-10-22

DOMPurify is a JavaScript library that sanitizes HTML to prevent XSS attacks. When configured to protect template expressions (like ${...}), it fails to clean template syntax inside shadow DOM content, allowing attackers to inject malicious code that a downstream template engine will execute as code. This can lead to stolen data or account takeover in web applications.

Technologies: [Cure53 DOMPurify](https://junglewise.ai/threats/technologies/cure53-dompurify), [dompurify (npm)](https://junglewise.ai/threats/technologies/dompurify). Vendors: [Cure53](https://junglewise.ai/threats/vendors/cure53), [npm](https://junglewise.ai/threats/vendors/npm).

## Quick answers

**Is This vulnerability exploited in the wild?** No. Junglewise Threat Intelligence has no report of This vulnerability being exploited in the wild.

**How severe is This vulnerability?** Critical severity, with a CVSS score of 4, published 22 October 2026.

**Which products and versions are affected?** Cure53 DOMPurify 3.4.4 through 3.4.16; DOMPurify 3.4.4 through 3.4.16; dompurify (npm) >= 3.4.4, <= 3.4.16, SEMVER:introduced=3.4.4,fixed=3.4.17.

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

**How is This vulnerability attacked?** It is attacked over the network, in a software library.

**Am I affected?** Check whether you run Cure53 DOMPurify, DOMPurify or 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.17 or later

  ```sh
  npm install dompurify@3.4.17
  ```


## Technical details

When SAFE_FOR_TEMPLATES is enabled with DOM-returning modes (IN_PLACE, RETURN_DOM, or RETURN_DOM_FRAGMENT), the post-walk safety check _scrubTemplateExpressions does not recurse into attached shadow roots, only into &lt;template&gt; elements. An attacker can split a template expression (e.g., "${alert(1)}") across text nodes separated by disallowed elements; when the disallowed elements are stripped during sanitization, the fragments become adjacent and merge into a complete expression that survives. This requires an attacker-supplied DOM node with an attached shadow root and downstream template evaluation.

## Affected products

- Cure53 DOMPurify 3.4.4 through 3.4.16

## Timeline

- 2026-10-22: disclosed

## References

- [https://github.com/cure53/DOMPurify/security/advisories/GHSA-cg2g-xh64-v4q7](https://github.com/cure53/DOMPurify/security/advisories/GHSA-cg2g-xh64-v4q7)
- [https://github.com/cure53/DOMPurify/pull/1672](https://github.com/cure53/DOMPurify/pull/1672)

## Related threats

- [DOMPurify SAFE_FOR_TEMPLATES bypass via shadow root content](https://junglewise.ai/threats/cve-2026-116804-dompurify-from-3-4-4-before-3-4-17-contains-a-safe-for-templates)
- [DOMPurify DOM XSS in IN_PLACE hook-detached subtrees](https://junglewise.ai/threats/cve-2026-116803-dompurify-before-3-4-17-contains-a-cross-site-scripting)
- [DOMPurify cross-site scripting in SMIL attributeName guard bypass](https://junglewise.ai/threats/cve-2026-116802-dompurify-before-3-4-17-contains-a-cross-site-scripting)
- [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)
