Both JWT (JSON Web Token) and PASETO (Platform-Agnostic Security Tokens) are technologies used to generate secure tokens. Secure and scalable token-based authentication and authorization are essential for any modern web and API applications. JWT is known for its flexibility and broad support across platforms. However, this flexibility can sometimes lead to cryptographic misconfigurations. PASETO is a newer addition to the token generation stack, simplifying token security with built-in cryptographic tools. In this article, I will compare the differences between JWT and PASETO.
JWT stands for JSON Web Token. It is a compact, URL-safe, self-contained token used to securely transfer information between interested parties. It is mainly used for authentication and authorization in stateless and highly scalable web applications. This compact token contains all the necessary information to validate the user's identity.
JWT token has three parts. These parts are separated by “.“
<Header>.<Payload>.<Signature>
The header specifies the type of token (JWT) and the signing algorithm (eg: HS256, RS256)
{ "alg": "HS256", "typ": "JWT" }
This contains claims. Claims can be standard, public claims, or private claims.
{
"sub": "123456",
"name": "myname",
"admin": true,
"iat": 1516239022
}
This is the part that ensures integrity and authenticity. It is created by combining the header, payload, a secret key, and the signing algorithm:
HMACSHA256(
base64UrlEncode(header) + "." + base64UrlEncode(payload),
secret
)
Here’s a sample of a JWT token:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTYiLCJuYW1lIjoibXluYW1lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.6GOSrUxRcqk5AjW7E6Xn-T3B9BE5Gy8iX3oyTsVswIY
PASETO (Platform-Agnostic Security Tokens) is a new standard for creating secure, stateless tokens, widely used in authentication and authorization. Built to address the shortcomings of JSON Web Tokens (JWT), PASETO prioritizes security, simplicity, and ease of use, making it an excellent choice for modern applications.
PASETO token consists of three or four parts. Each part is separated by “.“ Below is the structure of the PASETO token.
<Version>.<Purpose>.<Payload>.<optional_footer>
Criterion |
JWT |
PASETO |
---|---|---|
Design Philosophy |
1. Emphasizes flexibility and broad support.2. Allows a wide variety of algorithms, which has led to security issues3. Relies heavily on developers to choose secure configurations |
1. Prioritizes security by default |
Algorithm Choice |
1. Supports a wide range of algorithms, including some that are outdated or insecure (e.g., RS256, HS256, and even the "none" algorithm if not properly configured). |
1. Only allows safe and modern algorithms (e.g., AES-GCM). |
Usability and Simplicity |
1. Offers flexibility, but this can lead to misconfigurations.2.Developers must carefully manage signing, verification, and algorithm selection to avoid security risks. |
1.Easier for developers to use securely because it enforces secure defaults.2. Provides two main purposes: Local tokens (v2.local) for symmetric encryption and Public tokens (v2.public) for public key cryptography. |
Security |
1. Vulnerable to various attacks if not implemented carefully, such as: Algorithm confusion (e.g., using "none").2. Key mismanagement3. Security depends heavily on developers knowledge and configuration. |
1. Strong emphasis on cryptographic safety2. Removes the risk of algorithm confusion attacks by avoiding algorithm negotiation altogether3. Explicit versioning ensures compatibility and security |
Token Size |
Size is larger if asymmetric signatures are used |
Usually results in smaller and more consistent size. This is because of the fixed length header and more efficient cryptographic algorithms. |
Backward Compatibility |
Algorithm negotiation risks |
Explicit versioning helps with backward compatibility. |
Statefulness |
JWT is stateless by default. And it is harder to implement statefulness. |
PASETO also stateless by default. |
Storage |
Tokens are stored in the client side to be sent to server as part of the request. |
Tokens are stored in the client side to be sent to server as part of the request. |
Scalability |
JWT is widely used and proven to be highly scalable. But JWT token size is large and has expensive cryptographic operations. This design can introduce inefficiencies. |
PASETO token size is smaller and has faster algorithms with better default security. This is optimized for much higher scalability than JWT. |
Confidentiality |
By default, JWT is only encoded. Anybody who has access to the token can look into the data. While the token's signature ensures integrity, it doesn't hide the data**Optional:**To achieve confidentiality, the developer can implement JSON Web Encryption (JWE). Implementing JWE adds significant complexity to token management. Developers must handle encryption and decryption keys and ensure they use secure configurations. |
In 'local' mode, by default, PASETO uses authenticated encryption to encrypt the payload. This offers confidentiality and integrity. The payload is completely hidden even if somebody gets access to the token. |
Revocability (Revocability refers to the ability to invalidate tokens before their expiration, ensuring that unauthorized or compromised tokens can no longer be used) |
No built-in mechanism to support the revocability. Must rely on external mechanisms to support this. |
No built-in mechanism to support the revocability. Must rely on external mechanisms to support this. |
Implementation Complexity (The complexity depends on the ease of use, available libraries, cryptographic requirements, and design considerations) |
**Advantages: |
|
\ 1) Widespread Adoption: Extensive library support in every major programming language. Many frameworks include built-in tools for creating, verifying, and signing. |
|
|
\ 1) Custom Claims:Adding a custom claim to JWT token can lead to token bloating if not managed carefully. |
**Advantages: |
|
\ 1) Simpler Design:It has simplified the structure and enforcing best cryptographic practices. Unlink JWT both signing and encryption and handled natively. |
|
|
\ Less adoption. |
|
|
Use Cases |
1) Broad and flexible |
1) Ideal for scenarios where security is the highest priority, and flexibility is less critical. |
Both JWT and PASETO are widely used for stateless authentication and authorization, but their strengths and weaknesses make them more suitable for different use cases.