Skip to main content

Crate redos_detector

Crate redos_detector 

Source
Expand description

Static ReDoS analysis for ECMA-262 regular expressions.

This crate scores how vulnerable a regular expression is to ReDoS (regular-expression denial of service). It does not run the pattern. It enumerates the ways an input prefix could match and counts how many distinct paths can match the same prefix. More ambiguity means more backtracking, so a higher score. A score of 1 means every input matches at most one way. An infinite score means backtracking is unbounded.

Start with is_safe for a check that reads flags from the pattern string, or is_safe_pattern for a raw pattern with explicit options. to_friendly renders a result as text. downgrade_pattern rewrites unsupported patterns into supported ones.

Recoverable input problems return Error: an unsupported flag, a conflicting config, or a pattern that fails to parse. A successful check returns a Report. When the analysis hits a cap the report carries an AnalysisLimit in its error field, which is a different axis from input validation.

use redos_detector::{is_safe, Config};

let result = is_safe("(a+)+$", "", &Config::default()).unwrap();
assert!(!result.is_safe());

Structs§

BackReference
A backreference in a trail side.
Config
Options for is_safe and is_safe_pattern.
DowngradedRegexPattern
A downgraded pattern and the offsets of any atomic groups it introduced.
Node
A node in the checked pattern.
NodeLocation
A location in the checked pattern. The first character has offset 0.
QuantifierIteration
A quantifier iteration in a trail side.
Report
The result of a check.
ToFriendlyConfig
Options for to_friendly.
Trail
A trail: a pair of distinct ways to match the same input.
TrailEntry
A trail entry showing two ways through the pattern side by side.
TrailEntrySide
One side of a trail entry.

Enums§

AnalysisLimit
The error reported for an unsafe result.
Error
An input error from a public entry point.
Score
A score. Finite carries the count; Infinite means unbounded backtracking.

Constants§

DEFAULT_CASE_INSENSITIVE
Default case-insensitive mode.
DEFAULT_DOT_ALL
Default dot-all mode.
DEFAULT_MAX_SCORE
Default score cap.
DEFAULT_MAX_STEPS
Default step cap.
DEFAULT_MULTI_LINE
Default multi-line mode.
DEFAULT_UNICODE
Default unicode mode.
VERSION
The package version.

Functions§

downgrade_pattern
Downgrades pattern if needed.
is_safe
Checks whether source and its inline flags are safe from ReDoS.
is_safe_pattern
Checks whether input_pattern is safe from ReDoS using explicit options.
to_friendly
Renders result as text.