CVE-2019-20922: Regular Expression Denial of Service in Handlebars

handlebars Updated 02 Oct 2025

Summary

10/02/2022
Yes i
High
7.5

CVE-2019-20922: Regular Expression Denial of Service in Handlebars. Affects handlebars versions >= 4.0.0, < 4.4.5. Fixed in 4.4.5. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Your last release was probably never penetration tested Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

Handlebars is a popular templating engine for JavaScript that allows developers to build dynamic HTML templates. It is widely used in web development frameworks and applications. The vulnerability identified as CVE-2019-20922 is a Regular Expression Denial of Service (ReDoS) issue in Handlebars. This vulnerability arises due to eager matching in the parser, which can lead to an endless loop when processing crafted templates. Exploiting this vulnerability can result in the exhaustion of system resources, potentially leading to a denial of service (DoS) condition.

Vulnerability Detail

The vulnerability in Handlebars arises from the eager matching behavior of the parser. When processing specially crafted templates, the parser can be forced into an infinite loop, consuming excessive CPU resources and causing a DoS condition. This vulnerability can be exploited by an attacker to exhaust system resources, impacting the availability of the affected application or system. The vulnerability has been assigned a CVSS score of 7.5, indicating a high severity level.

How To Fix

Latest published version: 4.7.10 as of 22 Oct 2026

npm install handlebars@4.7.10

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

4.4.5

This is the first release that contains the fix.

npm install handlebars@4.4.5

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

If upgrading to the latest version of Handlebars is not immediately feasible, developers can implement input validation and sanitization techniques to mitigate the risk of exploitation. By carefully validating and sanitizing user input before passing it to the handlebars.compile function, the likelihood of triggering the ReDoS vulnerability can be reduced. Here is an example of input validation and sanitization using a regular expression to ensure the input does not contain any malicious patterns:

const input = req.body.template;
const sanitizedInput = input.replace(/[\^$*+?.()|{}\[\]]/g, '\\$&');
const compiledTemplate = handlebars.compile(sanitizedInput);

This code snippet escapes any special characters that could potentially trigger the ReDoS vulnerability, making the input safe for compilation.

Conclusion

The Regular Expression Denial of Service vulnerability in Handlebars (CVE-2019-20922) can have severe consequences, including the exhaustion of system resources and potential denial of service. It is crucial for developers to upgrade to the latest version of Handlebars (4.4.5 or later) to mitigate this vulnerability. Implementing input validation and sanitization techniques can provide an additional layer of defense. For further support and assistance in vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for handlebars →

Share this vulnerability

FAQ

Handlebars is a popular templating engine for JavaScript that allows developers to build dynamic HTML templates. It provides a simple and intuitive syntax for embedding variables and logic into HTML markup.

Regular Expression Denial of Service (ReDoS) is a type of vulnerability that arises when a regular expression pattern is susceptible to excessive backtracking. This can lead to a denial of service condition by causing the application to consume excessive CPU resources or hang indefinitely.

The Handlebars ReDoS vulnerability can be exploited by an attacker to force the parser into an infinite loop, causing the application to consume excessive CPU resources and potentially leading to a denial of service condition. This can impact the availability of the affected application or system.

The CVSS score assigned to this vulnerability is 7.5, indicating a high severity level.

To mitigate the risk associated with this vulnerability, it is recommended to upgrade to Handlebars version 4.4.5 or later. Additionally, implementing input validation and sanitization techniques can help reduce the likelihood of exploitation.

Related vulnerabilities

Recent vulnerabilities recorded for handlebars.

How To Fix

Latest published version: 4.7.10 as of 22 Oct 2026

npm install handlebars@4.7.10

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

4.4.5

This is the first release that contains the fix.

npm install handlebars@4.4.5

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback