CVE-2026-132276: wcmatch: Polynomial-time ReDoS when matching untrusted names against multi-star patterns (default flags)
Summary
With default flags, a pattern that contains several wildcards takes polynomial time, O(n^k) for k stars, to reject a crafted file name. The pattern is an ordinary developer constant such as .csv; only the string being matched comes from the attacker. A 255-byte file name (the maximum on common filesystems) takes 73 s with fnmatch.fnmatch() and 86 s with glob.globmatch(). The standard library's fnmatch handles the same input in under a millisecond.
This is different from GHSA-84v8-qmgq-9g88: that advisory covers extglob patterns, while this case needs no flags and no attacker-controlled pattern.
Details
Every is translated to a lazy .? (STAR, wcmatch/wcparse.py:212; PATHSTAR [^/]?, :218), which is emitted in handlestar (:1405-1424):
text .csv -> ^(?s:(?=.)(?![.]).?.?.?.?.?\.csv)$
When the subject consists of many and does not end in .csv, the regex engine tries every way of splitting it between the stars. CPython fixed the same problem in its own fnmatch (bpo-40480) by making every star segment except the last one atomic.
PoC
python import time, fnmatch as std from wcmatch import fnmatch, glob
for pat, n in [('.csv', 255), ('.csv', 400), ('.csv', 150), ('.csv', 200), ('.csv', 255)]: name = '' n t = time.perfcounter(); fnmatch.fnmatch(name, pat); w = time.perfcounter() - t t = time.perfcounter(); std.fnmatchcase(name, pat); s = time.perfcounter() - t print(f'{pat:15} len={n} wcmatch={w:.3f}s stdlib={s:.5f}s')
t = time.perfcounter(); glob.globmatch('uploads/' + '' 255, 'uploads/.csv') print(f'globmatch {time.perfcounter() - t:.2f}s')
wcmatch 11.1, CPython 3.13, macOS:
text .csv len=255 wcmatch=1.412s stdlib=0.00001s .csv len=400 wcmatch=8.599s stdlib=0.00004s .csv len=150 wcmatch=5.333s stdlib=0.00003s .csv len=200 wcmatch=22.415s stdlib=0.00007s .csv len=255 wcmatch=72.732s stdlib=0.00047s globmatch 85.75s
glob.glob('.csv', rootdir=d) on a real directory that contains one file named '' 255 takes 1.7 s.
Impact
Applications that match untrusted names against multi-star patterns can be blocked on a single CPU core for minutes per name. Examples: upload handlers, archive or object-store key filters, and glob/WcMatch scans of directories where other users can create files. No authentication is needed.
Fix
Emit every star segment except the last one as an atomic group, as the standard library does. On Python 3.11 and later use (?>.?); on 3.10 use the lookahead/backreference form from fnmatch.jointranslatedparts. For example:
text ^(?s:(?=.)(?![.])(?>.?)(?>.?)(?>.?)(?>.?).?\.csv)$
This rejects the 255-byte name in under 1 ms. On my spot-check inputs it gives the same results as the current regex. The same change applies to PATHSTAR.
Other sources
wcmatch is a Python library for wildcard file-name matching. Prior to 11.2, under the default flags, matching a non-matching attacker-controlled name against an application-supplied pattern containing several star wildcards separated by literals makes the lazy .? and [^/]? segments, including STAR and PATHSTAR emitted by handlestar() in wcmatch/wcparse.py, backtrack across possible splits, so a single comparison can consume prolonged CPU time. The pattern remains a developer-controlled constant and only the name is attacker-controlled; affected paths include fnmatch.fnmatch(), glob.globmatch(), and filesystem glob scans where another user can create names, without enabling extglob or any non-default flag. This issue is fixed in 11.2.
— MITRE
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/wcmatchto a version that resolves this vulnerability.Fixed in 11.2 - Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Fixed in 11.2