How do you use untrusted input and regex DoS with a short example?

Regular expressions are powerful tools in Perl, but when processing untrusted input, they can also introduce vulnerabilities, leading to Regular Expression Denial of Service (ReDoS). Untrusted input can be input that comes from users, API responses, or external databases, which can be manipulated to exploit regex patterns.

Here’s a simple example demonstrating how an attacker might exploit a regex. In this case, a regex pattern that is vulnerable to catastrophic backtracking:


regex Perl DoS security untrusted input ReDoS