Description
Handlebars provides the power necessary to let users build semantic templates. In versions 4.0.0 through 4.7.8, 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. Version 4.7.9 fixes the issue. Some workarounds are available. First, use the runtime-only build (`require('handlebars/runtime')`). Without `compile()`, the fallback compilation path in `invokePartial` is unreachable. Second, sanitize context data before rendering: Ensure no value in the context is a non-primitive object that could be passed to a dynamic partial. Third, avoid dynamic partial lookups (`{{> (lookup ...)}}`) when context data is user-controlled.
Published: 2026-03-27
Score: 8.1 High
EPSS: < 1% Very Low
KEV: No
Impact: Remote Code Execution
Action: Immediate Patch
AI Analysis

Impact

The flaw in Handlebars.js versions 4.0.0 through 4.7.8 is a type confusion that allows a crafted object in the template context to be interpreted as a Handlebars abstract syntax tree. The runtime then compiles and executes the injected JavaScript code, giving the attacker arbitrary command execution on the server. This vulnerability is a classic example of CWE‑843 (Type Confusion) combined with CWE‑94 (Code Injection). The primary impact is that an attacker controlling template data can run arbitrary code with the privileges of the Node.js process that renders the template.

Affected Systems

The vulnerability affects the Handlebars.js library released by handlebars‑lang for Node.js. All releases from 4.0.0 up to and including 4.7.8 are vulnerable. The issue was fixed in version 4.7.9 and later. Applications that embed user‑controlled data into templates or use dynamic partial syntax such as {{> (lookup …)}} are at risk.

Risk and Exploitability

The CVSS base score of 8.1 indicates a high severity, while the EPSS score of less than 1% suggests that exploitation is currently unlikely. An attacker who can influence a value returned by a dynamic partial lookup can trigger the malicious compilation path, resulting in remote code execution with the same privileges as the running server. The vulnerability is not listed in the CISA Known Exploited Vulnerabilities catalog, but its ability to execute arbitrary code makes it a serious threat if exploited.

Generated by OpenCVE AI on March 31, 2026 at 20:36 UTC.

Remediation

No vendor fix or workaround currently provided.

OpenCVE Recommended Actions

  • Upgrade Handlebars.js to version 4.7.9 or later
  • If an upgrade is not immediately possible, load the runtime‑only build with require('handlebars/runtime') to disable the fallback compilation path
  • Sanitize all context values to ensure no non‑primitive objects can be passed to a dynamic partial
  • Avoid using dynamic partial syntax such as '{{> (lookup …)}}' when the data originates from user input

Generated by OpenCVE AI on March 31, 2026 at 20:36 UTC.

Tracking

Sign in to view the affected projects.

Advisories
Source ID Title
Github GHSA Github GHSA GHSA-xhpv-hc6g-r9c6 Handlebars.js has JavaScript Injection via AST Type Confusion when passing an object as dynamic partial
History

Tue, 31 Mar 2026 18:00:00 +0000

Type Values Removed Values Added
CPEs cpe:2.3:a:handlebarsjs:handlebars:*:*:*:*:*:node.js:*:*

Mon, 30 Mar 2026 16:15:00 +0000

Type Values Removed Values Added
Metrics ssvc

{'options': {'Automatable': 'no', 'Exploitation': 'poc', 'Technical Impact': 'total'}, 'version': '2.0.3'}


Mon, 30 Mar 2026 08:15:00 +0000

Type Values Removed Values Added
First Time appeared Handlebarsjs
Handlebarsjs handlebars
Vendors & Products Handlebarsjs
Handlebarsjs handlebars

Sat, 28 Mar 2026 12:15:00 +0000

Type Values Removed Values Added
References
Metrics threat_severity

None

threat_severity

Important


Sat, 28 Mar 2026 03:15:00 +0000

Type Values Removed Values Added
Description Handlebars provides the power necessary to let users build semantic templates. In versions 4.0.0 through 4.7.8, 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. Version 4.7.9 fixes the issue. Some workarounds are available. First, use the runtime-only build (`require('handlebars/runtime')`). Without `compile()`, the fallback compilation path in `invokePartial` is unreachable. Second, sanitize context data before rendering: Ensure no value in the context is a non-primitive object that could be passed to a dynamic partial. Third, avoid dynamic partial lookups (`{{> (lookup ...)}}`) when context data is user-controlled.
Title Handlebars.js has JavaScript Injection via AST Type Confusion when passing an object as dynamic partial
Weaknesses CWE-843
CWE-94
References
Metrics cvssV3_1

{'score': 8.1, 'vector': 'CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H'}


Subscriptions

Handlebarsjs Handlebars
cve-icon MITRE

Status: PUBLISHED

Assigner: GitHub_M

Published:

Updated: 2026-04-01T03:55:41.422Z

Reserved: 2026-03-24T19:50:52.103Z

Link: CVE-2026-33940

cve-icon Vulnrichment

Updated: 2026-03-30T15:40:34.677Z

cve-icon NVD

Status : Analyzed

Published: 2026-03-27T22:16:21.030

Modified: 2026-03-31T17:51:04.210

Link: CVE-2026-33940

cve-icon Redhat

Severity : Important

Publid Date: 2026-03-27T21:11:10Z

Links: CVE-2026-33940 - Bugzilla

cve-icon OpenCVE Enrichment

Updated: 2026-04-02T07:55:20Z

Weaknesses