Skip to content

[BUG] Stored XSS Vulnerability in the Dialog Configuration #7250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

geckosecurity
Copy link

Version: 0.17.2

Description

A stored cross-site scripting (XSS) vulnerability exists in the dialog configuration functionality. The application fails to properly sanitize user input in the prompt_config fields, particularly in the "Opening greeting" section under "Assistant Setting". When this unsanitized content is later rendered using a markdown component with the rehype-raw plugin, malicious HTML and JavaScript can execute in victims' browsers.

Source - Sink Analysis

The vulnerability exists in the following function call chain:

  1. Source: set_dialog() in /api/apps/dialog_app.py
  • Accepts user-provided prompt_config parameter without sanitization:
    prompt_config = req.get("prompt_config", default_prompt)
  1. Intermediate: DialogService.save() in /api/db/services/common_service.py
  • Stores unsanitized user input directly in the database:
    sample_obj = cls.model(**kwargs).save(force_insert=True)
  1. Intermediate: get_json_result() in /api/utils/api_utils.py
  • Returns unsanitized data in JSON response:
    response = {"code": code, "message": message, "data": data}
  1. Sink: HightLightMarkdown component in /web/src/components/highlight-markdown/index.tsx
  • Renders unsanitized content with rehype-raw plugin, allowing JavaScript execution:
    rehypePlugins={[rehypeRaw, rehypeKatex]}

Proof of Concept

  1. Log into RAGFlow application
  2. Navigate to Chat section and click "Create an Assistant" button
  3. Locate the "Opening greeting" field (prompt_config.prologue) and enter the following payload:
<iframe srcdoc="<script>alert('XSS Vulnerability in RAGFlow')</script>"></iframe>
  1. Start a new conversation and observe that a JavaScript alert popup appears with the text "XSS Vulnerability in RAGFlow"

Impact

This stored XSS vulnerability allows attackers to:

  • Execute arbitrary JavaScript in the context of other users' browsers.
  • Steal authentication tokens, session cookies, and other sensitive information.
  • Perform unauthorized actions on behalf of the victim.
  • Access sensitive data potentially including knowledge base content.

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Apr 23, 2025
@KevinHuSh KevinHuSh requested a review from cike8899 April 24, 2025 03:45
@geckosecurity
Copy link
Author

Hi @cike8899, are there any updates on the review of the vulnerability?

@asiroliu
Copy link
Contributor

@KevinHuSh @cike8899
LGTM

@geckosecurity
Thank you for your submission.

  • set Opening greeting
image
  • I reproduced the issue using the nightly build:
image
  • Testing with your latest code:
image

@cike8899
Copy link
Contributor

Because I need to render legal HTML, I use DOMPurify to filter the output string. Thank you for your contribution. Fix: Use DOMPurify to filter out dangerous HTML #7668 @geckosecurity

@KevinHuSh
Copy link
Collaborator

Appreciations!

@KevinHuSh KevinHuSh closed this May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working, pull request that fix bug. size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants