Impact
Handlebars, a templating engine widely used in web applications, has a flaw in versions 4.0.0 through 4.7.8. The library’s compile function accepts a pre‑parsed abstract syntax tree (AST) as well as a plain text template. In a NumberLiteral node the numeric value is inserted into the generated JavaScript output without quotations or any form of sanitization. An attacker who can supply a crafted AST to compile can therefore inject and execute arbitrary JavaScript when the template is rendered. This allows remote code execution on the server with the privileges of the process running Handlebars. The weakness is reflected in CWE‑843 (Incorrect Type Conversion) and CWE‑94 (Code Injection).
Affected Systems
The affected package is Handlebars.js, maintained by the handlebars‑lang project. All releases from 4.0.0 up to, but not including, 4.7.9 are vulnerable. The issue applies to environments that use the Node.js runtime, as indicated by the CPE string. Version 4.7.9 and later contain a fix that removes the ability to pass an AST directly to compile and properly sanitizes numeric values.
Risk and Exploitability
The vulnerability carries a CVSS score of 9.8, indicating critical severity. The EPSS score is listed as less than 1 %, suggesting that few attacks have been observed or expected. It is not currently included in the CISA KEV catalog. Exploitation requires an attacker to supply a malicious AST to the compile function, which may be feasible through application input that is passed directly to compile or via an API that accepts template data without validation. When successful, the attacker can run arbitrary JavaScript with the permission of the hosting process.
OpenCVE Enrichment
Github GHSA