Skip to content
DoS Disclosed report Advanced CVE-2022-24713

Regexes with large repetitions on empty sub-expressions take a very long time to parse

The regex crate's built-in mitigations against malicious regular expressions only limited memory usage, so a crafted regex repeating an empty sub-expression could bypass them. An attacker could send such a regex to a service that accepts untrusted regexes and cause a CPU-based denial of service.

addisoncrump Follow

Originally disclosed on HackerOne

Bounty$4,000 High 7.5 View original
  • Fixed in 22 hours
  • Paid in 22 hours
  • Disclosed after 25 hours

Summary by the program

Security advisory for the regex crate (CVE-2022-24713) Mar. 8, 2022 · The Rust Security Response WG

The Rust Security Response WG was notified that the regex crate did not properly limit the complexity of the regular expressions (regex) it parses. An attacker could use this security issue to perform a denial of service, by sending a specially crafted regex to a service accepting untrusted regexes. No known vulnerability is present when parsing untrusted input with trusted regexes.

This issue has been assigned CVE-2022-24713. The severity of this vulnerability is "high" when the regex crate is used to parse untrusted regexes. Other uses of the regex crate are not affected by this vulnerability.

Overview The regex crate features built-in mitigations to prevent denial of service attacks caused by untrusted regexes, or untrusted input matched by trusted regexes. Those (tunable) mitigations already provide sane defaults to prevent attacks. This guarantee is documented and it's considered part of the crate's API.

Unfortunately a bug was discovered in the mitigations designed to prevent untrusted regexes to take an arbitrary amount of time during parsing, and it's possible to craft regexes that bypass such mitigations. This makes it possible to perform denial of service attacks by sending specially crafted regexes to services accepting user-controlled, untrusted regexes.

Affected versions All versions of the regex crate before or equal to 1.5.4 are affected by this issue. The fix is included starting from regex 1.5.5.

Mitigations We recommend everyone accepting user-controlled regexes to upgrade immediately to the latest version of the regex crate.

Unfortunately there is no fixed set of problematic regexes, as there are practically infinite regexes that could be crafted to exploit this vulnerability. Because of this, we do not recommend denying known problematic regexes.

Acknowledgements We want to thank Addison Crump for responsibly disclosing this to us according to the Rust security policy, and for helping review the fix.

We also want to thank Andrew Gallant for developing the fix, and Pietro Albini for coordinating the disclosure and writing this advisory.

https://blog.rust-lang.org/2022/03/08/cve-2022-24713.html

The report

Rust's regex crate guarantees a linear time complexity with regex length for compilation of untrusted regexes. However, existing mitigations for known malicious regexes are based on memory usage and, as such, do not mitigate repetitions of empty sub-expressions. For example, the following payload triggers such an issue:

RE
(?:){4294967295}

This will cause the regex compiler to attempt to create 4294967295 instances of an empty sub-expression, which will ultimately allocate zero bytes and therefore bypass existing memory-based mitigations. This can be further weaponised to create an exponential time complexity with regex length by using repetitions of repetitions, e.g.:

RE
(?:){64}{64}{64}{64}{64}{64}

This payload would cause the regex compiler to attempt to create 64^6 instances of an empty sub-expression.

Impact

An attacker can induce a CPU time-based denial of service with effectively infinite CPU time, which would cause the service to become entirely unavailable.

The original report as published on HackerOne, by addisoncrump. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The denial-of-service mitigations were based on memory usage only, so repetitions of empty sub-expressions allocated nothing and slipped past them.

Impact

An attacker could cause a CPU time-based denial of service with effectively infinite CPU time, making the service entirely unavailable; only services that parse untrusted regexes are affected.

What the attacker needed

Service accepts untrusted regexes

The fix

The issue was fixed in regex 1.5.5, and everyone accepting user-controlled regexes was advised to upgrade immediately.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A regular expression is a pattern used to search or match text, and some programs let users supply their own patterns. The Rust regex library tried to stop dangerous patterns from taking too long, but it only checked how much memory a pattern would use. A pattern that repeats an empty piece of text uses no memory yet still makes the computer work enormously hard, so the service can be knocked offline.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by addisoncrump

View all

1 more disclosed report, best first.

More from Internet Bug Bounty

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.