Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.
Sources: National Vulnerability Database, CISA KEV, Exploit-DB
CVE-2024-5278 Overview
CVE-2024-5278 affects gaizhenbiao/chuanhuchatgpt, an open-source ChatGPT web interface. The /upload endpoint lacks validation of file extensions and content types in the handle_file_upload function. Attackers can upload files with arbitrary extensions, including HTML files carrying cross-site scripting (XSS) payloads and Python files. The flaw is tracked as improper restriction of file types [CWE-434] and was present in the latest version as of 20240310. Successful exploitation can lead to stored XSS against application users and, under certain configurations, remote code execution on the hosting server.
Critical Impact
Unauthenticated attackers can upload malicious files through the /upload endpoint, enabling stored XSS and potential remote code execution on the server hosting ChuanhuChatGPT.
Affected Products
- gaizhenbiao/chuanhuchatgpt (version as of 20240310 and earlier)
- Deployments exposing the /upload endpoint to untrusted users
- Self-hosted ChuanhuChatGPT instances without upstream patch commit 22007a7
Discovery Timeline
- 2024-06-06 - CVE-2024-5278 published to the National Vulnerability Database (NVD)
- 2026-06-17 - Last updated in NVD database
Technical Details for CVE-2024-5278
Vulnerability Analysis
The vulnerability resides in the handle_file_upload function exposed through the /upload endpoint. The function accepts uploaded files without inspecting the extension, MIME type, or binary content. Because the application was intended to accept chat history JSON files, the original control relied on client-side file_types restrictions in the Gradio UploadButton. Client-side restrictions do not prevent an attacker from issuing a direct HTTP request to /upload with an arbitrary payload.
Once a file is written to a server-reachable path, HTML content can be served back to users, triggering stored XSS in the browser session of anyone retrieving it. Python files written to locations that are later imported or executed by the host process create a path to remote code execution.
Root Cause
The root cause is missing server-side validation of uploaded content [CWE-434]. The handle_file_upload handler trusts filenames and extensions supplied by the client and does not enforce an allowlist. There is also no check that uploaded JSON history files actually contain parseable JSON before persistence.
Attack Vector
Exploitation requires network access to the application and user interaction to trigger stored XSS payloads. An attacker sends a crafted multipart request to /upload referencing a .html, .py, or other sensitive extension. The server writes the file to disk under a predictable path. A victim visiting the resulting URL executes the attacker's script in the browser context of the application.
# Security patch in ChuanhuChatbot.py - restrict upload button to JSON and read as binary
# Before:
# uploadFileBtn = gr.UploadButton(
# interactive=True, label="", file_types=[".json"], elem_id="gr-history-upload-btn")
# After:
uploadHistoryBtn = gr.UploadButton(
interactive=True, label="", file_types=[".json"],
elem_id="gr-history-upload-btn", type="binary")
Source: GitHub Commit 22007a7
# Server-side validation added in modules/models/base_model.py
def upload_chat_history(self, new_history_file_content=None):
logging.debug(f"{self.user_name} loading chat history...")
if new_history_file_content is not None:
if isinstance(new_history_file_content, bytes):
try:
# Parse the content as JSON before persisting
json_content = json.loads(new_history_file_content.decode('utf-8'))
new_history_filename = new_auto_history_filename(self.user_name)
new_history_file_path = os.path.join(
HISTORY_DIR, self.user_name, new_history_filename)
os.makedirs(os.path.dirname(new_history_file_path), exist_ok=True)
with open(new_history_file_path, 'w', encoding='utf-8') as f:
json.dump(json_content, f, ensure_ascii=False, indent=2)
self.history_file_path = new_history_filename
except json.JSONDecodeError:
logging.error("Uploaded content is not valid JSON. Using default history.")
Source: GitHub Commit 22007a7
Stop Remote Code Execution Before It Runs
Singularity™ Endpoint detects and blocks exploit attempts at machine speed, including zero-days and novel attack techniques.
Stop Exploit AttemptsDetection Methods for CVE-2024-5278
Indicators of Compromise
- Files with executable or renderable extensions such as .html, .htm, .py, .php, or .svg written to the ChuanhuChatGPT upload or history directories.
- Access logs showing POST requests to /upload followed by GET requests retrieving non-JSON files.
- Unexpected JSON parse errors in application logs correlated with newly created files on disk.
Detection Strategies
- Inspect HTTP request bodies to /upload for Content-Type values other than application/json or filename extensions outside an approved allowlist.
- Review the ChuanhuChatGPT storage directory for files whose contents do not match their declared extensions, including JSON files containing HTML or script tags.
- Correlate authentication context, source IP, and user-agent for all upload activity against baseline chat usage patterns.
Monitoring Recommendations
- Enable file integrity monitoring on the chat history and upload directories used by ChuanhuChatGPT.
- Alert on process execution originating from the application working directory, especially python invocations on files created after deployment.
- Capture and retain web server access logs for /upload with full request metadata for forensic review.
How to Mitigate CVE-2024-5278
Immediate Actions Required
- Update ChuanhuChatGPT to a build that includes commit 22007a7 or later, which enforces binary JSON parsing of uploaded history files.
- Restrict network exposure of the /upload endpoint to authenticated, trusted users only, using a reverse proxy or application-layer authentication.
- Audit the chat history and upload directories for files created before the patch was applied and remove any that are not valid JSON.
Patch Information
The maintainer addressed the issue in commit 22007a77f037c0cf76180f9b73a8d19e87dad02e. The patch changes the Gradio UploadButton to read uploads as binary and adds a server-side upload_chat_history function that validates content with json.loads before writing to disk. Deployments should pull the latest main branch or a release containing this commit. See the GitHub Commit Reference and the Huntr Bounty Listing for additional detail.
Workarounds
- Place the application behind a reverse proxy that blocks requests to /upload with filenames ending in extensions other than .json.
- Serve the application's storage directory with a Content-Type: application/octet-stream and Content-Disposition: attachment header to prevent browsers from rendering uploaded HTML.
- Run the ChuanhuChatGPT process as an unprivileged user in a container with a read-only filesystem outside of the required history directory.
# Example nginx configuration limiting /upload to JSON content
location = /upload {
if ($http_content_type !~* "application/json|multipart/form-data") {
return 415;
}
client_max_body_size 2m;
proxy_pass http://chuanhuchatgpt_upstream;
}
location /history/ {
add_header Content-Type application/octet-stream always;
add_header Content-Disposition "attachment" always;
add_header X-Content-Type-Options nosniff always;
proxy_pass http://chuanhuchatgpt_upstream;
}
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.
Sources: National Vulnerability Database, CISA KEV, Exploit-DB

