# Handlebars.js remote code execution via template injection

Source: https://junglewise.ai/threats/handlebars-js-remote-code-execution-via-template-injection-c5d2b812  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2019-07-15. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

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)](https://junglewise.ai/threats/technologies/npm-handlebars). Vendors: [npm](https://junglewise.ai/threats/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

  ```sh
  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

- [https://github.com/wycats/handlebars.js/issues/1267](https://github.com/wycats/handlebars.js/issues/1267)
- [https://github.com/wycats/handlebars.js/commit/edc6220d51139b32c28e51641fadad59a543ae57](https://github.com/wycats/handlebars.js/commit/edc6220d51139b32c28e51641fadad59a543ae57)

## Related threats

- [Handlebars AST validation bypass in compile and precompile](https://junglewise.ai/threats/cve-2026-106446-handlebars-provides-the-power-necessary-to-let-users-build)
- [Handlebars prototype pollution RCE via constructor bypass](https://junglewise.ai/threats/cve-2026-106445-handlebars-provides-the-power-necessary-to-let-users-build)
- [Handlebars precompile script injection in generated code](https://junglewise.ai/threats/cve-2026-106444-handlebars-provides-the-power-necessary-to-let-users-build)
- [Handlebars.js prototype method access control gap via missing __lookupSetter__](https://junglewise.ai/threats/handlebars-js-prototype-method-access-control-gap-via-missing-f97c2407)
- [Handlebars.js property access validation bypass in container.lookup](https://junglewise.ai/threats/handlebars-js-property-access-validation-bypass-in-container-lookup-25bcfec0)
