Описание
NiceGUI's Path Traversal via Unsanitized FileUpload.name Enables Arbitrary File Write
Summary
NiceGUI's FileUpload.name property exposes client-supplied filename metadata without sanitization, enabling path traversal when developers use the pattern UPLOAD_DIR / file.name. Malicious filenames containing ../ sequences allow attackers to write files outside intended directories, with potential for remote code execution through application file overwrites in vulnerable deployment patterns. This design creates a prevalent security footgun affecting applications following common community patterns.
Note: Exploitation requires application code incorporating file.name into filesystem paths without sanitization. Applications using fixed paths, generated filenames, or explicit sanitization are not affected.
Details
Vulnerable Component: nicegui/elements/upload_files.py (upload_files.py#L79-L82 and upload_files.py#L110-L115)
Affected Methods: SmallFileUpload.save()and LargeFileUpload.save()
Root Cause: The save() method performs no validation on the provided path parameter. It accepts:
- Relative paths with
../sequences - Absolute paths
- Any file system location writable by the process
When developers use e.file.name (controlled by the attacker) in constructing save paths, directory traversal occurs:
PoC
- Terminal 1 (App)
- Terminal 2 (Exploit)
- Restart the application to execute the injected code:
- Observe http://localhost:8080
Impact
Affected Applications: All NiceGUI applications using ui.upload() where developers save files with e.file.save() and include user-controlled filenames (e.g., e.file.name) in the path.
Attack Capabilities:
- Write files to any location writable by the application process
- Overwrite Python application files to achieve remote code execution upon restart
- Overwrite configuration files to alter application behavior
- Write SSH keys, systemd units, or cron jobs for persistent access
- Deny service by corrupting critical files
Exploitability: Trivially exploitable without authentication. Attackers simply upload a file with a malicious filename like ../../../app.py to escape the upload directory. The vulnerability is prevalent in production applications as developers naturally use e.file.name directly, following patterns shown in community examples.
Remediation
For Users
For Maintainers
Ссылки
- https://github.com/zauberzeug/nicegui/security/advisories/GHSA-9ffm-fxg3-xrhh
- https://nvd.nist.gov/vuln/detail/CVE-2026-25732
- https://github.com/zauberzeug/nicegui/blob/main/nicegui/elements/upload_files.py#L110-L115
- https://github.com/zauberzeug/nicegui/blob/main/nicegui/elements/upload_files.py#L79-L82
Пакеты
nicegui
<= 3.6.1
3.7.0