CVE-2021-3828: Nltk Denial of Service Vulnerability

HIGH
Advisory Identifier: GHSA-2ww3-fxvq-293j
CVSS 7.5
CWE-1333 CWE-697
Published
Advisory Summary

CVE-2021-3828 is a HIGH (CVSS 7.5) denial of service vulnerability (CWE-1333: Inefficient Regular Expression Complexity) affecting Nltk libraries in the PyPI ecosystem. The issue involves nltk vulnerable to redos. Remediation is available by upgrading affected packages to version 3.6.4.

CVE-2021-3828 at a Glance

CVE Identifier CVE-2021-3828
GHSA Identifier GHSA-2ww3-fxvq-293j
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-1333: Inefficient Regular Expression Complexity
Affected Product Nltk
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity None (I:N)
Availability High (A:H)

How to Fix CVE-2021-3828

To remediate this vulnerability, upgrade all affected Nltk dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

nltk fixed: 3.6.4
pip install nltk>=3.6.4
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show nltk

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2021-3828, inspect your installed packages using pip:

pip show nltk

Analyze the terminal output to locate any version of Nltk in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.6.4), your application is affected.

Note: The pip show nltk 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 Nltk, 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

The nltk package is vulnerable to ReDoS (regular expression denial of service). An attacker that is able to provide as an input to the [`_read_comparison_block()`(https://github.com/nltk/nltk/blob/23f4b1c4b4006b0cb3ec278e801029557cec4e82/nltk/corpus/reader/comparative_sents.py#L259) function in the file `nltk/corpus/reader/comparative_sents.py` may cause an application to consume an excessive amount of CPU.

CVE-2021-3828 Affected Nltk Versions

1 component(s)
Fixed Versions:
3.6.4
Product / Package Ecosystem Affected Versions Fixed Version
nltk
PyPI
< 3.6.4
3.6.4

References

Frequently Asked Questions

What is CVE-2021-3828?
CVE-2021-3828 is a security vulnerability in Nltk involving NLTK Vulnerable to REDoS under CWE-1333: Inefficient Regular Expression Complexity.
Which Nltk versions are affected?
Affected versions include releases prior to 3.6.4 across affected packages: nltk.
What version fixes CVE-2021-3828?
Upgrading to 3.6.4 (or the latest patched release for your respective branch) resolves the vulnerability.
Is nltk affected?
Yes, nltk is affected in releases prior to 3.6.4. Upgrade your dependency to 3.6.4 or later.
What is the CVSS score of CVE-2021-3828?
CVE-2021-3828 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H.
What CWE is associated with CVE-2021-3828?
CVE-2021-3828 is classified under CWE-1333: Inefficient Regular Expression Complexity (The product uses a regular expression with a worst-case computational complexity that is inefficient and possibly exponential.).
How can I check PyPI dependencies for CVE-2021-3828?
Run the dependency tree command: 'pip show nltk'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-2ww3-fxvq-293j",
  "modified" : "2024-10-07T15:09:21Z",
  "published" : "2021-09-29T17:14:53Z",
  "aliases" : [ "CVE-2021-3828" ],
  "summary" : "NLTK Vulnerable to REDoS",
  "details" : "The nltk package is vulnerable to ReDoS (regular expression denial of service). An attacker that is able to provide as an input to the [`_read_comparison_block()`(https://github.com/nltk/nltk/blob/23f4b1c4b4006b0cb3ec278e801029557cec4e82/nltk/corpus/reader/comparative_sents.py#L259) function in the file `nltk/corpus/reader/comparative_sents.py` may cause an application to consume an excessive amount of CPU.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
  }, {
    "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" : "nltk"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.6.4"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-3828"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nltk/nltk/pull/2816"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nltk/nltk/commit/277711ab1dec729e626b27aab6fa35ea5efbd7e6"
  }, {
    "type" : "ADVISORY",
    "url" : "https://github.com/advisories/GHSA-2ww3-fxvq-293j"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/nltk/nltk"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/nltk/PYSEC-2021-356.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://huntr.dev/bounties/d19aed43-75bc-4a03-91a0-4d0bb516bc32"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-1333", "CWE-697" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-09-28T20:49:37Z",
    "nvd_published_at" : "2021-09-27T13:15:00Z"
  }
}