CVE-2022-40896: Pygments Denial of Service Vulnerability

MODERATE
Advisory Identifier: GHSA-mrwq-x4v8-fh7p
CVSS 5.5
CWE-434
Published
Advisory Summary

CVE-2022-40896 is a MODERATE (CVSS 5.5) denial of service vulnerability (CWE-434: Unrestricted Upload of File with Dangerous Type) affecting Pygments libraries in the PyPI ecosystem. The issue involves pygments vulnerable to redos. Remediation is available by upgrading affected packages to version 2.15.0.

CVE-2022-40896 at a Glance

CVE Identifier CVE-2022-40896
GHSA Identifier GHSA-mrwq-x4v8-fh7p
Severity MODERATE
CVSS v3.1 Base Score 5.5
CWE Classification CWE-434: Unrestricted Upload of File with Dangerous Type
Affected Product Pygments
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 5.5

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

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

How to Fix CVE-2022-40896

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

Pygments fixed: 2.15.0
pip install Pygments>=2.15.0
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 Pygments

How to Check if You Are Affected

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

pip show Pygments

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

Note: The pip show Pygments command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-434: Unrestricted Upload of File with Dangerous Type, where the product allows the upload or transfer of dangerous file types that are automatically processed within its environment. In Pygments, 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

A ReDoS issue was discovered in `pygments/lexers/smithy.py` in Pygments until 2.15.0 via SmithyLexer.

CVE-2022-40896 Affected Pygments Versions

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

References

Frequently Asked Questions

What is CVE-2022-40896?
CVE-2022-40896 is a security vulnerability in Pygments involving Pygments vulnerable to ReDoS under CWE-434: Unrestricted Upload of File with Dangerous Type.
Which Pygments versions are affected?
Affected versions include releases prior to 2.15.0 across affected packages: Pygments.
What version fixes CVE-2022-40896?
Upgrading to 2.15.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is Pygments affected?
Yes, Pygments is affected in releases prior to 2.15.0. Upgrade your dependency to 2.15.0 or later.
What is the CVSS score of CVE-2022-40896?
CVE-2022-40896 has a CVSS v3.1 base score of 5.5 (MODERATE) with vector string CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H.
What CWE is associated with CVE-2022-40896?
CVE-2022-40896 is classified under CWE-434: Unrestricted Upload of File with Dangerous Type (The product allows the upload or transfer of dangerous file types that are automatically processed within its environment.).
How can I check PyPI dependencies for CVE-2022-40896?
Run the dependency tree command: 'pip show Pygments'. 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-mrwq-x4v8-fh7p",
  "modified" : "2024-10-24T21:49:45Z",
  "published" : "2023-07-19T15:30:26Z",
  "aliases" : [ "CVE-2022-40896" ],
  "summary" : "Pygments vulnerable to ReDoS",
  "details" : "A ReDoS issue was discovered in `pygments/lexers/smithy.py` in Pygments until 2.15.0 via SmithyLexer.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "Pygments"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.15.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-40896"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pygments/pygments/commit/97eb3d5ec7c1b3ea4fcf9dee30a2309cf92bd194"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pygments/pygments/commit/dd52102c38ebe78cd57748e09f38929fd283ad04"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pygments/pygments/commit/fdf182a7af85b1deeeb637ca970d31935e7c9d52"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/pygments/pygments"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pygments/pygments/blob/master/pygments/lexers/smithy.py#L61"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/pygments/PYSEC-2023-117.yaml"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/EZGMXALE3HSP4OXC7UUWIKX3OXKZDTY3"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/VUZO4BQCIY2S2KZYHERQMKURB7AHXDBO"
  }, {
    "type" : "WEB",
    "url" : "https://pypi.org/project/Pygments"
  }, {
    "type" : "WEB",
    "url" : "https://pyup.io/posts/pyup-discovers-redos-vulnerabilities-in-top-python-packages-part-2"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-434" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-07-20T11:00:04Z",
    "nvd_published_at" : "2023-07-19T15:15:10Z"
  }
}