CVE-2016-4055: Regular Expression Denial of Service in moment
Summary
CVE-2016-4055: Regular Expression Denial of Service in moment. Affects moment versions < 2.11.2. Fixed in 2.11.2. How to fix ↓
Also tracked for
- node-moment · Debian:11
The same CVE-2016-4055 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
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
Moment is a popular JavaScript library used for parsing, manipulating, and displaying dates and times. It provides a simple and intuitive API for working with dates and times in various formats. However, versions of Moment prior to 2.11.2 are affected by a regular expression denial of service (ReDoS) vulnerability. This vulnerability can be triggered when arbitrary user input is passed into the moment.duration() function.
Vulnerability Detail
The regular expression denial of service vulnerability in Moment arises from the way it handles user input in the moment.duration() function. When a large input string is provided, the regular expression used for parsing the input can exhibit exponential time complexity, leading to a denial of service condition. An attacker could exploit this vulnerability by providing a specially crafted input string, causing the application to consume excessive CPU resources and potentially become unresponsive. The severity of this vulnerability is moderate, with a CVSS score of 6.5.
How To Fix
Latest published version: 2.31.0 as of 22 Oct 2026
npm install moment@2.31.0
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
2.11.2
This is the first release that contains the fix.
npm install moment@2.11.2
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If updating to the latest version of Moment is not immediately feasible, a possible workaround is to validate and sanitize user input before passing it to the moment.duration() function. By implementing input validation and limiting the length of the input string, the risk of triggering the vulnerability can be mitigated. Here is an example of how input validation can be performed in JavaScript:
function sanitizeInput(input) {
// Perform input validation and sanitization
// Limit the length of the input string
if (input.length > MAX_LENGTH) {
throw new Error('Input string is too long');
}
return input;
}
var userInput = '-1234567890';
var sanitizedInput = sanitizeInput(userInput);
moment.duration(sanitizedInput);
Conclusion
In conclusion, the Moment library prior to version 2.11.2 is vulnerable to a regular expression denial of service (ReDoS) issue. This vulnerability can be mitigated by updating to the latest version of the library or implementing input validation and sanitization. It is important to promptly address this vulnerability to ensure the security and stability of applications using Moment. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for moment →
FAQ
Moment is a JavaScript library used for parsing, manipulating, and displaying dates and times. It provides a simple and intuitive API for working with dates in various formats.
A regular expression denial of service (ReDoS) vulnerability occurs when a regular expression pattern takes a long time to match certain input strings, leading to a denial of service condition. This can be exploited by an attacker to consume excessive CPU resources and potentially render an application unresponsive.
The vulnerability in Moment can be exploited by providing a specially crafted input string to the moment.duration() function. When a large input string is passed, the regular expression used for parsing the input can exhibit exponential time complexity, causing the application to consume excessive CPU resources and potentially become unresponsive.
The severity of this vulnerability is moderate, with a CVSS score of 6.5. While it can lead to a denial of service condition, it does not allow for arbitrary code execution or unauthorized access to sensitive information.
To mitigate the risk of this vulnerability, it is recommended to update to version 2.11.2 or later of the Moment library. If immediate updating is not feasible, implementing input validation and sanitization can help mitigate the risk. Limiting the length of the input string and performing proper validation can reduce the likelihood of triggering the vulnerability.
Related vulnerabilities
Recent vulnerabilities recorded for moment.