CVE-2025-66645: NiceGUI has a path traversal in app.add_media_files() allows arbitrary file read
Summary A directory traversal vulnerability in NiceGUI's App.addmediafiles() 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.
Published Dec 9, 2025 · Updated Dec 10, 2025
Affected packages
nicegui
- Ecosystem
- PyPI
- Affected
- < 3.4.0
- Fixed in
- 3.4.0
- Check
pip show nicegui
Advisory details
From the GitHub Advisory Database (CC BY 4.0).
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.
def add_media_files(self, url_path: str, local_directory: Union[str, Path]) -> None:
@self.get(url_path.rstrip('/') + '/{filename:path}')
def read_item(request: Request, filename: str, nicegui_chunk_size: int = 8192) -> Response:
filepath = Path(local_directory) / filename
if not filepath.is_file():
raise HTTPException(status_code=404, detail='Not Found')
return get_range_response(filepath, request, chunk_size=nicegui_chunk_size)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:
# poc.py
from pathlib import Path
from nicegui import app, ui
MEDIA_DIR = Path(__file__).parent / 'media'
MEDIA_DIR.mkdir(exist_ok=True)
# Expose local "media" directory at /media
app.add_media_files('/media', MEDIA_DIR)
@ui.page('/')
def index():
ui.label('NiceGUI media PoC')
ui.run(port=8080, reload=False)- Run the application:
python3 poc.py
- Exploit with curl: Use URL-encoded dots (
%2e) to bypass client-side checks.
### 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 [email protected].
Thank you.Credited to y4rvin, evnchn, falkoschindler.
References
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. No analysis has been written for this entry yet. Methodology
More PyPI vulnerabilities
All PyPI entriesCVE-2026-45553
NiceGUI: Local file disclosure via Docutils file insertion in ui.restructured_text()
high7.5May 18, 2026CVE-2026-45554
NiceGUI: Unauthenticated log-volume denial of service in dynamic resource routes
medium5.3May 18, 2026CVE-2026-39844
NiceGUI: Upload filename sanitization bypass via backslashes allows path traversal on Windows
medium5.9Apr 8, 2026CVE-2026-33332
NiceGUI's unvalidated chunk size parameter in media routes can cause memory exhaustion
medium5.3Mar 19, 2026CVE-2026-27156
NiceGUI vulnerable to XSS via Code Injection during client-side element function execution
medium6.1Feb 24, 2026CVE-2026-25516
NiceGUI's XSS vulnerability in ui.markdown() allows arbitrary JavaScript execution through unsanitized HTML content
medium6.1Feb 5, 2026
