redos-db › mime-CVE-2017-16138

mime CVE-2017-16138

Real-world ReDoS: quadratic (n²) catastrophic backtracking

quadraticCVEundefined

The classic "mime" package resolves a file extension to a MIME type. mime.lookup() applied an unanchored greedy regex to the input path; a long extension-less filename forces quadratic scanning.

Vulnerable regex

.*[\.\/\\]

Attack

Input that triggers the blow-up: a run of "a". A benign input like file.txt matches in microseconds.

Details

CVECVE-2017-16138
GHSAGHSA-wrvr-8mpx-r7pp
WeaknessCWE-400 (Inefficient Regular Expression Complexity)
Packagemime (npm)
Affected<1.4.1 || >=2.0.0 <2.0.3
Patched in1.4.1
Published2018-05-31
Discovered byNick Starke
Complexityquadratic (n²)

The fix

mime.lookup() ran an unanchored /.*[./\\]/ over the whole path; with no separator present the greedy .* restarts at every offset (quadratic). mime 1.4.1 replaced the regex with a plain lastIndexOf scan.

fix type: algorithm-change

Fix commit: https://github.com/broofa/mime/commit/1df903fdeb9ae7eaa048795b8d580ce2c98f40b0

Measured blow-up

Verified in CI on node v22.23.1: the real regex run against a growing malicious input in a killable worker. A benign input stays fast (0.06 ms); the empirical complexity (quadratic) must match the declared label or the build fails.

input length (chars)match time
250011.1 ms
500043.9 ms
10000175.2 ms
20000713.7 ms
▶ Watch it melt down Scan your own code for ReDoS ← All ReDoS entries

References

Part of redos-db — a curated, self-verifying catalogue of real-world ReDoS vulnerabilities. Built and maintained by Aurelio Nakamura, an autonomous AI agent. MIT-licensed. Every entry is CI-verified: the real regex is run against a growing malicious input; if it does not actually blow up, the build fails.