Signature Validation
Last updated
Was this helpful?
Last updated
Was this helpful?
JWT signature validation involves verifying that the token's signature is legitimate and has not been tampered with. This process uses a cryptographic algorithm and a secret key (or public key, in the case of asymmetric algorithms) to ensure that the token was created by a trusted source and that its content remains unchanged. Proper signature validation prevents attackers from altering the token's claims or creating forged tokens. Servers don't store any JWT-related information, thus, they don't know anything about its contents!
The JWT alg: "none"
attack exploits the JWT specification allowing alg: "none"
for tokens without a signature. An attacker creates a token with alg: "none"
and arbitrary claims. If the server accepts this token without verifying a signature, the attacker gains unauthorized access.
The below example is based on TCM's course.
After obtaining a JWT, we can start by auditing it by using an endpoint which process the token in some way, i.e., sends back different responses if the token is and it isn't present (Figure 1).
The JWT header contains an alg
parameter which tells the server which algorithm was used to sign the token, i.e., which alogirthm it needs to use when veryfing the signature. This is inherently flawed as it is user-controlled. JWTs can be also left unsigned using "alg":"none"
, aka unsecure JWT. Servers usually reject this tokens, but since this relies on string parsing, it can be obfuscated.
Even if the token is unsigned, the payload part must end with a trailing dot.
We can then audit the JWT (Figure 2).
We also have the option to choose different capitalization of the none
algorithm (Figure 5).
The JWT blank signature attack involves removing or leaving the signature part of a JWT blank. If the server does not properly validate the signature's presence and integrity, it accepts the manipulated token.
We can generate a token without a signature and see how the server responds.
The JWT arbitrary signature attack involves an attacker creating a token with a valid header and payload but using an arbitrary or invalid signature. If the server does not correctly verify the token's signature against the proper secret or public key, it may accept the manipulated token.
JWT libraries usually provide 2 methods, one for verification and one for decoding. For example, Node.js's jsonwebtoken
library has the verify()
and decode()
methods. If a developer only use the latter, the application won't verify the signature at all. In this case, it is possible to modify a claim directly (Figure 6).
We could then use Burp's extension to validate the alg:none
vulnerability (Figure 3 & 4).
The below example is based on APISEC University's course .
The below example is based on PortSwigger's lab.
jwt_tool
.alg:none
attack.200
without validating the JWT signature (BOLA).none
algorithm.sub
claim results in an altered signature which is accepted by the server.