Algorithm Confusion
Last updated
Was this helpful?
Last updated
Was this helpful?
JWT algorithm confusion is a vulnerability where an attacker manipulates the alg
header parameter to trick the server into using an unintended or insecure algorithm for validating the JWT.
The below content & examples are based on PortSwigger's module.
Obtain the server's public key.
This might be done through conventional endpoints such as /jwks.json
or /well-known/jwks.json
.
Convert it to a suitable format.
The exposed keys (JWK format) must be identical with the server's keys.
Create a malicious JWT with a modified payload and the alg
set to HS256
.
Sign the token with HS256
using the public key as the secret.
The above command is using the provided token to calculate one or more potential n
values. For each potential value, the script outputs:
A base64-encoded PEM key in both X.509
and PKCS1
format.
A forged JWT signed using each of these keys.
To identify the correct key we need to try both and see which is accepted by the server.
If no exposed public keys are available, we can derive one from a pair of existing JWTs using .