{"id":"CVE-2026-106444","aliases":["CVE-2026-106444","GHSA-xw65-4hp5-5hc7"],"related":[],"kind":"vulnerability","state":"published","title":"Handlebars: JavaScript Injection via Unsafe Inline Embedding of Precompiled Templates","summary":"Handlebars provides the power necessary to let users build semantic templates. From 4.0.0 until 4.7.10, Handlebars.precompile() uses quotedString() in lib/handlebars/compiler/code-gen.js to emit static template text into generated JavaScript without escaping sequences that terminate an enclosing HTML script element. When an application precompiles attacker-controlled template text and embeds the generated source directly in an inline script element, a closing script delimiter can end the element and cause following attacker-controlled markup to be parsed and executed. Ordinary server-side rendering and precompiled templates served as external JavaScript files are not affected. This issue is fixed in version 4.7.10.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Handlebars provides the power necessary to let users build semantic templates. From 4.0.0 until 4.7.10, Handlebars.precompile() uses quotedString() in lib/handlebars/compiler/code-gen.js to emit static template text into generated JavaScript without escaping sequences that terminate an enclosing HTML script element. When an application precompiles attacker-controlled template text and embeds the generated source directly in an inline script element, a closing script delimiter can end the element and cause following attacker-controlled markup to be parsed and executed. Ordinary server-side rendering and precompiled templates served as external JavaScript files are not affected. This issue is fixed in version 4.7.10.","source":"cvelist"},{"lang":"en","text":"## Summary\n\n`Handlebars.precompile()` generates JavaScript source that is commonly embedded in browser `<script>` elements. Before the fix, static template text containing `</script>` was emitted unchanged. HTML parsers recognize `</script>` even inside a JavaScript string literal, closing the surrounding script element and allowing following attacker-controlled markup to be parsed and executed.\n\nThis affects applications that precompile attacker-controlled templates and embed the generated source directly in an HTML `<script>` element. It does not affect ordinary server-side rendering or precompiled templates delivered as external JavaScript files.\n\n## Details\n\nStatic text is serialized by `quotedString()` in `lib/handlebars/compiler/code-gen.js`. The generated JavaScript is valid, but JavaScript quoting alone does not make it safe to embed in HTML. In HTML script data, the sequence `</script>` terminates the element regardless of JavaScript string context.\n\nOn affected releases, this template:\n\n```handlebars\nsafe</script><script>alert(\"XSS\")</script><script>\n```\n\ncould produce generated source containing:\n\n```js\nreturn 'safe</script><script>alert(\"XSS\")</script><script>';\n```\n\nWhen included inline in an HTML document, the first `</script>` closes the script containing the precompiled template. The next `<script>` element is then parsed as HTML and executes.\n\n## Proof of Concept\n\n```js\nconst Handlebars = require('handlebars');\n\nconst template = 'safe</script><script>alert(\"XSS\")</script><script>';\nconst output = Handlebars.precompile(template);\n\nconsole.log(output.includes('</script>'));\n```\n\nAffected versions print `true`. Embedding `output` directly in an inline `<script>` element allows the injected script tag to be parsed by the browser.\n\n## Workarounds\n\n- Do not inline precompiled output from untrusted templates into HTML documents.\n- Serve generated precompiled templates as external JavaScript files where practical.\n\n## Credits\n\nReported by Curly-Haired-Baboon Aka Laplas","format":"markdown","source":"ghsa"}],"published":"2026-10-06T19:01:14.626Z","modified":"2026-10-08T18:00:09.713Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:L/I:L/A:N","score":4.7,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:L/I:L/A:N","score":4.7,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:L/I:L/A:N","score":4.7,"rating":"MEDIUM"}],"cwes":["CWE-116"],"affected":[{"ranges":[{"version":">= 4.0.0, < 4.7.10","status":"affected"}],"vendor":"handlebars-lang","product":"handlebars.js","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"4.0.0","status":"affected","fixed":"4.7.10"}],"ecosystem":"npm","package":"handlebars","purl":"pkg:npm/handlebars","source":"ghsa"}],"references":[{"url":"https://github.com/handlebars-lang/handlebars.js/security/advisories/GHSA-xw65-4hp5-5hc7","tags":["exploit","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/handlebars-lang/handlebars.js/pull/2185","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/handlebars-lang/handlebars.js/commit/609d1b11c833c9a3e00f56f2f34d22f425446725","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/handlebars-lang/handlebars.js/releases/tag/v4.7.10","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-106444","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/handlebars-lang/handlebars.js","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-10-06T19:47:42.547Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-106444","url":"https://www.cve.org/CVERecord?id=CVE-2026-106444","licence":"CVE Terms of Use","modified":"2026-10-06T19:48:02.050Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-xw65-4hp5-5hc7","url":"https://github.com/advisories/GHSA-xw65-4hp5-5hc7","licence":"CC-BY-4.0","modified":"2026-10-08T18:00:09.713Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-106444","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-106444","licence":"Public domain","modified":"2026-10-07T13:58:29.527Z"}],"updatedAt":"2026-11-25T22:59:42.505Z","epss":{"score":0.00334,"percentile":0.28662,"date":"2026-12-01T12:00:22.000Z"}}