`rgb2hex` is vulnerable to ReDoS when parsing crafted invalid colors
The rgb2hex library uses a regular expression with nested quantifiers that can backtrack catastrophically when parsing a crafted, malformed colour string. An attacker who can supply such a string could make the parsing call hang and cause a denial of service.
- Triaged in 39 days
- Fixed in 2 months
- Disclosed after 22 months
I would like to report a ReDoS in rgb2hex.
It allows to cause Denial of Service by trying to parse a crafted color string.
Module
module name: rgb2hex
version: 0.1.0
npm page: https://www.npmjs.com/package/rgb2hex
Module Description
Parse any rgb or rgba string into a hex color. Lightweight library, no dependencies!
Module Stats
6 788 downloads in the last day 119 402 downloads in the last week 478 341 downloads in the last month
~5 740 092 estimated downloads per year
Vulnerability
Vulnerability Description
ReDoS.
- regex:
/(.*?)rgb(a)*\((\d+),(\d+),(\d+)(,[0-9]*\.*[0-9]+)*\)/ - evil string:
rgb(0,0,0,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, - file: https://github.com/christian-bromann/rgb2hex/blob/master/index.js#L25 (and other places with the same regex)
Steps To Reproduce:
var rgb2hex = require('rgb2hex');
const color = 'rgb(0,0,0,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,';
console.log(rgb2hex(color));
Supporting Material/References:
State all technical information about the stack where the vulnerability was found
- Arch Linux Current
- Node.js 9.5.0
- npm 5.6.0
Wrap up
- I contacted the maintainer to let him know: N
- I opened an issue in the related repository: N
Impact
Cause denial of service by parsing a crafted color string
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the regular expression uses overlapping, repeated groups that allow exponential backtracking on invalid input.
Impact
Parsing a crafted colour string could cause a denial of service by hanging the process.
What the attacker needed
Attacker can supply the colour string
How it was found
- Require the rgb2hex module in a Node.js script.
- Pass a crafted, malformed colour string to the parser.
- Observe that parsing the crafted string causes a denial of service.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A regular expression is a pattern used to match text. Some patterns can take an extremely long time on certain inputs because the matcher tries many combinations. Here a malformed colour string makes the library's pattern spin for a very long time, so the program using it can freeze.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.