Security Flaw in OAuth JWT Library: `verify()` Method Fails to Validate `alg` Header, Enabling Algorithm Confusion Attacks
A critical security vulnerability has been identified in a widely used OAuth JWT library. The `verify()` method within the `JwtSigner.ts` file does not validate the `alg` (algorithm) field in the JWT header. This oversight creates a direct path for algorithm confusion attacks, a well-documented and high-severity exploit pattern. Despite the library's internal use of the correct `RSASSA-PKCS1-v1_5` with `SHA-256`, the absence of explicit header validation leaves the verification process fundamentally insecure against token manipulation.
The flaw is located in `packages/oauth/src/jwt/JwtSigner.ts` between lines 59 and 95. The code parses the token but proceeds with verification without checking if the declared algorithm matches the expected `RS256` or if the token type is `JWT`. This allows an attacker to craft a malicious token with a header claiming `alg: "none"` (no signature) or `alg: "HS256"` (symmetric signing). If the underlying cryptographic API's behavior were to change or be misconfigured in the future, such a token could bypass signature verification entirely, granting unauthorized access.
This vulnerability mirrors the attack vector documented in CVE-2015-9235 and related advisories. The suggested fix is straightforward: after parsing the header, the code must explicitly validate that `header.alg === 'RS256'` and `header.typ === 'JWT'` before any verification logic proceeds. The severity is rated as high, as this flaw represents a foundational weakness in a core authentication component, exposing any dependent application to potential credential forgery and system compromise.