/

CVE-2026-106446

Severity:

CRITICAL RISK

(9.8)

Code Injection (CWE-94) in Handlebars AST Compiler Engine

CVE-2026-106446

Awaiting Analysis

Vulnerability type

Category:

Code Injection

CWE:

CWE-94, CWE-843

Impact:

Server-Side Code Execution

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A critical code injection vulnerability in Handlebars affects applications that pass attacker-controlled, pre-parsed AST objects to compile() or precompile(). Unchecked AST fields can be emitted into generated JavaScript, potentially allowing code execution in the server process when compiled output is rendered or loaded.

A critical code injection vulnerability in Handlebars affects applications that pass attacker-controlled, pre-parsed AST objects to compile() or precompile(). Unchecked AST fields can be emitted into generated JavaScript, potentially allowing code execution in the server process when compiled output is rendered or loaded.

Affected context

The issue may affect Handlebars applications that:

  • Accept or construct pre-parsed AST objects from untrusted or insufficiently trusted sources
  • Pass those objects to Handlebars.compile() or Handlebars.precompile()
  • Render the resulting compiled template or load the generated precompiled output

Applications that supply only ordinary template strings generally do not expose this specific attack path.

The issue may affect Handlebars applications that:

  • Accept or construct pre-parsed AST objects from untrusted or insufficiently trusted sources
  • Pass those objects to Handlebars.compile() or Handlebars.precompile()
  • Render the resulting compiled template or load the generated precompiled output

Applications that supply only ordinary template strings generally do not expose this specific attack path.

Exploit preconditions

  • Attack surface: Application code that accepts AST objects as template input
  • Required access: Ability to provide or influence a pre-parsed Handlebars AST
  • Trigger point: AST compilation, precompilation, rendering, or loading of generated output
  • Why exploitation is possible: Certain AST properties are insufficiently validated and can be incorporated into generated JavaScript as executable expressions
  • Attack surface: Application code that accepts AST objects as template input
  • Required access: Ability to provide or influence a pre-parsed Handlebars AST
  • Trigger point: AST compilation, precompilation, rendering, or loading of generated output
  • Why exploitation is possible: Certain AST properties are insufficiently validated and can be incorporated into generated JavaScript as executable expressions

Why this happens

The vulnerability results from incomplete validation of pre-parsed Handlebars AST objects. Although selected path, number, and boolean values are checked, other fields can retain attacker-controlled types or content and are later emitted into compiler-generated JavaScript.

This behavior maps to CWE-94: Improper Control of Generation of Code, because data supplied through an AST is treated as code-generation input without comprehensive validation. CWE-843: Access of Resource Using Incompatible Type is also relevant where values with unexpected types bypass assumptions made by the compiler.

The vulnerability results from incomplete validation of pre-parsed Handlebars AST objects. Although selected path, number, and boolean values are checked, other fields can retain attacker-controlled types or content and are later emitted into compiler-generated JavaScript.

This behavior maps to CWE-94: Improper Control of Generation of Code, because data supplied through an AST is treated as code-generation input without comprehensive validation. CWE-843: Access of Resource Using Incompatible Type is also relevant where values with unexpected types bypass assumptions made by the compiler.

Potential impact

  • Arbitrary JavaScript execution in the server process
  • Compromise of application confidentiality and integrity
  • Access to server-side secrets, files, or environment data
  • Potential lateral movement using the privileges of the affected process
  • Template or application supply-chain compromise
  • Arbitrary JavaScript execution in the server process
  • Compromise of application confidentiality and integrity
  • Access to server-side secrets, files, or environment data
  • Potential lateral movement using the privileges of the affected process
  • Template or application supply-chain compromise

General mitigation guidance

Mitigation generally focuses on reducing trust in AST inputs and preventing unvalidated values from reaching code-generation paths.

Common defensive patterns include:

  • Prefer accepting ordinary template strings over externally supplied AST objects
  • Reject AST inputs from untrusted or insufficiently trusted sources
  • Apply strict, recursive schema validation to every AST node, field, and value type
  • Use compiler interfaces that do not generate executable code from unchecked data
  • Separate template compilation from sensitive server-side privileges
  • Run rendering services with least-privilege identities and restricted filesystem and network access
  • Treat precompiled template artifacts as executable code and protect their integrity

Mitigation generally focuses on reducing trust in AST inputs and preventing unvalidated values from reaching code-generation paths.

Common defensive patterns include:

  • Prefer accepting ordinary template strings over externally supplied AST objects
  • Reject AST inputs from untrusted or insufficiently trusted sources
  • Apply strict, recursive schema validation to every AST node, field, and value type
  • Use compiler interfaces that do not generate executable code from unchecked data
  • Separate template compilation from sensitive server-side privileges
  • Run rendering services with least-privilege identities and restricted filesystem and network access
  • Treat precompiled template artifacts as executable code and protect their integrity

How teams detect issues like this

Organizations can identify similar risks through:

  • Static analysis rules for calls to compile() or precompile() with non-literal or externally derived objects
  • Code review checks for AST deserialization, transformation, or acceptance across trust boundaries
  • Schema-validation policies requiring recursive checks of AST node types and properties
  • Dependency and security testing that exercises unexpected AST value types
  • Runtime monitoring for unusual child processes, filesystem access, or network activity from template-rendering services

Automated code review and software composition analysis tools may help surface unsafe compiler-input flows.

Organizations can identify similar risks through:

  • Static analysis rules for calls to compile() or precompile() with non-literal or externally derived objects
  • Code review checks for AST deserialization, transformation, or acceptance across trust boundaries
  • Schema-validation policies requiring recursive checks of AST node types and properties
  • Dependency and security testing that exercises unexpected AST value types
  • Runtime monitoring for unusual child processes, filesystem access, or network activity from template-rendering services

Automated code review and software composition analysis tools may help surface unsafe compiler-input flows.

Sources

SourceLink
github.comgithub.com/handlebars-lang/handlebars.js/commit/703fdcc5fd6cc8d1cc0c33cc19de40c467c4b8d2
github.comgithub.com/handlebars-lang/handlebars.js/pull/2185
github.comgithub.com/handlebars-lang/handlebars.js/releases/tag/v4.7.10
github.comgithub.com/handlebars-lang/handlebars.js/security/advisories/GHSA-8r5x-fm3f-whwj

Frequently asked

questions

Generally, no. The described attack path depends on supplying a pre-parsed AST object rather than only a template string.

An attacker must be able to provide or influence an AST object that reaches Handlebars compilation or precompilation, directly or through an application-controlled transformation or storage layer.

Avoid accepting untrusted AST objects, and enforce complete recursive validation when AST processing is necessary. Values that can reach generated code should be constrained to expected types and formats.

Maintain strict trust boundaries around template compilation, review code-generation inputs, validate all structured fields rather than selected properties, and run rendering components with minimal privileges.

Generally, no. The described attack path depends on supplying a pre-parsed AST object rather than only a template string.

An attacker must be able to provide or influence an AST object that reaches Handlebars compilation or precompilation, directly or through an application-controlled transformation or storage layer.

Avoid accepting untrusted AST objects, and enforce complete recursive validation when AST processing is necessary. Values that can reach generated code should be constrained to expected types and formats.

Maintain strict trust boundaries around template compilation, review code-generation inputs, validate all structured fields rather than selected properties, and run rendering components with minimal privileges.

Find out what's already
exploitable in your codebase.