Vulnerabilities in pkg:pypi/semver
PACKAGECVE-2026-140095 is a HIGH denial of service vulnerability (CWE-1333: Inefficient Regular Expression Complexity) affecting python-semver libraries in the PyPI ecosystem. The issue involves super-quadratic redos in _last_number via attacker-controlled version strings. Remediation is available by upgrading affected packages to version 3.1.3.
pkg:pypi/semver
Vulnerability advisories affecting package pkg:pypi/semver. Select an advisory below to view technical details or fixes.
| Advisory ID | CVE / NVD | Severity | Summary |
|---|---|---|---|
| GHSA-3qgw-g8j9-rcg4 | CVE-2026-140095 | HIGH | python-semver: Super-quadratic ReDoS in _LAST_NUMBER via attacker-controlled version strings |
CVE-2026-140095 at a Glance
How to Fix CVE-2026-140095
To remediate this vulnerability, upgrade all affected python-semver dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
pip install semver>=3.1.3
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
pip show semver
How to Check if You Are Affected
To determine whether your Python environment is affected by CVE-2026-140095, inspect your installed packages using pip:
pip show semver
Analyze the terminal output to locate any version of python-semver in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.1.3), your application is affected.
Note: The pip show semver command checks currently installed packages in your active Python environment.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-1333: Inefficient Regular Expression Complexity, where the product uses a regular expression with a worst-case computational complexity that is inefficient and possibly exponential. In python-semver, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2026-140095 Affected python-semver Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
semver
|
PyPI |
< 3.1.3
|
3.1.3
|
References
Frequently Asked Questions
What is CVE-2026-140095?
Which python-semver versions are affected?
What version fixes CVE-2026-140095?
Is semver affected?
What CWE is associated with CVE-2026-140095?
How can I check PyPI dependencies for CVE-2026-140095?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-3qgw-g8j9-rcg4",
"modified" : "2026-12-04T17:16:08Z",
"published" : "2026-12-01T19:08:01Z",
"aliases" : [ "CVE-2026-140095" ],
"summary" : "python-semver: Super-quadratic ReDoS in _LAST_NUMBER via attacker-controlled version strings",
"details" : "## Summary\n`python-semver/python-semver` is the Python Semantic Versioning library published on PyPI as `semver`. At `src/semver/version.py:95` it defines:\n\n```python\n_LAST_NUMBER = re.compile(r\"(?:[^\\d]*(\\d+)[^\\d]*)+\")\n```\n\nThe 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.\n\nThe 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.\n\nThe 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.\n\n## Affected version\n- Repository: `python-semver/python-semver`; package: `semver`.\n- Affected release: latest release tag `3.1.0`, with master HEAD `f3c7138120d7f49e190bd7c555c6e7eb155b482d`\n- Regex definition: `src/semver/version.py:95`.\n- 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).\n- Affected public entry point: `semver.Version.parse(version_string).bump_build()`, and any other public path that eventually calls `_increment_string`.\n\n## Reproduction and timing\nAll 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.\n\nIsolated `_LAST_NUMBER` search on a payload of `'a' * N` with no digits:\n\n```\nn=1000 len=1000 7.34 ms\nn=2000 len=2000 40.98 ms\nn=4000 len=4000 161.87 ms\nn=8000 len=8000 495.65 ms\nn=16000 len=16000 1932.34 ms\nn=32000 len=32000 16038.80 ms\n```\n\nEnd-to-end via the public API `Version.parse('1.0.0+' + 'a' * N).bump_build()` (first measurement series):\n\n```\nN=1000 8.1 ms\nN=2000 30.5 ms x3.8\nN=4000 124.7 ms x4.1\nN=8000 459.2 ms x3.7\nN=16000 2001 ms x4.4\nN=32000 15177 ms x7.6\n```\n\nA second end-to-end measurement series of the same call, recorded in the detailed evidence, gives:\n\n```\nN=1000 7.31 ms\nN=2000 29.48 ms\nN=4000 120.50 ms\nN=8000 517.93 ms\nN=16000 2091.86 ms\nN=32000 15655.43 ms\n```\n\nThe 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\n```\nn=1000 len=2000 0.68 ms\nn=4000 len=8000 2.08 ms\nn=16000 len=32000 11.46 ms\n```\n\n## Reachability\nNo 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, and the search cannot be aborted once it starts backtracking.\n\nIn practice the untrusted version string can arrive through a `requirements.txt` or lock file submitted for analysis, a tag or version number checked by a release pipeline, registry or SBOM metadata imported from a third party, an update-check response, or a tenant-supplied policy in a multi-tenant service. In each case the caller typically parses first and only afterwards decides whether the version is acceptable, so an attacker does not need the string to survive validation: successful parsing with an expensive subsequent increment is enough.\n\n## Impact\nThe principal consequence is denial of service. A single call with a 32 KB all-letter build identifier consumes about 15 seconds of CPU in the parsing process; a small number of concurrent calls can occupy all available workers and make a service unresponsive. The trigger is a valid version string, so it passes ordinary validation, and the amplification ratio is severe: doubling the input roughly quadruples the cost, with a worse factor at the largest measured size. The affected code sits in a public parsing and increment API, so any downstream application that consumes untrusted version strings from manifests, registry metadata, CI inputs, or client submissions is exposed. This is rated High because the input threshold is low, the amplification is clearly measured, the path is public API, and no privileges are required; the impact is availability only, with no data disclosure or code execution, so it is not Critical.\n\nThe measured progression illustrates the risk: about 8 ms at 1000 characters, just over 2 seconds at 16000, and roughly 15 seconds at 32000. A service that accepts version strings over the network can therefore be pushed from negligible latency to a full CPU stall by a single modest payload, and the super-quadratic step at the largest size means the effect grows faster than the amount of data sent.\n\n## Suggested fix\n- Rewrite the pattern to remove ambiguity. The goal is simply to obtain the last run of digits, so use `re.compile(r'\\d+')` with `finditer` and keep the final match, use a bounded-backtracking form such as `(\\d+)(?!.*\\d)`, or perform a hand-written right-to-left scan. Preserve the existing `_increment_string` semantics for `match.group(1)` and `match.span(1)`.\n- Apply a reasonable length limit, for example 256 bytes, to the overall version string and to the build and prerelease components in `Version.parse` and `bump_build`, rejecting longer values outright.\n- Add timing or timeout regression tests for long all-non-digit build strings such as `'a' * N`, so a future reintroduction of the nested quantifier is caught.\n- Where a service exposes version parsing to external callers, add timeouts, rate limits, and input size checks on the calling side, and avoid unbounded increment operations on untrusted paths.\n- Add static regular-expression complexity scanning to CI and scan the rest of the library for unbounded quantifiers inside repeated groups.\n\nTaken together, rewriting the expression and bounding the input length remove both the computational flaw and the ability of an attacker to feed it an arbitrarily large value. The regression test should include the all-letter build identifier as well as other digit-free strings, since the vulnerable condition is the absence of a digit rather than the specific character used.\n\n## Disclosure\n\nReported by Jiawei Guo (GitHub: plailenceGrill).",
"severity" : [ {
"type" : "CVSS_V4",
"score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "PyPI",
"name" : "semver"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "3.1.3"
} ]
} ],
"database_specific" : {
"last_known_affected_version_range" : "<= 3.1.2"
}
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/python-semver/python-semver/security/advisories/GHSA-3qgw-g8j9-rcg4"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-140095"
}, {
"type" : "WEB",
"url" : "https://github.com/python-semver/python-semver/commit/fbf1e8f21c050256579de9199e53b6807e49014a"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/python-semver/python-semver"
}, {
"type" : "WEB",
"url" : "https://github.com/python-semver/python-semver/releases/tag/3.1.3"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-1333" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2026-12-01T19:08:01Z",
"nvd_published_at" : "2026-11-30T23:17:24Z"
}
}