Today, virtually every web developer uses JSON Web Tokens (JWTs) one way or another. OAuth 2.0 and OpenID Connect use them to exchange information between parties. Modern applications use them to keep track of state between requests. Backend services use them to propagate authorization information in a microservice architecture.
In spite of the popularity of JWTs, their security properties are often unknown or misunderstood. How do you choose the signature scheme for a JWT? What other properties should you verify before trusting a JWT? How do you handle key rotation and key management?
The answers to these questions are crucial to ensure the security of the application's architecture. In this article, we go beyond the typical narrative of using JWTs. We look at the hard parts nobody ever talks about, including:
- Symmetric JWT signatures
- Asymmetric JWT signatures
- JWT validation beyond signatures
- Cryptographic key management
- Using JWTs in practice
In the end, we also provide a cheat sheet on JWT security, to keep track of the best practices we cover here.
NOTE: If you are not familiar with the basics of JWTs, we suggest you read an introduction to JWT before diving into this article.