Media

Arbitrary file write in mindsdb when Extracting Tarballs retrieved from a remote location

  • Publicada: 30.03.2023
  • Actualizado: 11.10.2026 11:20

Summary

An unsafe extraction is being performed using shutil.unpack_archive() from a remotely retrieved tarball. Which may lead to the writing of the extracted files to an unintended location. This vulnerability is sometimes called a TarSlip or a ZipSlip variant.

Details

Unpacking files using the high-level function shutil.unpack_archive() from a potentially malicious tarball without validating that the destination file path remained within the intended destination directory may cause files to be overwritten outside the destination directory.

As can be seen in the vulnerable snippet code source, an archive is being retrieved using the download_file() function from a remote location which is a user-provided permanent storage bucket s3. Immediately after being retrieved, the tarball is unsafely unpacked using the function shutil.unpack_archive().

The vulnerable code is L128..L129 in fs.py file.

python
    def __init__(self):
        super().__init__()
        if 's3_credentials' in self.config['permanent_storage']:
            self.s3 = boto3.client('s3', **self.config['permanent_storage']['s3_credentials'])
        else:
            self.s3 = boto3.client('s3')
       
        # User provided remote storage!
        self.bucket = self.config['permanent_storage']['bucket'] 

    def get(self, local_name, base_dir):
        remote_name = local_name
        remote_ziped_name = f'{remote_name}.tar.gz'
        local_ziped_name = f'{local_name}.tar.gz'
        local_ziped_path = os.path.join(base_dir, local_ziped_name)
        os.makedirs(base_dir, exist_ok=True)
        
        # Retrieve a potentially malicious tarball
        self.s3.download_file(self.bucket, remote_ziped_name, local_ziped_path)

        # Perform an unsafe extraction
        shutil.unpack_archive(local_ziped_path, base_dir)

        os.system(f'chmod -R 777 {base_dir}')
        os.remove(local_ziped_path)

PoC

The following PoC is provided for illustration purposes only. It showcases the risk of extracting a non-harmless text file sim4n6.txt to one of the parent locations rather than the intended current folder.

bash
> tar --list -f archive.tar
tar: Removing leading "../../../" from member names
../../../sim4n6.txt

> python3 
Python 3.10.6 (main, Nov  2 2022, 18:53:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import shutil
>>> shutil.unpack_archive("archive.tar")
>>> exit()

> test -f ../../../sim4n6.txt && echo "sim4n6.txt exists"
sim4n6.txt exists

Attack Scenario

An attacker could craft a malicious tarball with a filename path, such as ../../../../../../../../etc/passwd, and then serve the archive remotely using a personal bucket s3, thus, retrieve the tarball through mindsdb and overwrite the system files of the hosting server.

Mitigation

Potential mitigation could be to:

  • Use a safer module, like zipfile.
  • Validate the location of the extracted files and discard those with malicious paths such as relative path .. or absolute path such as /etc/password.
  • Perform a checksum verification for the retrieved archive, but hard-coding the hashes may be cumbersome and difficult to manage.

Software afectado

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

PlataformaPaqueteVersiones vulnerablesCorregida en
Python (PyPI) mindsdb < 22.11.4.3 22.11.4.3

Referencias

Puntuación CVSS 8.5/10
Vector CVSS
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:L/A:N
Debilidad (CWE)
CWE-22
Plataforma
Python (PyPI)
Paquete
mindsdb
Publicada
30.03.2023
Actualizado
11.10.2026 11:20

Fuentes y licencias

OSV / GitHub Advisory Database - PYSEC-2023-26 - PyPA Advisory Database; CC BY 4.0

OSV / GitHub Advisory Database - GHSA-7x45-phmr-9wqp - CC BY 4.0

Historial de vulnerabilidades: mindsdb

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.

Todas (22) en el archivo
Entradas en total
22
Primera → última
03.2023 05.2026
Sin corrección
7
Explotada en ataques
0

Distribución por gravedad

  • Crítica 1
  • Alta 16
  • Media 5

Divulgaciones por año

  1. 2023: 5
  2. 2024: 13
  3. 2025: 0
  4. 2026: 4
Gravedad:
  1. Alta · 8.8 CVE-2026-27483 < 25.9.1.1 25.9.1.1
  2. Alta · 8.8 CVE-2024-45847 >= 23.11.4.2, < 24.7.4.1 24.7.4.1
  3. Alta · 9.3 CVE-2024-24759 < 23.12.4.2 23.12.4.2
  4. Crítica · 9.1 CVE-2023-38699 < 23.7.4.0 23.7.4.0
  5. Arbitrary file write in mindsdb when Extracting Tarballs retrieved from a remote location esta entrada
    Media · 8.5 CVE-2022-23522 < 22.11.4.3 22.11.4.3

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.