Skip to content

Authentication Bypass Because of Hardcoded JWT Secret

Critical
Yooooomi published GHSA-gvcr-g265-j827 Mar 13, 2024

Package

No package listed

Affected versions

<1.8.0

Patched versions

1.8.0

Description

Summary

YourSpotify version <1.8.0 uses a hardcoded JSON Web Token (JWT) secret to sign authentication tokens. Attackers can use this well-known value to forge valid authentication tokens for arbitrary users.

Details

The following functions handling JWT processing in YourSpotify use the hardcoded string MyPrivateKey to sign and verify the tokens:

This JWT "secret" is the same in all installations and deployments of the application. It can easily be extracted from the source code.

This means that attackers can forge JWT signatures easily, either with custom tools or publicly available tools such as https://jwt.io/ or CyberChef.

Proof of Concept

After logging in with Spotify, the YourSpotify backend saves a signed JWT in the token cookie to save the authentication state of the current user. As an example, such a JWT may look like this:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI2NWNlNzM5ZmNhNDhkZDI1ODk3NmE1OGEiLCJpYXQiOjE3MDgxMTAyMDIsImV4cCI6MTcwODExMzgwMn0.mIOWcMxJry4SXuD8_9ol4tUZE9sO_QfABUXv-CCUsC4

This token can be decoded using widely publicly available tools such as https://jwt.io/ or CyberChef. The token from this example decodes to the following JSON header and payload:

{
  "alg": "HS256",
  "typ": "JWT"
}

{
  "userId": "65ce739fca48dd258976a58a",
  "iat": 1708110202,
  "exp": 1708113802
}

As the signature secret is hardcoded and publicly available, attackers can bypass authentication by specifying the userId of any YourSpotify user, setting an appropriate expiration time in exp, and re-signing the JWT with the hardcoded secret MyPrivateKey.

The following CyberChef recipe can be used to demonstrate how easy this process is: https://gchq.github.io/CyberChef/#recipe=JWT_Sign('MyPrivateKey','HS256')&input=ewogICAgInVzZXJJZCI6ICJpbnNlcnQgYW55IHVzZXJJZCBoZXJlIiwKICAgICJpYXQiOiAxNzA4MTEwMjAyLAogICAgImV4cCI6IDIwMDAwMDAwMDAKfQ
To reproduce the issue, simply change the userId in the token to a valid value for your specific instance and change the token cookie to the new JWT.

It must be noted that attackers need knowledge of valid YourSpotify userId for successful exploitation. However, these IDs are MongoDB IDs and are not intended to be unguessable values.
Furthermore, the userId of all registered users can be obtained by any other registered user or guests using guest tokens by querying the /accounts endpoint. It is therefore likely that attackers can obtain a valid userId.

Impact

This vulnerability allows attackers to bypass authentication and authenticate as arbitrary YourSpotify users, including admin users.

Severity

Critical

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
None

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N

CVE ID

CVE-2024-28194

Weaknesses

Credits