|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Security advisory for the regex crate (CVE-2022-24713)" |
| 4 | +author: The Rust Security Response WG |
| 5 | +--- |
| 6 | + |
| 7 | +> This is a cross-post of [the official security advisory][advisory]. The |
| 8 | +> official advisory contains a signed version with our PGP key, as well. |
| 9 | +
|
| 10 | +[advisory]: https://groups.google.com/g/rustlang-security-announcements/c/NcNNL1Jq7Yw |
| 11 | + |
| 12 | +The Rust Security Response WG was notified that the `regex` crate did not |
| 13 | +properly limit the complexity of the regular expressions (regex) it parses. An |
| 14 | +attacker could use this security issue to perform a denial of service, by |
| 15 | +sending a specially crafted regex to a service accepting untrusted regexes. No |
| 16 | +known vulnerability is present when parsing untrusted input with trusted |
| 17 | +regexes. |
| 18 | + |
| 19 | +This issue has been assigned CVE-2022-24713. The severity of this vulnerability |
| 20 | +is "high" when the `regex` crate is used to parse untrusted regexes. Other uses |
| 21 | +of the `regex` crate are not affected by this vulnerability. |
| 22 | + |
| 23 | +## Overview |
| 24 | + |
| 25 | +The `regex` crate features built-in mitigations to prevent denial of service |
| 26 | +attacks caused by untrusted regexes, or untrusted input matched by trusted |
| 27 | +regexes. Those (tunable) mitigations already provide sane defaults to prevent |
| 28 | +attacks. This guarantee is documented and it's considered part of the crate's |
| 29 | +API. |
| 30 | + |
| 31 | +Unfortunately a bug was discovered in the mitigations designed to prevent |
| 32 | +untrusted regexes to take an arbitrary amount of time during parsing, and it's |
| 33 | +possible to craft regexes that bypass such mitigations. This makes it possible |
| 34 | +to perform denial of service attacks by sending specially crafted regexes to |
| 35 | +services accepting user-controlled, untrusted regexes. |
| 36 | + |
| 37 | +## Affected versions |
| 38 | + |
| 39 | +All versions of the `regex` crate before or equal to 1.5.4 are affected by this |
| 40 | +issue. The fix is include starting from `regex` 1.5.5. |
| 41 | + |
| 42 | +## Mitigations |
| 43 | + |
| 44 | +We recommend everyone accepting user-controlled regexes to upgrade immediately |
| 45 | +to the latest version of the `regex` crate. |
| 46 | + |
| 47 | +Unfortunately there is no fixed set of problematic regexes, as there are |
| 48 | +practically infinite regexes that could be crafted to exploit this |
| 49 | +vulnerability. Because of this, we do not recommend denying known problematic |
| 50 | +regexes. |
| 51 | + |
| 52 | +## Acknowledgements |
| 53 | + |
| 54 | +We want to thank Addison Crump for responsibly disclosing this to us according |
| 55 | +to the [Rust security policy][1], and for helping review the fix. |
| 56 | + |
| 57 | +We also want to thank Andrew Gallant for developing the fix, and Pietro Albini |
| 58 | +for coordinating the disclosure and writing this advisory. |
| 59 | + |
| 60 | +[1]: https://www.rust-lang.org/policies/security |
0 commit comments