REDHAT-BUG-2452523: High severity Handlebars Handlebars vulnerability

Published Mar 27, 2026
·
Updated

Handlebars provides the power necessary to let users build semantic templates. In versions 4.0.0 through 4.7.8, Handlebars.compile() accepts a pre-parsed AST object in addition to a template string. The value field of a NumberLiteral AST node is emitted directly into the generated JavaScript without quoting or sanitization. An attacker who can supply a crafted AST to compile() can therefore inject and execute arbitrary JavaScript, leading to Remote Code Execution on the server. Version 4.7.9 fixes the issue. Some workarounds are available. Validate input type before calling Handlebars.compile(); ensure the argument is always a string, never a plain object or JSON-deserialized value. Use the Handlebars runtime-only build (handlebars/runtime) on the server if templates are pre-compiled at build time; compile() will be unavailable.

Affected Software

2 affected components
Handlebars Handlebars>=4.0.0<=4.7.8
Handlebars Handlebars=4.7.9

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade to a fixed release to a version that resolves this vulnerability.

    Fixed in 4.7.9
  2. Configuration

    If templates are pre-compiled at build time, use the Handlebars runtime-only build (`handlebars/runtime`) on the server so `compile()` is unavailable.

    Handlebars (server-side template compilation) Use runtime-only build handlebars/runtime vs full build = handlebars/runtime
  3. Configuration

    Before calling `Handlebars.compile()`, validate that the argument is always a `string` and ensure it is never a plain object or a JSON-deserialized value.

    Handlebars.compile() Input validation for compile() argument type = string only

Event History

Mar 27, 2026
Data Sourced
via Red Hat·10:03 PM
DescriptionSeverityAffected Software

Frequently Asked Questions

1

What applications are realistically exposed to this issue?

Applications using Handlebars versions 4.0.0 through 4.7.8 are exposed if untrusted input can reach Handlebars.compile() as a pre-parsed AST object rather than as a template string. The impact is server-side arbitrary JavaScript execution.

2

What must an attacker control to exploit it?

An attacker must be able to supply a crafted AST object to Handlebars.compile(). Supplying only ordinary template text is not the condition described for exploitation.

3

Are default template compilation patterns affected?

The vulnerable behavior occurs because compile() accepts an AST object in addition to a string. Code that ensures its compile() argument is always a string is not exposed through this AST injection path.

4

What can be done if upgrading is not immediately possible?

Validate the input type before calling Handlebars.compile() and reject plain objects or JSON-deserialized values, allowing only strings. If templates are precompiled during the build process, use the handlebars/runtime server-side build so compile() is unavailable.

5

Which version fixes the issue?

Handlebars version 4.7.9 fixes the issue.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203