Junglewise Threat Intelligence

CVE-2023-48238: joaquimserafim json-web-token algorithm confusion attack

CVE-2023-48238 · Severity: high · CVSS 7.5 · Published 2023-11-17

Vendors: npm.

Executive brief

The json-web-token library is a Node.js package used to create and verify JSON Web Tokens (JWTs), which are commonly used for authentication in web applications. The library contains a design flaw where it trusts the algorithm specified in an unverified JWT token. An attacker who can obtain an application's public key can forge valid-looking authentication tokens by crafting them with a weaker algorithm that uses the public key as a secret, bypassing all security checks and potentially gaining administrative access or impersonating any user.

Technical details

The vulnerability is a JWT algorithm confusion attack caused by line 86 of index.js reading the algorithm from the JWT header before verification is complete. When an application uses RS256 (RSA signing), the library reads the attacker-controlled "alg" field and switches to the specified algorithm (HS256) to verify the token. Since HS256 uses a shared secret (HMAC), an attacker who has the RSA public key can sign a token with HS256 using that public key as the HMAC secret, resulting in a valid signature that the vulnerable code accepts. The attack requires the attacker to obtain the public key (extractable from two valid JWT tokens) but requires no authentication or user interaction. The vulnerability affects all versions prior to 4.0.0, which fixed it by validating that the key type (PEM vs plain secret) matches the algorithm family.

Affected products

  • npm json-web-token < 4.0.0

Timeline

  • 2023-11-17: disclosed
  • 2023: patched: Fixed in version 4.0.0

References