Unauthenticated Path Traversal in text-generation-webui load_grammar()
Overview
The text-generation-webui application, a popular open-source interface for interacting with Large Language Models, contains a critical security flaw prior to version 4.3. Specifically, the `load_grammar()` function suffers from an unauthenticated path traversal vulnerability. This vulnerability arises because the underlying Gradio framework does not perform server-side validation on dropdown selections. An attacker can exploit this by crafting a malicious POST request to the application's API. By including directory traversal sequences, such as `../../../etc/passwd`, within the payload intended for a grammar file selection, an attacker can manipulate the file path. The `load_grammar()` function, lacking proper sanitization or validation of the provided path, will then attempt to read arbitrary files from the server's filesystem. This bypasses standard file access controls and allows an unauthenticated user to exfiltrate sensitive data from the server. The vulnerability is not restricted by file extensions, further increasing its impact.
Affected Systems
Testing Guide
* Ensure text-generation-webui is running. * Use a tool like `curl` or Postman to send a POST request to the `/api/v1/load_grammar` endpoint (or equivalent). * Craft a payload that attempts to read sensitive files, e.g., `{"grammar_file": "../../../../etc/passwd"}`. * Analyze the response for the contents of the attempted file. A successful exploit will return file data.
Mitigation Steps
* Upgrade text-generation-webui to version 4.3 or later. * Implement input validation on all API endpoints, specifically for file path parameters, to prevent directory traversal sequences. * Employ a Web Application Firewall (WAF) with rules to detect and block path traversal attempts. * Restrict the permissions of the user account running text-generation-webui to the minimum necessary for its operation.
Patch Details
4.3