JWT (Json Web Token) Attacks
JWT (Json Web Token) Attacks
Attacks
What is JWT (JSON Web Token)
JSON Web Token (JWT) is an open standard (RFC 7519) for securely
transmitting information between parties as JSON object. It is compact,
readable and digitally signed using a private key/ or a public key pair by the
Identity Provider(IdP). So the integrity and authenticity of the token can be
verified by other parties involved. The purpose of using JWT is not to hide
data but to ensure the authenticity of the data. JWT is signed and encoded,
not encrypted. JWT is a token based stateless authentication mechanism.
Since it is a client-side based stateless session, server doesn’t have to
completely rely on a datastore(database) to save session information.
Structure of JWT
Header
Payload
Signature
Headers
Usually, headers are first part in JWT’s which consist of Algorithm used to
encode JWT and type of the token which is JWT by-default.
Payload
Payload section is the middle part of JSON web tokens, which consists of
User Data, which is passed between Client and Server.
Signature
Signature is the third part of the JWT which is created by server, and used
to validate the requests, done by the user. To create the signature, the
base-64 encoded header and payload are taken, along with a secret key
and signed with algorithm specified in the header.
This Entire JWT is embedded in a type of string and these 3 parts are
separated by dots(.).
What is Jwt token hacking
Information leakage
Since JSON web tokens are used for access control, they often contain
information about the user.
If the token is not encrypted, anyone can base64 decode the token and
read the token’s payload. So, if the token contains sensitive information, it
might become a source of information leaks.
KID is parameter seen in jwt token, and if the parameter is not properly
validated it leads to attacks like Command injection, LFI, SQLi etc. Since
the KID is often used to retrieve a key file from the file system, if it is not
sanitized before use, it can lead to a directory traversal attack.
Changing the algorithm from “RS256” to “HS256”
The HMAC algorithm uses a single key for doing both the tasks. Hence,
this method changes the workflow from Asymmetric encryption to
Symmetric encryption and allows using the same public key for signing new
tokens.
https://medium.com/swlh/hacking-json-web-tokens-jwts-
9122efe91e4a
https://blog.convisoappsec.com/en/json-web-tokens-tips-and-
procedures-for-secure-implementation/
https://portswigger.net/web-security/jwt
https://cloudentity.com/developers/basics/tokens/json-web-tokens/
https://www.invicti.com/blog/web-security/json-web-token-jwt-attacks-
vulnerabilities/