/

CVE-2026-25732

Severity:

HIGH RISK

(7.5)

Path Traversal in NiceGUI FileUpload.name

CVE-2026-25732

Analyzed

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Arbitrary File Write and Potential Remote Code Execution

Severity:

HIGH RISK

(7.5)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

NiceGUI's FileUpload.name property exposes client-supplied filenames without sanitization, which can lead to path traversal when application code directly concatenates this value into filesystem paths.

If a NiceGUI application follows the common pattern UPLOAD_DIR / file.name without validation, an attacker can craft filenames with ../ sequences to write files outside the intended upload directory, potentially overwriting application files and enabling remote code execution in certain deployment setups.

Affected context

The vulnerability affects NiceGUI-based applications that:

  • Use the FileUpload.name attribute directly when constructing filesystem paths, e.g., UPLOAD_DIR / file.name
  • Do not sanitize or normalize the filename before writing to disk
  • Run in environments where the application process has write permissions beyond the intended upload directory

Applications that ignore client-supplied filenames, generate their own safe names, or apply strict sanitization of filenames are generally not affected by this issue.

Exploit preconditions

  • Attack surface: HTTP(S) endpoints or UI routes that accept file uploads via NiceGUI's FileUpload component.
  • Required access: Ability to submit file uploads to the affected endpoint (often unauthenticated in public-facing applications).
  • Trigger point: Application file write operations that use expressions like UPLOAD_DIR / file.name or equivalent direct concatenation of FileUpload.name into paths.
  • Why exploitation is possible: The framework exposes FileUpload.name directly from client input without normalization or restriction, and many example/community patterns encourage its direct use when forming filesystem paths. When combined with permissive filesystem permissions, ../ segments in filenames can traverse out of the intended directory and land in arbitrary locations.

Why this happens

This is a design-level path traversal issue aligned with CWE-22: Improper Limitation of a Pathname to a Restricted Directory.

The framework exposes a filename property that is entirely controlled by the client and does not enforce:

  • Removal of directory traversal sequences (e.g., ../, ..\)
  • Restriction to a specific directory or path prefix
  • Normalization and validation against an allowed set of characters or patterns

Because the common and documented usage pattern is to construct paths as UPLOAD_DIR / file.name, developers may inadvertently trust this metadata as safe. In this pattern, the application implicitly treats user-controlled filenames as trustworthy components of filesystem paths, allowing crafted values to escape the intended directory boundary.

Potential impact

  • Writing files outside the intended upload directory
  • Overwriting existing application files, static assets, or configuration files
  • Planting executable scripts or code artifacts in web-accessible or runtime-loaded locations
  • Elevating impact to remote code execution in deployments where overwritten files are executed or interpreted by the application stack
  • Tampering with logs, data files, or other sensitive resources the application user can write to

General mitigation guidance

Effective mitigation focuses on decoupling filesystem paths from untrusted filenames and strictly constraining where uploaded files can be written. Common defensive patterns include:

  • Generating server-side filenames:
  • Use randomly generated identifiers, UUIDs, or monotonically increasing counters instead of client-supplied names.
  • Store the original client filename only as metadata in a database or separate mapping, not as part of the filesystem path.
  • Enforcing strict path constraints:
  • Resolve the target path and verify that it remains within the designated upload directory after normalization.
  • Reject or rewrite filenames that contain directory separators, traversal sequences, or non-printable characters.
  • Applying robust input validation:
  • Allow only a restricted character set (e.g., alphanumerics plus a small whitelist of safe symbols).
  • Limit filename length and strip or replace suspicious patterns such as ../, ..\, ~/, or absolute path prefixes.
  • Hardening filesystem permissions:
  • Run the application with a dedicated OS user restricted to a narrow directory tree.
  • Ensure the upload directory is isolated and does not overlap with code, configuration, or template directories.

These measures reduce the risk even when client-supplied filenames are exposed by the framework.

How teams detect issues like this

Detection typically combines code-level inspection with configuration review:

  • Static analysis and linting:
  • Search for direct uses of file.name, FileUpload.name, or equivalent properties in path-building expressions.
  • Flag patterns where user-controlled filename data is concatenated or interpolated into filesystem paths.
  • Use custom rules in SAST tools to detect ../-prone path construction and missing normalization/validation steps.
  • Code review practices:
  • Review all file upload handlers to verify that filenames are generated server-side or sanitized.
  • Examine helper utilities and shared modules that create upload paths for misuse of user-supplied metadata.
  • Runtime and policy enforcement:
  • Monitor application logs for suspicious filenames containing traversal characters or patterns.
  • Use filesystem monitoring to detect writes outside intended upload directories by the application process.

Automated code review tools can be configured to flag insecure path-building patterns around file uploads in NiceGUI projects.

Sources

SourceLink
github.comgithub.com/zauberzeug/nicegui/blob/main/nicegui/elements/upload_files.py#L110-L115
github.comgithub.com/zauberzeug/nicegui/blob/main/nicegui/elements/upload_files.py#L79-L82
github.comgithub.com/zauberzeug/nicegui/security/advisories/GHSA-9ffm-fxg3-xrhh

Frequently asked

questions

Yes. In typical NiceGUI deployments where file upload endpoints are exposed over the network, attackers can remotely submit crafted filenames in uploads to attempt path traversal, provided the application code uses FileUpload.name directly in filesystem paths.

The attacker generally needs the ability to invoke the file upload functionality. If the upload endpoint is public and unauthenticated, no prior authentication is required. If uploads are restricted, the attacker must hold whatever role or credentials are needed to perform a file upload.

The most robust pattern is to ignore client-supplied filenames when constructing filesystem paths: generate a safe, server-side filename (e.g., a UUID) in a fixed upload directory and store the original filename only as non-path metadata. If the original filename must influence the stored name, apply strict sanitization and normalization and verify the final path stays within the expected directory.

Treat all path components derived from user input as untrusted. Establish coding guidelines that forbid direct use of client-supplied filenames in filesystem paths, enforce centralized utilities for safe path creation, and incorporate automated checks (static analysis, code review templates) that specifically look for unsanitized filename usage in file upload flows.

Find out what's already
exploitable in your codebase.