CVE-2019-20922: Regular Expression Denial of Service in Handlebars
Summary
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 ↓
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.
No signup required · Results in about 60 seconds
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 →
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.