Описание
NiceGUI has a path traversal in app.add_media_files() allows arbitrary file read
Summary
A directory traversal vulnerability in NiceGUI's App.add_media_files() allows a remote attacker to read arbitrary files on the server filesystem.
Details
Hello, I am Seungbin Yang, a university student studying cybersecurity. While reviewing the source code of the repository, I discovered a potential vulnerability and successfully verified it with a PoC.
The App.add_media_files(url_path, local_directory) method allows users to serve media files. However, the implementation lacks proper path validation.
Root Cause:
- The
{filename:path}parameter accepts full paths, including traversal sequences like../. - The code simply joins local_directory and filename without checking if the result is still inside the local_directory.
- There is no path sanitization or boundary check.
Consequence:
An attacker can use .. to access files outside the intended directory. If the application has permission, sensitive files (e.g., /etc/hosts, source code, config files) can be exposed.
POC
- Create
poc.py:
-
Run the application:
python3 poc.py -
Exploit with curl: Use URL-encoded dots (
%2e) to bypass client-side checks.curl -v "http://localhost:8080/media/%2e%2e/%2e%2e/%2e%2e/etc/hosts"
Result:
The HTTP status is 200 OK, and the response body contains the contents of the server’s /etc/hosts file.
I have attached a screenshot of the successful exploitation below. As shown in the image, the content of /etc/hosts displayed via cat matches the output received from the curl request perfectly.
Impact
Any NiceGUI application that calls app.add_media_files() on a URL path reachable by an attacker is affected. An unauthenticated remote attacker can read sensitive files outside the intended media directory, potentially exposing:
•Application source code and configuration files •Credentials, API keys, and secrets •Operating system configuration files (e.g., /etc/passwd, /etc/hosts)
This is my first github vulnerability report, so I would appreciate your understanding regarding any potential shortcomings. If you require any further information or clarification, please feel free to contact me at y4rvin@naver.com.
Thank you.
Пакеты
nicegui
< 3.4.0
3.4.0
Связанные уязвимости
NiceGUI is a Python-based UI framework. Versions 3.3.1 and below are vulnerable to directory traversal through the App.add_media_files() function, which allows a remote attacker to read arbitrary files on the server filesystem. This issue is fixed in version 3.4.0.