Fixed XSS in unescaped chat input #2196
Open
+6
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Version: Latest
An XSS exists in the conversation history feature of GPT Academic. This allows users to save chat conversations as HTML files, but fails to properly sanitize user input before storing it in these files. When these HTML files are later accessed through the application's
/file
endpoint, any malicious JavaScript embedded in the conversation executes in the victim's browser.The vulnerability occurs in the
write_chat_to_file()
function incrazy_functions/Conversation_To_File.py
, where user-controlled content from both questions and answers is directly interpolated into HTML templates without any sanitization or escaping. This creates a persistent XSS where an attacker can craft malicious inputs, save them as conversation files, and share the resulting URLs with victims.Source-Sink Analysis
Source: User-controlled input in the chat interface
chatbot
parameter ofwrite_chat_to_file()
Transformation: Unsanitized processing in
write_chat_to_file()
Storage: HTML file creation
File Access: The
/file
endpoint inshared_utils/fastapi_server.py
serves these HTML filesSink: Browser execution
Proof of Concept
XSS Payload 1:
XSS Payload 2:
onerror
attribute executes when the image fails to loadXSS Payload 3:
To demonstrate the potential for data theft, use a payload that makes a request to an external server:
Replace
YOUR-UNIQUE-ID
with a unique identifier from webhook.site or a similar service.Impact
An attacker can: