CVE-2021-32837: Mechanize Denial of Service Vulnerability

HIGH
Advisory Identifier: GHSA-g3pv-pj5f-3hfq
CVSS 7.5
CWE-1333
Published
Advisory Summary

CVE-2021-32837 is a HIGH (CVSS 7.5) denial of service vulnerability (CWE-1333: Inefficient Regular Expression Complexity) affecting Mechanize libraries in the PyPI ecosystem. The issue involves mechanize regular expression denial of service vulnerability. Remediation is available by upgrading affected packages to version 0.4.6.

CVE-2021-32837 at a Glance

CVE Identifier CVE-2021-32837
GHSA Identifier GHSA-g3pv-pj5f-3hfq
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-1333: Inefficient Regular Expression Complexity
Affected Product Mechanize
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-32837

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

mechanize fixed: 0.4.6
pip install mechanize>=0.4.6
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 mechanize

How to Check if You Are Affected

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

pip show mechanize

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

Note: The pip show mechanize 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 Mechanize, 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

mechanize, a library for automatically interacting with HTTP web servers, contains a regular expression that is vulnerable to regular expression denial of service (ReDoS) prior to version 0.4.6. If a web server responds in a malicious way, then mechanize could crash. Version 0.4.6 has a patch for the issue.

CVE-2021-32837 Affected Mechanize Versions

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

References

Frequently Asked Questions

What is CVE-2021-32837?
CVE-2021-32837 is a security vulnerability in Mechanize involving mechanize Regular Expression Denial of Service vulnerability under CWE-1333: Inefficient Regular Expression Complexity.
Which Mechanize versions are affected?
Affected versions include releases prior to 0.4.6 across affected packages: mechanize.
What version fixes CVE-2021-32837?
Upgrading to 0.4.6 (or the latest patched release for your respective branch) resolves the vulnerability.
Is mechanize affected?
Yes, mechanize is affected in releases prior to 0.4.6. Upgrade your dependency to 0.4.6 or later.
What is the CVSS score of CVE-2021-32837?
CVE-2021-32837 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-32837?
CVE-2021-32837 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-32837?
Run the dependency tree command: 'pip show mechanize'. 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-g3pv-pj5f-3hfq",
  "modified" : "2025-12-22T16:31:05Z",
  "published" : "2023-01-18T00:30:18Z",
  "aliases" : [ "CVE-2021-32837" ],
  "summary" : "mechanize Regular Expression Denial of Service vulnerability",
  "details" : "mechanize, a library for automatically interacting with HTTP web servers, contains a regular expression that is vulnerable to regular expression denial of service (ReDoS) prior to version 0.4.6. If a web server responds in a malicious way, then mechanize could crash. Version 0.4.6 has a patch for the issue.",
  "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" : "mechanize"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.4.6"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-32837"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/python-mechanize/mechanize/commit/dd05334448e9f39814bab044d2eaa5ef69b410d6"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/mechanize/PYSEC-2023-25.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/python-mechanize/mechanize"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/python-mechanize/mechanize/blob/3acb1836f3fd8edc5a758a417dd46b53832ae3b5/mechanize/_urllib2_fork.py#L878-L879"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/python-mechanize/mechanize/releases/tag/v0.4.6"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2023/06/msg00022.html"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2025/12/msg00028.html"
  }, {
    "type" : "ADVISORY",
    "url" : "https://securitylab.github.com/advisories/GHSL-2021-108-python-mechanize-mechanize"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-1333" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-01-20T23:35:49Z",
    "nvd_published_at" : "2023-01-17T22:15:00Z"
  }
}