JWT Signed With a Weak Secret

JSON Web Tokens are signed with an HMAC secret that is short or guessable, so it can be recovered offline from any valid token and used to forge new ones.

SeverityHigh
CVSS 3.18.1 CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N Open in the calculator
CVSS 4.08.6 CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-1391: Use of Weak Credentials
OWASP Top 10A07:2025 Authentication Failures
MITRE ATT&CKT1110.002 Password Cracking, T1606 Forge Web Credentials
CategoryCryptographic Failures

Description

Tokens signed with the HMAC algorithms (HS256, HS384 or HS512) are protected by a shared secret: anyone who knows it can create tokens the application will accept. The application uses a secret that is short, a dictionary word, a value copied from documentation or sample code, or a default shipped with a framework or product, rather than a long random key.

Because every token contains both the signed data and its signature, the secret can be attacked offline. An attacker with a single valid token, which normally means holding an ordinary account or seeing a token issued to someone else, can try candidate secrets at very high speed without sending any request to the application, so lockout and monitoring do not come into play. Tools such as hashcat and jwt_tool, used with wordlists of common and published JWT secrets, recover weak secrets quickly.

An attacker who recovers the secret can sign tokens with any claims, so they can impersonate any user, raise their own role to administrator and extend token lifetimes at will, with the same effect as having no signature check at all. Forged tokens are indistinguishable from genuine ones, which makes the abuse hard to detect, and where the same secret is shared by several applications or environments, all of them are affected. The same secret is sometimes also found in source code, configuration files or container images, which is a separate exposure with the same result.

The weakness is identified by taking a token issued to a test account, confirming from its header that an HMAC algorithm is used, and running such a cracking attempt against it. Recovery of the secret proves the issue, and it can be demonstrated by signing a modified token with the recovered secret and observing that the application accepts it.

Remediation

Replace the secret and manage it as a cryptographic key:

  • Generate a new secret with a cryptographically secure random number generator, at least as long as the hash output of the algorithm (256 bits for HS256, as RFC 7518 requires), for example with openssl rand -base64 32 or longer.
  • Keep the secret out of source code and images: load it from a secrets manager or key vault, use a different secret for each environment and application, and restrict who can read it.
  • Where tokens are verified by more than one service, or by parties that should not be able to issue tokens, move to an asymmetric algorithm such as RS256, PS256 or ES256, so that verifiers hold only the public key.
  • Plan for rotation by supporting more than one active key, identified by the kid header, so the key can be changed without disruption.

Replacing the secret invalidates every existing token, so plan for users to sign in again, and do not keep accepting the old secret. If forged tokens may already have been used, review logs for unexpected claims or privilege changes. Confirm the fix by repeating the cracking attempt against a newly issued token with the same wordlists and checking that the secret is not recovered.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Authentication and Sessions Findings

Every Authentication and Sessions finding