Endpoint vulnerable to JWT algorithm confusion

이 페이지는 아직 영어로 제공되지 않습니다. 번역 작업 중입니다.
현재 번역 프로젝트에 대한 질문이나 피드백이 있으신 경우 언제든지 연락주시기 바랍니다.

Description

This publicly exposed API endpoint may be vulnerable to JWT algorithm confusion attacks. The endpoint accepts JWTs signed with both HMAC symmetric algorithms (HS256, HS384, HS512) and asymmetric algorithms (RSA or ECDSA such as RS256, PS256, ES256).

JWT algorithm confusion occurs when an attacker can exploit the difference between symmetric and asymmetric signing algorithms. If an endpoint accepts both types, an attacker might be able to:

  1. Take a JWT that was signed with an asymmetric algorithm (like RS256)
  2. Change the algorithm header to a symmetric one (like HS256)
  3. Use the public key (which is meant to verify signatures) as the HMAC secret to create a new signature
  4. Successfully forge valid JWTs

This vulnerability allows attackers to bypass authentication and potentially gain unauthorized access to protected resources.

Your endpoint is only vulnerable if a JWT signed with a symmetric algorithm is passed to the validation function with a public key intended for asymmetrically signed JWTs. If the endpoint checks the algorithm first and sends a different secret in either of those cases, then your endpoint is secure.

Remediation

To prevent JWT algorithm confusion attacks:

  1. Use a single algorithm family: Configure your JWT validation to accept only one specific algorithm (for example, only RS256 or only HS256).
  2. Explicit algorithm verification: Always explicitly verify that the JWT uses the expected algorithm before validation.
  3. Separate keys: Use different validation keys for different algorithms if multiple algorithms are absolutely necessary.
  4. Algorithm allowlist: Implement a strict allowlist of permitted algorithms and reject any JWT using algorithms not on the list.