ReDoS

Last reviewed:

ReDoS (Regular Expression Denial of Service) is a type of denial-of-service (DoS) attack that exploits the inefficiencies in the processing of regular expressions. Regular expressions are sequences of characters that define search patterns, commonly used for string matching within texts. In a ReDoS attack, an attacker crafts input data that causes the regular expression engine to consume excessive computational resources, potentially to service degradation or unavailability. As of October 2023, ReDoS remains a relevant threat, particularly in web applications and services that rely heavily on regular expressions for input validation or data parsing.

Overview

ReDoS, or Regular Expression Denial of Service, is a specialized form of denial-of-service attack targeting the processing of regular expressions. Regular expressions are powerful tools used in programming and scripting languages for pattern matching within strings. However, certain complex or poorly designed regular expressions can lead to excessive backtracking, where the engine repeatedly attempts to match the pattern against the input. This excessive backtracking can be exploited by attackers to cause significant delays in processing, to a denial of service.

ReDoS attacks are particularly concerning in environments where regular expressions are used for input validation, data parsing, or other critical operations. Web applications, in particular, are vulnerable to ReDoS attacks if they utilize regular expressions for processing user inputs without adequate safeguards. The impact of a successful ReDoS attack can range from degraded performance to complete service unavailability, depending on the severity of the attack and the robustness of the target system.

How it works

ReDoS attacks exploit the inherent inefficiencies in the processing of certain regular expressions. Regular expressions are processed by engines that attempt to match patterns against input strings. In cases where the regular expression is complex or poorly constructed, the engine may engage in excessive backtracking. Backtracking occurs when the engine attempts multiple paths to find a match, which can be computationally expensive.

An attacker can craft input strings that maximize the backtracking efforts of the regular expression engine. This is typically achieved by creating input that causes the engine to explore numerous potential matches before ultimately failing. The excessive computational resources consumed during this process can lead to significant delays, effectively causing a denial of service.

For example, consider a regular expression designed to match a sequence of letters followed by numbers. If the expression is not carefully constructed, an attacker could provide an input string that causes the engine to attempt numerous combinations of matches, to excessive backtracking and resource consumption.

Applications

Regular expressions are widely used in various applications for tasks such as input validation, data parsing, and search operations. In web applications, regular expressions are commonly employed to validate user inputs, such as email addresses, phone numbers, and other forms of data entry. They are also used in search engines, text editors, and other software that requires pattern matching capabilities.

The versatility and power of regular expressions make them indispensable in many programming and scripting environments. However, this same power can be a double-edged sword, as improperly designed regular expressions can be vulnerable to ReDoS attacks. Developers must exercise caution when implementing regular expressions, ensuring that they are efficient and resistant to excessive backtracking.

Limitations

While ReDoS attacks can be highly effective in certain scenarios, they also have limitations. The success of a ReDoS attack largely depends on the complexity and inefficiency of the target regular expression. Well-designed regular expressions that minimize backtracking are less susceptible to ReDoS attacks.

Additionally, modern regular expression engines and libraries often include optimizations and safeguards to mitigate the risk of ReDoS attacks. These may include limiting the depth of backtracking, implementing timeouts for pattern matching operations, or using alternative algorithms that are less prone to excessive resource consumption.

Developers can further mitigate the risk of ReDoS attacks by conducting thorough testing and analysis of regular expressions, employing static analysis tools to identify potential vulnerabilities, and adhering to practices for regular expression design. By understanding the limitations and potential risks associated with regular expressions, developers can build more resilient applications that are less susceptible to ReDoS attacks.

ReDoS Attack Process

Evolution of ReDoS Awareness

See also

  • Denial of Service (DoS)
  • Input Validation
  • Pattern Matching

Sources

Categories: Vulnerabilities
Last updated: September 17, 2026