CVE-2026-140095: python-semver · Super-quadratic ReDoS in _LAST_NUMBER via attacker-controlled version strings
Affects semverSource GCVE Database
Not known to be exploited · CVSS 8.7 High : upgrade to 3.1.3 soon.
Data as of 1 Dec 2026, 20:00 UTC
Thin evidence
One scorer or none| CNA (GitHub_M) | CVSS 4.0 | 8.7 |
|---|
- Patch
- Available – fixed in 3.1.3
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:NExploitation evidence
Disclosed: evidence found.
CVE published 30 Nov 2026
Detectable: no evidence on record.
No public nuclei template indexed
Weaponized: no evidence on record.
No public exploit code indexed in Metasploit or Exploit-DB
Exploited in the wildExploited: no evidence on record.
Not in CISA KEV and no source reports exploitation
Observed by OffSeq MirageSeen by Mirage: no evidence on record.
No attack traffic recorded by OffSeq Mirage sensors
A missing step is not evidence of safety. Sources: cve.org (opens in a new tab), the Metasploit, Exploit-DB and nuclei-templates index as of 1 Dec 2026.
What to do
Upgrade semver to 3.1.3.
Affected software
| Product | Affected | Fixed in |
|---|---|---|
| PyPIsemver | Affected
| Fixed in
|
Check your own hosts for these packages with threat-finder (opens in a new tab), our free open-source scanner.
Description
## Summary `python-semver/python-semver` is the Python Semantic Versioning library published on PyPI as `semver`. At `src/semver/version.py:95` it defines: ```python _LAST_NUMBER = re.compile(r"(?:[^\d]*(\d+)[^\d]*)+") ``` The pattern is used by `bump_build()` to find and increment the last numeric component of a version string's build metadata. Its outer repeated group `(?:[^\d]*(\d+)[^\d]*)+` contains two unbounded `[^\d]*` quantifiers plus `\d+`, and adjacent repetitions can consume the same run of non-digit characters. When the build metadata is a long alphabetic string with no digits, the engine must try an enormous number of ways to divide that run among the quantifiers before the overall match fails, producing super-quadratic catastrophic backtracking, a CWE-1333 (Inefficient Regular Expression Complexity / ReDoS) condition. The vulnerability is reachable end to end through the public API `semver.Version.parse("1.0.0+" + "a" * N).bump_build()`: the library's `BUILD_IDENTIFIER` rule is `[0-9a-zA-Z-]+`, so an arbitrarily long all-letter build identifier parses successfully and is then passed to the vulnerable search. The untrusted input surface is any version string supplied by an external party: package manifests and dependency constraints, version validation in CI and release pipelines, registry metadata, SBOM imports, update-check services, and multi-tenant version-policy validation. A roughly 32 KB build identifier blocks the parsing process for about 15 seconds, and longer values reach minute scale. Python's regular-expression engine cannot be interrupted by a timeout during that work. The ambiguity inside `_LAST_NUMBER` is structural: the trailing `[^\d]*` of one iteration and the leading `[^\d]*` of the next iteration can consume the same characters, and there is no separator that forces a unique division. With no digit anywhere in the input, the engine keeps generating new candidate partitions for the outer `+`, each of which must then fail at the mandatory digits, until the search has explored a combinatorial number of possibilities. The control run with interleaved digits confirms that the presence of a matchable `\d` collapses the search to linear time. ## Affected version - Repository: `python-semver/python-semver`; package: `semver`. - Affected release: latest release tag `3.1.0`, with master HEAD `f3c7138120d7f49e190bd7c555c6e7eb155b482d`; the pattern is present in both and unfixed. - Regex definition: `src/semver/version.py:95`. - Trigger chain: `src/semver/version.py:424` (`bump_build()`) calls `src/semver/version.py:452` (`_increment_string(self._build)`), which calls `Version._LAST_NUMBER.search(string)` at `src/semver/version.py:324` inside `_increment_string` (lines 313-329). - Affected public entry point: `semver.Version.parse(version_string).bump_build()`, and any other public path that eventually calls `_increment_string`. ## Reproduction and timing All timings below were measured under CPython 3.12 with python-semver 3.1.0 in a controlled local environment. Isolated regex measurements are listed separately from the end-to-end public-API measurements. Isolated `_LAST_NUMBER` search on a payload of `'a' * N` with no digits: ``` n=1000 len=1000 7.34 ms n=2000 len=2000 40.98 ms n=4000 len=4000 161.87 ms n=8000 len=8000 495.65 ms n=16000 len=16000 1932.34 ms n=32000 len=32000 16038.80 ms ``` End-to-end via the public API `Version.parse('1.0.0+' + 'a' * N).bump_build()` (first measurement series): ``` N=1000 8.1 ms N=2000 30.5 ms x3.8 N=4000 124.7 ms x4.1 N=8000 459.2 ms x3.7 N=16000 2001 ms x4.4 N=32000 15177 ms x7.6 ``` A second end-to-end measurement series of the same call, recorded in the detailed evidence, gives: ``` N=1000 7.31 ms N=2000 29.48 ms N=4000 120.50 ms N=8000 517.93 ms N=16000 2091.86 ms N=32000 15655.43 ms ``` The roughly fourfold cost for each doubling up to 16000 characters, followed by a larger factor at 32000, is consistent with quadratic behaviour that becomes super-quadratic at larger sizes. A control run using a payload of `'a1' * N`, which does contain digits, stays linear and confirms that the blowup is specifically triggered by a long run with no `\d` match: ``` n=1000 len=2000 0.68 ms n=4000 len=8000 2.08 ms n=16000 len=32000 11.46 ms ``` ## Reachability No special configuration is needed. A caller passes a syntactically valid semantic version whose build component is a long run of letters; `Version.parse` accepts it because `BUILD_IDENTIFIER` is `[0-9a-zA-Z-]+` and imposes no length limit. Calling `bump_build()` then reads `self._build`, passes it to `_increment_string`, and reaches `_LAST_NUMBER.search`. Because the version string itself is attacker-controlled in many integration paths, an external party can choose both that it parses successfully and that the subsequent increment becomes arbitrarily expensive. There is no input length validation at the parse, build, or increment stages, a
References
- github.com/python-semver/python-semver/security/advisories/GHSA-3qgw-g8j9-rcg4 (opens in a new tab)
- nvd.nist.gov/vuln/detail/CVE-2026-140095 (opens in a new tab)
- github.com/python-semver/python-semver/commit/fbf1e8f21c050256579de9199e53b6807e49014a (opens in a new tab)
- github.com/python-semver/python-semver (opens in a new tab)
- github.com/python-semver/python-semver/releases/tag/3.1.3 (opens in a new tab)