CVE-2025-66645: Nicegui Path Traversal Vulnerability

HIGH
Advisory Identifier: GHSA-hxp3-63hc-5366
CVSS 7.5
CWE-22
Published
Advisory Summary

CVE-2025-66645 is a HIGH (CVSS 7.5) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Nicegui libraries in the PyPI ecosystem. The issue involves nicegui has a path traversal in app.add_media_files() allows arbitrary file read. Remediation is available by upgrading affected packages to version 3.4.0.

CVE-2025-66645 at a Glance

CVE Identifier CVE-2025-66645
GHSA Identifier GHSA-hxp3-63hc-5366
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Nicegui
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity None (I:N)
Availability None (A:N)

How to Fix CVE-2025-66645

To remediate this vulnerability, upgrade all affected Nicegui dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

nicegui fixed: 3.4.0
pip install nicegui>=3.4.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show nicegui

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2025-66645, inspect your installed packages using pip:

pip show nicegui

Analyze the terminal output to locate any version of Nicegui in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.4.0), your application is affected.

Note: The pip show nicegui command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In Nicegui, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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. ```python 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: 1. The `{filename:path}` parameter accepts full paths, including traversal sequences like `../`. 2. The code simply joins local_directory and filename without checking if the result is still inside the local_directory. 3. 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 1. Create `poc.py`: ```python # 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) ``` 2. Run the application: `python3 poc.py` 3. 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. <img width="1728" height="1078" alt="POC screenshot" src="https://github.com/user-attachments/assets/6c1be75b-6be2-4372-90df-55042c1e4775" /> ### 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.

CVE-2025-66645 Affected Nicegui Versions

1 component(s)
Fixed Versions:
3.4.0
Product / Package Ecosystem Affected Versions Fixed Version
nicegui
PyPI
< 3.4.0
3.4.0

References

Frequently Asked Questions

What is CVE-2025-66645?
CVE-2025-66645 is a security vulnerability in Nicegui involving NiceGUI has a path traversal in app.add_media_files() allows arbitrary file read under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Nicegui versions are affected?
Affected versions include releases prior to 3.4.0 across affected packages: nicegui.
What version fixes CVE-2025-66645?
Upgrading to 3.4.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is nicegui affected?
Yes, nicegui is affected in releases prior to 3.4.0. Upgrade your dependency to 3.4.0 or later.
What is the CVSS score of CVE-2025-66645?
CVE-2025-66645 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N.
What CWE is associated with CVE-2025-66645?
CVE-2025-66645 is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check PyPI dependencies for CVE-2025-66645?
Run the dependency tree command: 'pip show nicegui'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-hxp3-63hc-5366",
  "modified" : "2026-01-08T20:44:47Z",
  "published" : "2025-12-09T14:25:15Z",
  "aliases" : [ "CVE-2025-66645" ],
  "summary" : "NiceGUI has a path traversal in app.add_media_files() allows arbitrary file read",
  "details" : "### 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.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "nicegui"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.4.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/zauberzeug/nicegui/security/advisories/GHSA-hxp3-63hc-5366"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-66645"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/zauberzeug/nicegui/commit/a1b89e2a24e1911a40389ace2153a37f4eea92a9"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/zauberzeug/nicegui"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2025-12-09T14:25:15Z",
    "nvd_published_at" : "2025-12-09T22:16:15Z"
  }
}