Summary
A path traversal-style arbitrary file overwrite in text-generation-webui allows extension settings to be saved as .py files in the application root directory.
If abused, an attacker can overwrite Python modules such as download-model.py and later trigger their execution via the Model download functionality, leading to remote code execution.
Affected context
The vulnerability occurs in text-generation-webui deployments where:
- Extension settings can be saved in
.pyformat, and - The application allows writing those settings files into the app root directory (alongside core Python scripts), and
- Application logic can later import or execute those
.pyfiles as part of normal workflows (e.g., model download).
It is most relevant in multi-user or shared environments, or where untrusted users have access to the web UI to configure extensions and save settings.
Exploit preconditions
- Attack surface: Web interface of text-generation-webui, specifically the extension settings functionality.
- Required access: Ability to authenticate or otherwise gain UI access with permission to configure extensions and save their settings.
- Trigger point: Saving extension settings in
.pyformat to the application root and then invoking functionality (like the "Model" menu) that executes or imports the overwritten Python file (e.g.,download-model.py). - Why exploitation is possible: The application allows user-controlled paths/filenames for extension settings to be written into sensitive code directories without proper validation or directory restrictions, and later trusts those files as executable code.
Why this happens
This issue stems from insufficient validation and confinement of file paths when persisting extension settings.
By allowing users to save settings as .py files in the application root directory, the system effectively lets untrusted input control both the location and content of Python source files that are later executed.
This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, where the application fails to constrain file operations to a safe directory and does not enforce a clear separation between data files and executable code.
The insecure pattern is treating configuration-like data as arbitrary files in a shared code directory, enabling overwrite of security-sensitive modules that are loaded or run as part of normal application behavior.
Potential impact
- Arbitrary Python code execution when the overwritten script (such as
download-model.py) is triggered. - Full compromise of the text-generation-webui process, including access to any models, prompts, and data it handles.
- Lateral movement within the hosting environment, depending on the privileges of the application user.
- Installation of backdoors or persistence mechanisms within the application codebase.
- Data exfiltration or tampering with downloaded models and other artifacts.
General mitigation guidance
Effective mitigation focuses on strict separation of user-controlled content from executable code and robust path handling:
- Constrain all extension settings and user-generated files to a dedicated, non-executable data directory that is never imported as code.
- Normalize and validate file paths before writing, ensuring they cannot escape designated directories (reject absolute paths,
..segments, or unexpected extensions). - Treat configuration as data only: avoid allowing
.pyor other executable extensions for settings files; prefer structured formats like JSON, YAML, or TOML. - Enforce least-privilege file system permissions so that the web UI process cannot modify application source code directories.
- Apply secure-by-default file naming conventions that the user cannot override, such as auto-generated, fixed patterns scoped to each extension.
How teams detect issues like this
Organizations can detect and monitor for this class of vulnerability through:
- Static analysis rules and linters that flag file-write operations using user-controlled paths without normalization and directory checks.
- Code review guidelines that require a clear separation between configuration directories and executable code directories, with special scrutiny on any
.pyfile creation. - Runtime monitoring or file integrity checks (e.g., checksums, watchdogs) on core application scripts like
download-model.pyto detect unexpected modifications. - Logging and alerting for suspicious write operations to application root or code directories originating from web-facing request handlers.
- Periodic security scans for generic path traversal and arbitrary file write patterns in web UI components and extension systems.

