CVE-2023-50731
JSON

9.1critical

MindsDB has arbitrary file write in file.py

Severity
9.1critical CVSS:3.1 by GitHub_M
Exploit likelihood
0.98% (higher than 63% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-j8w6-2r9h-cxhjPYSEC-2023-279

Description

MindsDB is a SQL Server for artificial intelligence. Prior to version 23.11.4.1, the `put` method in `mindsdb/mindsdb/api/http/namespaces/file.py` does not validate the user-controlled name value, which is used in a temporary file name, which is afterwards opened for writing on lines 122-125, which leads to path injection. Later in the method, the temporary directory is deleted on line 151, but since we can write outside of the directory using the path injection vulnerability, the potentially dangerous file is not deleted. Arbitrary file contents can be written due to `f.write(chunk)` on line 125. Mindsdb does check later on line 149 in the `save_file` method in `file-controller.py` which calls the `_handle_source` method in `file_handler.py` if a file is of one of the types `csv`, `json`, `parquet`, `xls`, or `xlsx`. However, since the check happens after the file has already been written, the files will still exist (and will not be removed due to the path injection described earlier), just the `_handle_source` method will return an error. The same user-controlled source source is used also in another path injection sink on line 138. This leads to another path injection, which allows an attacker to delete any `zip` or `tar.gz` files on the server.

Affected

Product or packageVersionsReported by
mindsdb mindsdb< 23.11.4.1, before 23.11.4.1CVE List, NVD
mindsdb (PyPI)before 23.11.4.1GitHub Advisory Database, PyPA Advisory Database

All scores

GitHub_M9.1critical CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:H
GitHub9.1high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:H
GitHubhigh CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:H/VA:H/SC:N/SI:N/SA:N
NVD9.1critical CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:H
PyPA Advisory Database9.1critical CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:H

Classification

What each source says

CVE List

MindsDB is a SQL Server for artificial intelligence. Prior to version 23.11.4.1, the `put` method in `mindsdb/mindsdb/api/http/namespaces/file.py` does not validate the user-controlled name value, which is used in a temporary file name, which is afterwards opened for writing on lines 122-125, which leads to path injection. Later in the method, the temporary directory is deleted on line 151, but since we can write outside of the directory using the path injection vulnerability, the potentially dangerous file is not deleted. Arbitrary file contents can be written due to `f.write(chunk)` on line 125. Mindsdb does check later on line 149 in the `save_file` method in `file-controller.py` which calls the `_handle_source` method in `file_handler.py` if a file is of one of the types `csv`, `json`, `parquet`, `xls`, or `xlsx`. However, since the check happens after the file has already been written, the files will still exist (and will not be removed due to the path injection described earlier), just the `_handle_source` method will return an error. The same user-controlled source source is used also in another path injection sink on line 138. This leads to another path injection, which allows an attacker to delete any `zip` or `tar.gz` files on the server.

GitHub Advisory Database
Impact

Issue: Arbitrary file write in file.py (GHSL-2023-183)

Patches

Use mindsdb staging branch or v23.11.4.1

NVD (es)

MindsDB es un servidor SQL para inteligencia artificial. Antes de la versión 23.11.4.1, el método `put` en `mindsdb/mindsdb/api/http/namespaces/file.py` no valida el valor del nombre controlado por el usuario, que se usa en un nombre de archivo temporal, que se muestra posteriormente. abierto para escritura en las líneas 122-125, lo que conduce a inyección de ruta. Más adelante en el método, el directorio temporal se elimina en la línea 151, pero como podemos escribir fuera del directorio utilizando la vulnerabilidad de inyección de ruta, el archivo potencialmente peligroso no se elimina. Se pueden escribir contenidos de archivos arbitrarios debido a `f.write(chunk)` en la línea 125. Mindsdb verifica más adelante en la línea 149 en el método `save_file` en `file-controller.py` que llama al método `_handle_source` en ` file_handler.py` si un archivo es de uno de los tipos `csv`, `json`, `parquet`, `xls` o `xlsx`. Sin embargo, dado que la verificación se realiza después de que el archivo ya se haya escrito, los archivos seguirán existiendo (y no se eliminarán debido a la inyección de ruta descrito anteriormente), solo el método `_handle_source` devolverá un error. La misma fuente controlada por el usuario también se utiliza en otro receptor de inyección de ruta en la línea 138. Esto conduce a otra inyección de ruta, que permite a un atacante eliminar cualquier archivo `zip` o `tar.gz` en el servidor.

References

Sources

SourceRecordLicence
CVE ListCVE-2023-50731 changed 2024-08-02CVE Terms of Use
GitHub Advisory DatabaseGHSA-j8w6-2r9h-cxhj changed 2024-11-22CC-BY-4.0
NVDCVE-2023-50731 changed 2026-06-17Public domain
PyPA Advisory DatabasePYSEC-2023-279 changed 2024-11-21CC-BY-4.0