Summary
An unauthenticated path traversal vulnerability in text-generation-webui before version 4.3 allows arbitrary file reads from the server filesystem via the load_grammar() functionality.
By abusing unvalidated dropdown values over the Gradio API, an attacker can submit directory traversal payloads (such as ../../../etc/passwd) and receive the full contents of targeted files in the server response.
Affected context
This vulnerability appears in deployments of text-generation-webui that expose the Gradio-based HTTP API or web interface to a network where untrusted users can send requests.
It specifically involves the grammar-loading feature, which accepts a file path from a dropdown or API parameter and then reads that file from disk.
Because the server does not constrain or sanitize these paths before use, a crafted value that navigates outside the intended grammar directory can access arbitrary readable files on the host system.
Exploit preconditions
- Attack surface: HTTP(S) endpoint provided by the Gradio interface or API.
- Required access: Network access to the text-generation-webui instance; no prior authentication required in the vulnerable configuration.
- Trigger point: Invocation of the grammar loading endpoint (e.g., load_grammar()) with a directory traversal payload in the file path parameter.
- Why exploitation is possible: The server trusts client-supplied dropdown values, lacks server-side normalization and path restriction, and directly uses them in file I/O calls without validating that the resolved path stays within an allowed directory.
Why this happens
The root cause is insufficient validation of file paths supplied by the client before performing filesystem operations, corresponding to CWE-22: Path Traversal.
The load_grammar() routine treats a user-controlled value (originating from a UI dropdown or direct API call) as a trusted file path and passes it directly to file reading logic.
Because the code does not enforce constraints such as base-directory whitelisting, canonical path checks, or rejection of traversal sequences like ../, an attacker can escape the intended grammar directory and read arbitrary files that the server process can access.
Potential impact
- An attacker may read sensitive configuration files (e.g., containing API keys, access tokens, or service credentials) available to the application user.
- An attacker could access system files such as
/etc/passwdthat facilitate reconnaissance and further attacks. - Application logs, prompt logs, or conversation histories could be exposed, leaking user data or model interactions.
- Environment-specific secrets or infrastructure metadata stored on disk may be disclosed, potentially enabling lateral movement or privilege escalation in the environment.
General mitigation guidance
Effective mitigation focuses on constraining file access and hardening how user-supplied paths are handled:
- Restrict grammar and similar resources to a fixed, server-side configured directory and reject any path that resolves outside this directory after normalization.
- Avoid trusting client-side UI elements (such as dropdowns) as a security control; always validate on the server.
- Use safe file selection mechanisms that map user-visible names or IDs to server-side whitelisted paths, instead of letting clients submit arbitrary filesystem paths.
- Run the application under a dedicated, least-privileged system account with minimal filesystem permissions, so that even if a path traversal occurs, the accessible data is limited.
- Consider isolating the application in a container or sandbox with a reduced view of the host filesystem, exposing only the files necessary for operation.
How teams detect issues like this
Detection can rely on both code-centric and operational approaches:
- Static analysis / code review: Look for file operations where request parameters or UI-controlled values are used directly in
open(), path joining, or similar APIs without normalization and base-directory checks. - Security review patterns: Flag endpoints or callbacks that allow users to select or upload files and verify they enforce strict allowlists or mapping layers rather than raw path usage.
- Runtime monitoring: Inspect HTTP logs for suspicious patterns such as
../sequences or absolute paths in parameters associated with grammar or file-loading endpoints. - Automated tooling: Incorporate SAST tools or linters configured with rules for CWE-22 to detect potentially unsafe path construction and file access.

