Skip to content
DoS Disclosed report Beginner

@nextcloud/logger NPM package brings vulnerable ansi-regex version

The Nextcloud password_policy package depends on an outdated version of the ansi-regex library that is vulnerable to regular expression denial of service. An attacker could supply a crafted string to cause excessive CPU usage and potentially make the service unavailable.

ro0t_elqayser Follow

Originally disclosed on HackerOne

  • Triaged in 21 hours
  • Fixed in 9 days
  • Disclosed after 39 days

Summary:

Affected versions of this package are vulnerable to Regular Expression Denial of Service (ReDoS) due to the sub-patterns [\#;?]* and (?:;[-a-zA-Z\d\/#&.:=?%@~_]).

Details:

Denial of Service (DoS) describes a family of attacks, all aimed at making a system inaccessible to its original and legitimate users. There are many types of DoS attacks, ranging from trying to clog the network pipes to the system by generating a large volume of traffic from many machines (a Distributed Denial of Service - DDoS - attack) to sending crafted requests that cause a system to crash or take a disproportional amount of time to process. The Regular expression Denial of Service (ReDoS) is a type of Denial of Service attack. Regular expressions are incredibly powerful, but they aren't very intuitive and can ultimately end up making it easy for attackers to take your site down.

Steps To Reproduce:

  1. First I download the code (https://github.com/nextcloud/password_policy) I usual cat files and See the technologies that the site use and its versions I Found that You use ansi-regex
  2. then I cat every file and find in package-lock.json has the version I have the versions of the ansi-regex with a lot of versions there some of some vulnerable and other update to the latest version and the vulnerable paths is
JSON
},
				"strip-ansi": {
					"version": "3.0.1",
					"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
					"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
					"requires": {
						"ansi-regex": "^2.0.0"
					}
				}

					"has-ansi": {
			"version": "2.0.0",
			"resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz",
			"integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=",
			"requires": {
				"ansi-regex": "^2.0.0"
			},

			"dependencies": {
				"ansi-regex": {
					"version": "2.1.1",
					"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
					"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8="
				}

				"node_modules/babel-code-frame/node_modules/ansi-regex": {
			"version": "2.1.1",
			"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
			"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
			"engines": {
				"node": ">=0.10.0"
			}
		},
		"node_modules/babel-code-frame/node_modules/strip-ansi": {
			"version": "3.0.1",
			"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
			"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
			"dependencies": {
				"ansi-regex": "^2.0.0"
			}
			"node_modules/has-ansi/node_modules/ansi-regex": {
			"version": "2.1.1",
			"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
			"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
			"engines": {
				"node": ">=0.10.0"
			}
		},
  1. then I found that every version of ansi-regex before 4.1.1 as you see in the code you use 2.11,2.0.0,3.0.1 and these versions are vulnerable to Regular Expression Denial of Service (ReDoS) as every policy that Denial of service attack is out of scope so I didn't try anything to not make any damage to your work but I want to report it to you to investigate on that and update to the fixed version to denied this attack from happening.
  2. this is a poc that attacker can use to

#POC

import ansiRegex from 'ansi-regex';

for(var i = 1; i <= 50000; i++) { var time = Date.now(); var attack_str = "\u001B["+";".repeat(i*10000); ansiRegex().test(attack_str) var time_cost = Date.now() - time; console.log("attack_str.length: " + attack_str.length + ": " + time_cost+" ms") 

Fix:

update to these (4.1.1, 5.0.1, and 6.0.1) like you do in most of your code.

Supporting Materials:

this useful links that can you check on this vuln

  1. https://www.cve.org/CVERecord?id=CVE-2021-3807
  2. https://cwe.mitre.org/data/definitions/400.html
  3. https://security.snyk.io/vuln/SNYK-JS-ANSIREGEX-1583908

Impact

the attacker aimed at making a system inaccessible to its original and legitimate users. There are many types of DoS attacks, ranging from trying to clog the network pipes to the system by generating a large volume of traffic from many machines (a Distributed Denial of Service - DDoS - attack) to sending crafted requests that cause a system to crash or take a disproportional amount of time to process.

The original report as published on HackerOne, by ro0t_elqayser. 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 outdated ansi-regex library contains a regular expression with nested quantifiers that leads to catastrophic backtracking on certain inputs.

Impact

An attacker could cause a denial of service by making the system process a specially crafted string, potentially making it inaccessible to legitimate users.

What the attacker needed

Attacker can supply input to ansi-regex

The fix

Update ansi-regex to version 4.1.1, 5.0.1, or 6.0.1.

How it was found

  1. Download the password_policy code from GitHub.
  2. Inspect package-lock.json to find ansi-regex versions.
  3. Identify that versions 2.1.1 and 3.0.1 are used, which are before 4.1.1.
  4. Note that these versions are vulnerable to ReDoS.

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.

Regular expressions are patterns used to match text. Some patterns can be very slow when given specially crafted input, causing the program to freeze. This report shows that an old version of a text-processing library used by Nextcloud has such a slow pattern, so an attacker could send a string that makes the server hang.

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 ro0t_elqayser

View all

1 more disclosed report, best first.

More from Nextcloud

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.