Skip to main content
Vulnerability Database/CVE-2026-106444

CVE-2026-106444: Handlebars Template Engine XSS Vulnerability

CVE-2026-106444 is a cross-site scripting flaw in Handlebars template engine affecting precompiled templates embedded in inline scripts. This article covers the technical details, affected versions, and mitigation strategies.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2026-106444 Overview

CVE-2026-106444 is a script injection vulnerability in Handlebars, a widely used JavaScript templating library. Versions from 4.0.0 up to (but not including) 4.7.10 fail to escape HTML script delimiters inside template text processed by Handlebars.precompile(). The quotedString() helper in lib/handlebars/compiler/code-gen.js emits template content into generated JavaScript without escaping sequences like </script> or <!--. When precompiled output derived from attacker-controlled templates is embedded in an inline <script> element, the enclosing element can be prematurely terminated, enabling arbitrary markup execution.

Critical Impact

Attackers who control template input and have their precompiled output embedded in inline script tags can inject arbitrary HTML and JavaScript into victim pages, resulting in cross-site scripting [CWE-116].

Affected Products

  • Handlebars.js versions 4.0.0 through 4.7.9
  • Applications using Handlebars.precompile() on untrusted template text
  • Web applications embedding precompiled Handlebars output in inline <script> elements

Discovery Timeline

  • 2026-10-06 - CVE-2026-106444 published to NVD
  • 2026-10-07 - Last updated in NVD database

Technical Details for CVE-2026-106444

Vulnerability Analysis

The flaw is an output encoding failure classified as [CWE-116] (Improper Encoding or Escaping of Output). Handlebars.precompile() converts template text into a JavaScript string literal using the quotedString() helper. That helper escapes typical JavaScript string hazards such as backslashes, quotes, and control characters, but it does not escape the < character or HTML script-closing sequences.

When the generated JavaScript is served as an external .js file, the HTML parser never inspects the contents, so no injection occurs. The vulnerability only manifests when the precompiled output is inlined into an HTML <script> block, where the HTML parser scans for script-element terminators before the JavaScript parser runs.

Root Cause

The HTML specification defines restrictions for the contents of script elements: the substrings <!--, <script, and </script can end or change the parsing of an enclosing <script> element. Because quotedString() emitted these sequences verbatim inside string literals, an attacker-supplied template containing </script><img src=x onerror=alert(1)> would terminate the script tag and inject executable markup.

Attack Vector

Exploitation requires an application that (1) accepts template source from an untrusted actor, (2) calls Handlebars.precompile() on that input, and (3) embeds the generated code directly inside an inline <script> tag on a page served to victims. Ordinary server-side rendering with Handlebars.compile() and precompiled templates served as external JavaScript files are not affected.

javascript
// Patch from lib/handlebars/compiler/code-gen.js
// Source: https://github.com/handlebars-lang/handlebars.js/commit/609d1b11c833c9a3e00f56f2f34d22f425446725

// Matches any character that quotedString may have to escape: quotes,
// backslashes, control characters, line separators, surrogates and "<".
// eslint-disable-next-line no-control-regex
const NEEDS_ESCAPING = /[\\x00-\\x1f\\"\\u2028\\u2029<\\ud800-\\udfff]/;

// Per HTML "Restrictions for contents of script elements": "<!--", "<script"
// and "</script" can end or change the parsing of an enclosing <script>
// element.
const SCRIPT_DELIMITERS = /<(?=!--|\/?script)/gi;

/**
 * Escape the "<" of every sequence that could end or change the parsing of
 * an enclosing <script> element.
 */
function escapeScriptDelimiters(code) {
  return code.replace(SCRIPT_DELIMITERS, '\\\u003C');
}

The patch replaces the leading < of any dangerous sequence with the equivalent JavaScript escape \\u003C, which the HTML parser will not treat as a script terminator while preserving the string value at runtime.

Detection Methods for CVE-2026-106444

Indicators of Compromise

  • Precompiled Handlebars output in inline <script> blocks containing raw </script>, <script, or <!-- substrings inside string literals.
  • Unexpected DOM nodes appearing immediately after an inline script element known to carry Handlebars precompiled output.
  • Client-side errors referencing truncated JavaScript near template literals in pages serving precompiled templates.

Detection Strategies

  • Perform a software composition analysis (SCA) scan of application dependencies to flag any handlebars package resolving below version 4.7.10.
  • Audit application code for calls to Handlebars.precompile() whose input is sourced from user submissions, CMS content, or external APIs.
  • Review build pipelines and server templates for inline <script> blocks that interpolate precompiled Handlebars output.

Monitoring Recommendations

  • Monitor web application logs for template submissions containing script-delimiter sequences such as </script>, <!--, or <script.
  • Enable Content Security Policy (CSP) violation reporting to surface unexpected inline script execution on pages that render precompiled templates.
  • Track dependency manifests (package.json, package-lock.json, yarn.lock) in version control for Handlebars version pinning drift.

How to Mitigate CVE-2026-106444

Immediate Actions Required

  • Upgrade Handlebars to version 4.7.10 or later across all application code, build tooling, and transitive dependencies.
  • Identify every call site that passes untrusted input to Handlebars.precompile() and treat those paths as high priority for patching.
  • Deploy a strict Content Security Policy that forbids inline scripts, mitigating injection even if an unpatched build remains in production.

Patch Information

The fix is included in Handlebars.js v4.7.10. The code change is documented in GitHub commit 609d1b1 and in the GitHub Security Advisory GHSA-xw65-4hp5-5hc7. Context on the implementation is available in the GitHub Pull Request discussion.

Workarounds

  • Serve precompiled Handlebars output as external .js files rather than inlining it into <script> elements on HTML pages.
  • Restrict Handlebars.precompile() to trusted template sources and reject templates containing </script>, <script, or <!-- substrings prior to compilation.
  • Apply a server-side post-processing step that replaces < with \\u003C inside generated string literals before embedding them inline.
bash
# Upgrade Handlebars across the project to the patched release
npm install handlebars@^4.7.10

# Verify the resolved version in the dependency tree
npm ls handlebars

# For Yarn-managed projects
yarn upgrade handlebars@^4.7.10

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.