Handlebars.js remote code execution via template injection

Severity: info · Published 2019-07-15

Handlebars.js is a popular templating engine used to dynamically generate HTML and other content in web applications. A critical vulnerability allowed attackers to inject malicious template code that could execute arbitrary JavaScript on the server or client. This could lead to full system compromise if an attacker could control template input.

Technologies: handlebars (npm). Vendors: npm.

Quick answers

Is This vulnerability exploited in the wild?
No. Junglewise Threat Intelligence has no report of This vulnerability being exploited in the wild.
How severe is This vulnerability?
Informational severity, published 15 July 2019.
Which products and versions are affected?
handlebars (npm) SEMVER:introduced=0,fixed=4.1.0.
Is there a fix for This vulnerability?
Yes. handlebars (npm): upgrade to 4.1.0 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
How is This vulnerability attacked?
It is attacked over the network.
Am I affected?
Check whether you run handlebars (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

How to fix

  • handlebars (npm): upgrade to 4.1.0 or later
    npm install handlebars@4.1.0

Technical details

The vulnerability is a template injection flaw in Handlebars.js versions before 4.1.0, where attackers could access the "constructor" property in compiled templates to break out of the sandbox and execute arbitrary code. The root cause was insufficient input sanitization in template compilation, allowing access to non-enumerable properties via the constructor chain. An attacker must be able to inject or control template content passed to Handlebars.compile(). The fix, released in version 4.1.0, explicitly prohibits access to constructor properties in template evaluation, blocking the gadget chain used for code execution.

Affected products

  • Handlebars Handlebars.js before 4.1.0

Timeline

  • 2019-07-15: disclosed
  • 2019-07-15: patched: Fixed in version 4.1.0

References

This page as Markdown. Free to reuse under CC BY 4.0 with a link back.