CVE-2026-106446 in Handlebars
Summary
by MITRE • 10/06/2026
Handlebars provides the power necessary to let users build semantic templates. From 4.0.0 until 4.7.10, Handlebars.compile() and Handlebars.precompile() accept pre-parsed AST objects while validating only selected PathExpression, NumberLiteral, and BooleanLiteral values. This issue bypasses the AST validation introduced in version 4.7.9 for CVE-2026-33937. An attacker who can supply an object instead of a template string can place JavaScript expressions in unchecked values such as Program.blockParams.length, a non-PathExpression parameter depth, a non-string StringLiteral.value, or a non-string PathExpression.original. The compiler emits those values into generated JavaScript, causing code execution in the server process when compile output renders or wherever precompile output is loaded. Applications that pass only template strings are not affected. This issue is fixed in version 4.7.10.
If you want to get the best quality for vulnerability data then you always have to consider VulDB.
Analysis
by VulDB Data Team • 10/07/2026
The Handlebars templating engine, widely utilized for generating dynamic HTML and other text-based outputs, contains a critical logic flaw within its compilation pipeline affecting versions from 4.0.0 through 4.7.9. This vulnerability stems from an incomplete implementation of input validation when the library processes pre-parsed Abstract Syntax Tree objects rather than raw template strings. While Handlebars introduced robust AST sanitization measures in version 4.7.9 to mitigate code injection risks, these safeguards were narrowly scoped and failed to cover all entry points within the compiler's internal logic. Specifically, the functions Handlebars.compile() and Handlebars.precompile(), when invoked with an already parsed AST object instead of a string template, bypassed the newly implemented security checks that target PathExpression nodes. This oversight creates a significant gap in defense-in-depth strategies for applications relying on pre-compiled or dynamically generated templates where input data is not strictly validated before being passed to these compilation functions.
The technical root cause lies in the selective validation of AST node types during the parsing phase. The security patch introduced in version 4.7.9 focused primarily on validating PathExpression, NumberLiteral, and BooleanLiteral values to prevent prototype pollution or arbitrary code execution via standard template syntax. However, it neglected to enforce strict type checking on other structural properties within the AST object. An attacker who gains the ability to supply a crafted JavaScript object representing an AST can inject malicious payloads into fields that are not subject to these specific validations. Key vectors include manipulating Program.blockParams.length, altering the depth parameter which is expected to be numeric but may accept unexpected types, injecting non-string values into StringLiteral.value nodes, or modifying the original property of PathExpression objects. These unchecked attributes serve as conduits for arbitrary JavaScript expressions that are subsequently emitted directly into the generated output code by the compiler engine.
The operational impact of this vulnerability is severe, leading to Remote Code Execution on the server side when the compiled template is rendered or when pre-compiled templates are loaded and executed in a Node.js environment. Because Handlebars compiles templates into JavaScript functions that run within the application's process context, any injected code inherits the privileges of the running service. This allows an attacker to execute arbitrary commands, exfiltrate sensitive data such as session tokens or database credentials, pivot to other internal systems, or compromise the integrity of the entire server infrastructure. The severity is exacerbated by the fact that many applications utilize Handlebars for rendering user-supplied content or dynamic views where input sanitization might be assumed sufficient due to previous patches, leading developers to overlook this specific vector involving pre-parsed AST objects.
This vulnerability aligns with CWE-94 Improper Control of Generation of Code (Code Injection) and is exploitable via the ATT&CK technique T1059 Command and Scripting Interpreter through JavaScript execution on Linux or Windows platforms depending on the hosting environment. It represents a classic case of incomplete validation where security controls are applied to specific data types while leaving related structures exposed. The flaw underscores the importance of comprehensive input sanitization across all code paths, particularly when dealing with dynamic compilation features that transform untrusted input into executable logic.
To mitigate this risk, organizations must immediately upgrade Handlebars to version 4.7.10 or later, where these validation gaps have been closed and strict type checking is enforced for all AST node properties regardless of their entry point in the compiler pipeline. For applications unable to update instantly due to dependency constraints, a temporary mitigation involves ensuring that only raw template strings are passed to Handlebars.compile() and Handlebars.precompile(), thereby avoiding the vulnerable code path entirely. Additionally, implementing strict input validation on any data structures intended for AST construction can provide an additional layer of defense. Developers should also audit their use cases involving pre-compiled templates to ensure no untrusted data influences the structure or content of the AST objects before compilation occurs.