Skip to content

Dify - Stored XSS in chat

Moderate
laipz8200 published GHSA-qpv6-75c2-75h4 Mar 3, 2026

Package

No package listed

Affected versions

1.10.1

Patched versions

1.11.2

Description

Summary

We have identified a vulnerability that can result in stored XSS in chat conversations. This can result in an attacker creating a malicious chat, which, when shared, will compromise a victim's session.

Details

Dify is vulnerable to a stored XSS issue when rendering Mermaid diagrams within chats. This occurs because Dify’s default Mermaid configuration uses securityLevel: loose, which allows potentially unsafe content to execute.

const initMermaid = () => {
  if (typeof window !== 'undefined' && !isMermaidInitialized) {
    try {
      const config: MermaidConfig = {
        startOnLoad: false,
        fontFamily: 'sans-serif',
        securityLevel: 'loose',
        flowchart: {
          htmlLabels: true,
          useMaxWidth: true,
          curve: 'basis',
          nodeSpacing: 50,
          rankSpacing: 70,
        },

web/app/components/base/mermaid/index.tsx

In Mermaid Gantt diagrams, you can attach click events to tasks, directing them either to a JavaScript callback or to an external link. This feature is available only when securityLevel is set to ‘loose’ and it is disabled when securityLevel is set to ‘strict’.

click taskId call callback(arguments)
click taskId href URL

This configuration allows users to embed JavaScript-based payloads into chatbot conversations by using the javascript protocol.

PoC

Create a ChatBot in the Dify app.
Include the following payload in the chat input field:

flowchart TD

A["Click"]

click A href "javascript:alert(location.href)"
Loading

After sending the message, click the generated element and observe that the pop up element is executed.

Impact

This can result in an attacker creating a malicious chat, which, when shared, will compromise a victim's session.

Severity

Moderate

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
Required
Scope
Unchanged
Confidentiality
High
Integrity
None
Availability
None

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:U/C:H/I:N/A:N

CVE ID

CVE-2026-21866

Weaknesses

Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')

The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. Learn more on MITRE.

Credits