Maxim Mironjuk
-
January 26, 2025
A regular expression that matches short test inputs in milliseconds can suddenly take seconds or minutes on a only slightly longer, maliciously crafted input, because the PCRE engine tries exponentially many backtracking points. This phenomenon, known as catastrophic backtracking, is one of the most underestimated performance and security pitfalls in PHP applications that validate user input against regex patterns. This article shows how backtracking works mechanically, which pattern structures cause it to explode, and which concrete techniques systematically defuse the risk.