CVE-2026-140391 — Dompurify — CWE-79 · CWE-1336
### Summary With `SAFE_FOR_TEMPLATES: true`, DOMPurify 3.4.17 returns strings that contain no `{{` or `}}`, but which turn into a live `{{…}}` expression as soon as the string is assigned to `innerHTML`. A template engine that then compiles that DOM (verified with Vue 3 in-DOM templates and AngularJS 1.8.3) evaluates the attacker's expression, giving arbitrary JavaScript execution. The attacker controls only the markup passed to `sanitize()`. The only configuration required is `SAFE_FOR_TEMPLATES: true`, which is a protective option, and the application uses it for its documented purpose. There are two independent variants. Both variants reproduce on Chromium 156, Firefox 157 and WebKit 27.2. The plain `{{…}}` case and the "expression split by a removed element" case are still correctly scrubbed, so this is a gap in the existing protection, not a missing feature. ### Details `SAFE_FOR_TEMPLATES` scrubbing happens in two places, and neither accounts for how the returned string is parsed a second time by the consumer. 1. Per text node, during the walk (`src/purify.ts`, around line 2396): ```ts if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) { const content = _stripTemplateExpressions(currentNode.textContent); ... ``` 2. On the final serialized string (`src/purify.ts`, around line 3273): ```ts if (SAFE_FOR_TEMPLATES) { serializedHTML = _stripTemplateExpressions(serializedHTML); } ``` Both use the expressions in
### Summary With `SAFE_FOR_TEMPLATES: true`, DOMPurify 3.4.17 returns strings that contain no `{{` or `}}`, but which turn into a live `{{…}}` expression as soon as the string is assigned to `innerHTML`. A template engine that then compiles that DOM (verified with Vue 3 in-DOM templates and AngularJS 1.8.3) evaluates the attacker's expression, giving arbitrary JavaScript execution. The attacker controls only the markup passed to `sanitize()`. The only configuration required is `SAFE_FOR_TEMPLATES: true`, which is a protective option, and the application uses it for its documented purpose. There are two independent variants. Both variants reproduce on Chromium 156, Firefox 157 and WebKit 27.2. The plain `{{…}}` case and the "expression split by a removed element" case are still correctly scrubbed, so this is a gap in the existing protection, not a missing feature. ### Details `SAFE_FOR_TEMPLATES` scrubbing happens in two places, and neither accounts for how the returned string is parsed a second time by the consumer. 1. Per text node, during the walk (`src/purify.ts`, around line 2396): ```ts if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) { const content = _stripTemplateExpressions(currentNode.textContent); ... ``` 2. On the final serialized string (`src/purify.ts`, around line 3273): ```ts if (SAFE_FOR_TEMPLATES) { serializedHTML = _stripTemplateExpressions(serializedHTML); } ``` Both use the expressions in
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
CVE-2026-140391
CVSS 6.1/10 · MEDIUM · 01.12.2026
CWE: CWE-79, CWE-1336
Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🎯 WHAT IS THIS VULNERABILITY?
Cross-Site Scripting (XSS)
Summary: ### Summary
With SAFE_FOR_TEMPLATES: true, DOMPurify 3.4.17 returns strings that contain no {{ or }}, but which turn into a live {{…}} expression as soon as the string is assigned to innerHTML. A template engine that then compiles that DOM (verified with Vue 3 in-DOM templates and AngularJS 1.8.3) evaluates the attacker's expression, giving arbitrary JavaScript execution. The attac…
Affected: dompurify
⚡ ATTACK VECTOR
Network / Remote (AV:N) · no authentication required (PR:N) · user interaction required (UI:R) · low attack complexity (AC:L).
⚠️ Scope changes (S:C) — impact can cross security boundaries.
🌍 REAL WORLD IMPACT
Partial confidentiality disclosure (C:L); limited integrity modification (I:L); pivot to other systems possible.
🛡️ REMEDIATION
→ Apply vendor security update for dompurify.
→ Add CSP headers, HTML-encode all user input.
→ Pre-patch: put service behind VPN or apply IP allowlist.
→ Add WAF rule, create IDS alert for anomalous traffic.
⚠️ URGENCY
📋 Routine update cycle (30 days)
────────────────────────────────────────
[Automated Technical Vulnerability & CVSS Vector Analysis]