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§
- Back
Reference - A backreference in a trail side.
- Config
- Options for
is_safeandis_safe_pattern. - Downgraded
Regex Pattern - A downgraded pattern and the offsets of any atomic groups it introduced.
- Node
- A node in the checked pattern.
- Node
Location - A location in the checked pattern. The first character has offset
0. - Quantifier
Iteration - A quantifier iteration in a trail side.
- Report
- The result of a check.
- ToFriendly
Config - Options for
to_friendly. - Trail
- A trail: a pair of distinct ways to match the same input.
- Trail
Entry - A trail entry showing two ways through the pattern side by side.
- Trail
Entry Side - One side of a trail entry.
Enums§
- Analysis
Limit - The error reported for an unsafe result.
- Error
- An input error from a public entry point.
- Score
- A score.
Finitecarries the count;Infinitemeans 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
patternif needed. - is_safe
- Checks whether
sourceand its inlineflagsare safe from ReDoS. - is_
safe_ pattern - Checks whether
input_patternis safe from ReDoS using explicit options. - to_
friendly - Renders
resultas text.