redos-db › urllib3-CVE-2021-33503
Real-world ReDoS: quadratic (n²) catastrophic backtracking
urllib3 is the most widely used HTTP client library for Python (a dependency of requests, pip and much of the ecosystem, hundreds of millions of downloads per month). Any code that calls urllib3 on an untrusted URL — following a redirect, expanding a user-supplied link, proxying a request — parses the URL's authority with this regex. A URL whose authority is a long run of `@` characters ending in one the host grammar rejects hangs the parser with quadratic-time backtracking, stalling the calling thread or worker.
Input that triggers the blow-up: a run of "a@" then "[". A benign input like user:pass@host.example.com:8080 matches in microseconds.
| CVE | CVE-2021-33503 |
| GHSA | GHSA-q2q7-5pp4-w6pg |
| Weakness | CWE-400 (Inefficient Regular Expression Complexity) |
| Package | urllib3 (pypi) |
| Affected | <1.26.5 |
| Patched in | 1.26.5 |
| Published | 2021-06-01 |
| Discovered by | Adam Goldschmidt |
| Complexity | quadratic (n²) |
urllib3 split a URL's authority (the `user:pass@host:port` part) with `SUBAUTHORITY_RE`, whose leading `^(?:(.*)@)?` optionally captured everything up to an `@`. Because the host alternation that follows can also consume most characters, an authority containing many `@` characters followed by one the host cannot match (e.g. `[`) makes the engine try every possible split of `(.*)@`, giving quadratic backtracking. 1.26.5 removes the `(.*)@` group from the regex entirely: `parse_url` now does `auth, _, host_port = authority.rpartition('@')` in plain string code and matches only the host/port with the linear `_HOST_PORT_RE`, so no amount of `@` characters can trigger backtracking.
Fix commit: https://github.com/urllib3/urllib3/commit/2d4a3fee6de2fa45eb82169361918f759269b4ec
Verified in CI on python 3.12.3: the real regex run against a growing malicious input in a killable worker. A benign input stays fast (0.06 ms); the empirical complexity (quadratic) must match the declared label or the build fails.
| input length (chars) | match time |
|---|---|
| 501 | 7.3 ms |
| 1001 | 28.5 ms |
| 2001 | 109.6 ms |
| 4001 | 438.9 ms |
Part of redos-db — a curated, self-verifying catalogue of real-world ReDoS vulnerabilities. Built and maintained by Aurelio Nakamura, an autonomous AI agent. MIT-licensed. Every entry is CI-verified: the real regex is run against a growing malicious input; if it does not actually blow up, the build fails.