Skip to content
DoS Disclosed report Intermediate

`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.

chalker Follow

Originally disclosed on HackerOne

Medium 6.5 View original
  • 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.

Steps To Reproduce:

JavaScript
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

The original report as published on HackerOne, by chalker. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

  1. Require the rgb2hex module in a Node.js script.
  2. Pass a crafted, malformed colour string to the parser.
  3. 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.

More by chalker

View all

36 more disclosed reports, best first.

More from Node.js third-party modules

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.