The Hacker's Guide to JWT Security - Patrycja Wegrzynowicz

Learn the essential security measures to protect your JSON Web Tokens (JWTs) from vulnerabilities and misuse, including key management, token verification, and anti-XSS practices to ensure secure stateless sessions and data exchange.

Key takeaways
  • JSON Web Tokens (JWTs) by default do not provide any built-in feature to revoke token or expire tokens.
  • Never trust clients and always verify signatures.
  • Always require a specific algorithm and key during verification to prevent token misuse.
  • HMAC with SHA is a widely used algorithm in JWTs, but it’s not recommended due to its potential vulnerabilities.
  • JWTs can be easily cracked, and a single compromised token can compromise the entire system.
  • It’s essential to use HTTPS from a browser to the server side, and always verify the algorithm used to generate the token.
  • Always check for vulnerabilities in libraries and frameworks used to implement JWTs.
  • Keys should be kept secret and never shared, and a single compromised key can result in massive token misuse.
  • It’s recommended to use asymmetric encryption, such as RSA, to generate JWTs, but it’s not widely supported.
  • JWTs can be used to create a stateless session mechanism, but this also provides an opportunity for attackers to steal tokens.
  • Always verify if the algorithm provided in a token is the one used on the server side.
  • Tokens can be stolen using cross-site scripting (XSS) attacks or injected attacks.
  • A shared key used on all servers can be compromised, allowing attackers to steal tokens.
  • It’s essential to understand the library in use and apply anti-XSS practices.
  • A fool with a tool is only a fool; it’s essential to know the library and its limitations.
  • JWTs can be used to bypass same origin policy, making it possible to access information from other domains.
  • It’s recommended to use a cookie as a storage mechanism for JWTs instead of using only cookies or headers.
  • The recommended key length for HMAC with SHA is a minimum of 2K bits, but keys should be as long as the length of the hash.
  • Always check for updates and maintenance cycles of libraries used to implement JWTs.
  • Keys should be changed periodically to prevent token misuse.
  • Always require proper verification of signatures and algorithm used during token generation.