Recently, we have witnessed a surge in ReDoS (Regular Expression Denial of Service) issues, and the root cause behind these occurrences lies in the regex engine we employ for matching patterns. There is a library called re2, which serves as a wrapper for Google's re2 engine. This library resolves all regex patterns in linear time, albeit lacking support for backreferences and look-arounds.
Upon researching this matter, it becomes evident that prominent projects are grappling with this problem. Languages such as Rust and Go have successfully mitigated these issues long ago. Considering the impact of ReDoS on Node.js, particularly its tendency to stall the event loop, it seems prudent to integrate this functionality into the Node.js codebase.
For further insights into the severity of ReDoS vulnerabilities, you may refer to the following resources:
https://snyk.io/blog/redos-vulnerabilities-in-npm-spikes-by-143-and-xss-continues-to-grow/https://swtch.com/~rsc/regexp/regexp1.htmlTo solve this problem maybe we can implementing a regex algorithm that operates in linear time, such as the Thompson implementation detailed in this
link, is a worthwhile endeavor.
A had open the issues in Node Js issues page, take a look
https://github.com/nodejs/node/issues/51659Best regards,
Jardel Matias