Coordinated Disclosure Timeline
- 2023-08-09: Sent report to hello@mindsdb.com
- 2023-08-23: Sent a follow up email.
- 2023-09-11: Created an issue and sent the report to the email I received in response.
- 2023-09-28: Asked for an update.
- 2023-10-31: Sent a reminder about our disclosure policy deadline and asked for a CVE.
- 2023-11-17: Sent a reminder about the expired deadline (9 November 2023) and asked for publishing an advisory and a CVE.
- 2023-11-27: Sent a final reminder asking to publish an advisory.
- 2023-11-28: Received an answer that the issues are in the process of being fixed.
- 2023-12-11: Advisories for two of the issues are created and CVEs assigned. Sent an email inquiring about an advisory and CVE for the last vulnerability - GHSL-2023-183.
- 2023-12-15: The maintainer creates an advisory for GHSL-2023-183.
- 2023-12-18: GitHub Security Lab assigns a CVE to GHSL-2023-183.
Summary
Three vulnerabilities that can be exploited by unauthenticated users were found in MindsDB: a Server-side request forgery (SSRF) vulnerability, an arbitrary file write vulnerability and a limited file write vulnerability.
Product
mindsdb/mindsdb
Tested Version
Details
Issue 1: SSRF in file.py
(GHSL-2023-182
)
The put
method in mindsdb/mindsdb/api/http/namespaces/file.py does not validate the user-controlled URL in the source
variable and uses it to create arbitrary requests on line 115, which allows Server-side request forgery (SSRF).
with requests.get(url, stream=True) as r:
if r.status_code != 200:
return http_error(
400,
"Error getting file",
f"Got status code: {r.status_code}"
)
There is another potential instance of SSRF on line 96 affecting cloud-based deployments.
This issue was found using the SSRF CodeQL query for python.
Proof of Concept
- Create a new test folder with an example CSV file called
test.csv
. Start a simple python server in the folder withpython -m http.server 9090
This command will serve the example files container in the folder onhttp://127.0.0.1:9090
- Start MindsDB. We assume in this example that MindsDB in running on
http://127.0.0.1:47334/
- Send the following request to MindsDB:
curl -X PUT http://127.0.0.1:47334/api/files/foobar -H "Content-Type: application/json" -d '{"name":"foobar","source":"http://127.0.0.1:9090/test.csv","source_type":"url"}'
Impact
This issue may lead to Information Disclosure
.
The SSRF allows for forging arbitrary network requests from the MindsDB server. It can be used to scan nodes in internal networks for open ports that may not be accessible externally, as well as scan for existing files on the internal network. It allows for retrieving files with csv, xls, xlsx, json or parquet extensions, which will be viewable via MindsDB GUI. For any other existing files, it is a blind SSRF.
Resources
Issue 2: Arbitrary file write in file.py
(GHSL-2023-183
)
The same 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.
file_path = os.path.join(temp_dir_path, data['file'])
with open(file_path, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
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.
os.rmdir(temp_dir_path)
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, 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.
This issue was found using the Uncontrolled data used in path expression CodeQL query for python.
Impact
This issue may lead to arbitrary file write
. This vulnerability allows for writing files anywhere on the server that the filesystem permissions that the server is running with allow to.
Resources
-
Path injection leading to arbitrary file write on lines 122-125
-
Path injection leading to deleting zip and tar.gz files on the server on line 138
Proof of Concept
- Create a new test folder with a potentially dangerous file called
pwned.txt
. Start a simple python server in the folder withpython -m http.server 9090
. This command will serve the example files container in the folder onhttp://127.0.0.1:9090
- Start MindsDB. We assume in this example that MindsDB in running on
http://127.0.0.1:47334/
- Send the following request to MindsDB:
curl -X PUT http://127.0.0.1:47334/api/files/foo -H "Content-Type: application/json" -d '{"name":"../../../../../../mindsdb/file.txt","source":"http://127.0.0.1:9090/pwned.txt","source_type":"url"}'
You may need to modify the
original_file_name
value in case you are using another folder name for your MindsDB installation. - Go to the
mindsdb
folder on the server and check that file.txt file with contents of pwned.txt has been created.
Issue 3: Limited file write in file.py
(GHSL-2023-184
)
The same put
method in mindsdb/mindsdb/api/http/namespaces/file.py does not validate the user-controlled original_file_name
value, which is used in a path and afterwards moved in file_controller.py on lines 98-100, which leads to path injection.
source = file_dir.joinpath(file_name)
# NOTE may be delay between db record exists and file is really in folder
shutil.move(file_path, str(source))
Since the path injection happens after the file’s contents have been checked by the _handle_source
method in file_handler.py to be one of csv, xls, xlsx, json or parquet files, it is possible to create and overwrite files that are real csv, xls, xlsx, json or parquet files.
This issue was found using the Uncontrolled data used in path expression CodeQL query for python.
Impact
This issue may lead to limited file write
. It allows for creating and overwriting files, but only if they are real csv, xls, xlsx, json or parquet files.
Proof of Concept
- Create a new test folder with a potentially dangerous file called
file.csv
. Start a simple python server in the folder withpython -m http.server 9090
. This command will serve the example files container in the folder onhttp://127.0.0.1:9090
- Start MindsDB. We assume in this example that MindsDB in running on
http://127.0.0.1:47334/
- Send the below request to MindsDB
curl -X PUT http://127.0.0.1:47334/api/files/bar -H "Content-Type: application/json" -d '{"name":"bar","original_file_name":"../../../../../../../../../../../mindsdb/file.txt","source":"http://127.0.0.1:9090/file.csv","source_type":"url"}'
You may need to modify the
original_file_name
value in case you are using another folder name for your MindsDB installation. - Go to the
mindsdb
folder on the server and check that file.txt file with contents of file.csv has been created.
CVE
- GHSL-2023-182 has CVE-2023-49795
- GHSL-2023-183 has CVE-2023-50731
- GHSL-2023-184 has CVE-2023-49796
Credit
These issues were discovered and reported by GHSL team member @sylwia-budzynska (Sylwia Budzynska).
Contact
You can contact the GHSL team at securitylab@github.com
, please include a reference to GHSL-2023-182
, GHSL-2023-183
, or GHSL-2023-184
in any communication regarding these issues.