CVE-2023-23608: Spotipy Path Traversal Vulnerability

MODERATE
Advisory Identifier: GHSA-q764-g6fm-555v
CVSS 5.4
CWE-22
Published
Advisory Summary

CVE-2023-23608 is a MODERATE (CVSS 5.4) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Spotipy libraries in the PyPI ecosystem. The issue involves path traversal in spotipy. Remediation is available by upgrading affected packages to version 2.22.1.

CVE-2023-23608 at a Glance

CVE Identifier CVE-2023-23608
GHSA Identifier GHSA-q764-g6fm-555v
Severity MODERATE
CVSS v3.1 Base Score 5.4
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Spotipy
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 5.4

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

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

How to Fix CVE-2023-23608

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.22.1
pip install spotipy>=2.22.1
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-2023-23608, 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.22.1), 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-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. 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 If a malicious URI is passed to the library, the library can be tricked into performing an operation on a different API endpoint than intended. ### Details The [code Spotipy uses to parse URIs and URLs ](https://github.com/spotipy-dev/spotipy/blob/master/spotipy/client.py#L1942) accepts user data too liberally which allows a malicious user to insert arbitrary characters into the path that is used for API requests. Because it is possible to include `..`, an attacker can redirect for example a track lookup via `spotifyApi.track()` to an arbitrary API endpoint like playlists, but this is possible for other endpoints as well. Before the security advisory feature was enabled on GitHub, I was already in contact with Stéphane Bruckert via e-mail, and he asked me to look into a potential fix. My recommendation is to perform stricter parsing of URLs and URIs, which I implemented in the patch included at the end of the report. If you prefer, I can also invite you to a private fork of the repository. ### Impact The impact of this vulnerability depends heavily on what operations a client application performs when it handles a URI from a user and how it uses the responses it receives from the API.

CVE-2023-23608 Affected Spotipy Versions

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

References

Frequently Asked Questions

What is CVE-2023-23608?
CVE-2023-23608 is a security vulnerability in Spotipy involving Path traversal in spotipy under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Spotipy versions are affected?
Affected versions include releases prior to 2.22.1 across affected packages: spotipy.
What version fixes CVE-2023-23608?
Upgrading to 2.22.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is spotipy affected?
Yes, spotipy is affected in releases prior to 2.22.1. Upgrade your dependency to 2.22.1 or later.
What is the CVSS score of CVE-2023-23608?
CVE-2023-23608 has a CVSS v3.1 base score of 5.4 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:L/A:L.
What CWE is associated with CVE-2023-23608?
CVE-2023-23608 is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check PyPI dependencies for CVE-2023-23608?
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-q764-g6fm-555v",
  "modified" : "2023-02-07T04:11:52Z",
  "published" : "2023-01-23T22:05:11Z",
  "aliases" : [ "CVE-2023-23608" ],
  "summary" : "Path traversal in spotipy",
  "details" : "### Summary\nIf a malicious URI is passed to the library, the library can be tricked into performing an operation on a different API endpoint than intended.\n\n### Details\nThe [code Spotipy uses to parse URIs and URLs ](https://github.com/spotipy-dev/spotipy/blob/master/spotipy/client.py#L1942) accepts user data too liberally which allows a malicious user to insert arbitrary characters into the path that is used for API requests. Because it is possible to include `..`, an attacker can redirect for example a track lookup via `spotifyApi.track()` to an arbitrary API endpoint like playlists, but this is possible for other endpoints as well.\n\nBefore the security advisory feature was enabled on GitHub, I was already in contact with Stéphane Bruckert via e-mail, and he asked me to look into a potential fix. \n\nMy recommendation is to perform stricter parsing of URLs and URIs, which I implemented in the patch included at the end of the report. If you prefer, I can also invite you to a private fork of the repository.\n\n### Impact\nThe impact of this vulnerability depends heavily on what operations a client application performs when it handles a URI from a user and how it uses the responses it receives from the API.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:L/A:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "spotipy"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.22.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/spotipy-dev/spotipy/security/advisories/GHSA-q764-g6fm-555v"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-23608"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/spotipy-dev/spotipy"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-01-23T22:05:11Z",
    "nvd_published_at" : "2023-01-26T21:18:00Z"
  }
}