The Hard Parts of JWT Security Nobody Talks About (2024)

JWT Validation beyond Signatures

Using JWTs securely goes beyond verifying their signatures. Apart from the signature, the JWT can contain a few other security-related properties. These properties come in the form of reserved claims that can be included in the body of the JWT.

The most crucial security claim is the "exp" claim. The issuer uses this claim to indicate the expiration date of a JWT. If this expiration date lies in the past, the JWT has expired and must not be used anymore. A typical example use case is an OpenID Connect identity token, which expires after a set period.

A second related claim is the “iat” claim. This claim indicates when the JWT has been issued. It is often used to enable the consumer of the JWT to decide if the token is fresh enough. If not, the consumer can reject the JWT in favor of a newly issued one.

Third, JWTs can contain the "nbf" claim. This abbreviation stands for "not before." It indicates the point in time when the JWT becomes valid. A JWT can only be accepted if this timestamp lies in the past.

The fourth security-relevant reserved claim is "iss." This claim indicates the identity of the party that issued the JWT. The claim holds a simple string, of which the value is at the discretion of the issuer. The consumer of a JWT should always check that the "iss" claim matches the expected issuer (e.g., sso.example.com).

The fifth relevant claim is the "aud" claim. This abbreviation stands for audience. It indicates for whom the token is intended. The consumer of a JWT should always verify that the audience matches its own identifier. The value of this claim is again a string value, at the discretion of the issuer. In OAuth 2.0 and OpenID Connect scenarios, this value typically contains the client identifier (e.g., api.example.com).

Note that the specification mentions that all of these claims are optional. Nonetheless, it is highly recommended that your application includes them when issuing JWTs. Similarly, their presence must be verified when validating JWTs. Doing so can help prevent abuse when the JWT is exposed one way or another.

Below is a code example of how to verify these claims using the popular “java-jwt” library. As you can see, the library offers dedicated functions to verify these claims. Check your libraries to find out how to optimally handle these claims.

Algorithm algorithm = Algorithm.HMAC256(HMAC_KEY);
JWTVerifier verifier = JWT.require(algorithm)
.withIssuer("sso.pragmaticwebsecurity.com")
.withAudience("api.pragmaticwebsecurity.com")
.build();
DecodedJWT verifiedJWT = verifier.verify(token);

// Get the subject
verifiedJWT.getSubject();

The Hard Parts of JWT Security Nobody Talks About (2024)

FAQs

What is the security flaw in JWT? ›

JWT attacks involve a user sending modified JWTs to the server in order to achieve a malicious goal. Typically, this goal is to bypass authentication and access controls by impersonating another user who has already been authenticated.

Is JWT enough for security? ›

It's important to note that a JWT guarantees data ownership but not encryption. The reason is that the JWT can be seen by anyone who intercepts the token because it's serialized, not encrypted. It is strongly advised to use JWTs with HTTPS, a practice that extends to general web security.

What are the weaknesses of JWT? ›

Lack of Encryption

One of the most significant weaknesses of JWTs is their lack of encryption. JWTs are designed to be compact and self-contained, which means that the data within them is not encrypted. While they can be signed to ensure data integrity, sensitive information within a JWT remains exposed in plaintext.

Why JWTs are bad for authentication? ›

JWTs which just store a simple session token are inefficient and less flexible than a regular session cookie, and don't gain you any advantage. The JWT specification itself is not trusted by security experts. This should preclude all usage of them for anything related to security and authentication.

What is better than JWT security? ›

Security: OAuth is a secure way to manage authorization flows, while JWT is a lightweight and self-contained token. It does not provide security on its own, but can be secure as part of a well designed authentication system.

Is JWT obsolete? ›

In May 2023, Adobe announced the deprecation and end of life of Service Account (JWT) credentials. This means that any of your integrations or custom applications using a Service Account (JWT) credential will need to migrate to the new OAuth Server-to-Server credential before January 27, 2025.

Why are JWTs insecure? ›

Some web applications rely on JSON Web Tokens (JWTs) for stateless authentication and access control instead of stateful ones with traditional session cookies. Some implementations are insecure and allow attackers to bypass controls, impersonate users, or retrieve secrets.

Is JWT more secure than API key? ›

The credentials can either be a cryptographically secure JSON Web Token (JWT) signed with the client's private key or a secret value generated from your authorization server. A private key JWT is more secure, as you won't risk exposing the secret value that accidentally creates similar access concerns as an API key.

What is the most secure JWT? ›

The option with the best security and performance is EdDSA, though ES256 (The Elliptic Curve Digital Signature Algorithm (ECDSA) using P-256 and SHA-256) is also a good choice.

What is the weak algorithm of JWT? ›

Our security testers did a penetration testing on community site and noticed that application uses JWT (JSON Web Token) for session management. They identified that the JWT implemented uses the HS256 algorithm, which is considered a weaker algorithm. Recommendation is to use RS256 as a signing algorithm.

What prevents a JWT from being tampered with? ›

Use an encrypted channel(HTTPS): Encrypting data while it's in transit between the client and server when sending JWTs over HTTPS ensures confidentiality and integrity. By using HTTPS, attackers are prevented from listening in on or altering the JWTs while they are being transmitted.

What is JWT token vulnerability? ›

JWT vulnerabilities typically arise due to flawed JWT handling within the application itself. The various specifications related to JWTs are relatively flexible by design, allowing website developers to decide many implementation details for themselves.

What are the risks of JWT authentication? ›

This includes personally identifiable information (PII), authentication credentials, and session tokens. Without proper encryption measures, such as JSON Web Encryption (JWE), organizations risk exposing critical data to unauthorized parties, leading to privacy violations, identity theft, and fraud.

Is JWT vulnerable to XSS? ›

On the other hand, session storage provides a more persistent storage solution for JWTs, as the data is stored within the user's session. However, session storage is still vulnerable to XSS attacks. An attacker can steal JWTs and gain unauthorized access to the application.

What is authentication flaw? ›

Authentication vulnerabilities can allow attackers to gain access to sensitive data and functionality. They also expose additional attack surface for further exploits. For this reason, it's important to learn how to identify and exploit authentication vulnerabilities, and how to bypass common protection measures.

Top Articles
Foundation Issue Vs. House Settling | Differences And Signs
How to Make a Living from Writing
San Angelo, Texas: eine Oase für Kunstliebhaber
Kansas Craigslist Free Stuff
OSRS Fishing Training Guide: Quick Methods To Reach Level 99 - Rune Fanatics
Decaying Brackenhide Blanket
T&G Pallet Liquidation
Texas (TX) Powerball - Winning Numbers & Results
Obituary Times Herald Record
FIX: Spacebar, Enter, or Backspace Not Working
Oriellys St James Mn
Bnsf.com/Workforce Hub
Daily Voice Tarrytown
Brett Cooper Wikifeet
Marvon McCray Update: Did He Pass Away Or Is He Still Alive?
Sni 35 Wiring Diagram
10 Fun Things to Do in Elk Grove, CA | Explore Elk Grove
Crawlers List Chicago
Qhc Learning
Why do rebates take so long to process?
Sussyclassroom
Xfinity Outage Map Fredericksburg Va
Craigslist Pennsylvania Poconos
Phantom Fireworks Of Delaware Watergap Photos
Bay Area Craigslist Cars For Sale By Owner
3 Ways to Format a Computer - wikiHow
2487872771
Craigslist Texas Killeen
Loopnet Properties For Sale
Grand Teton Pellet Stove Control Board
How To Make Infinity On Calculator
Orange Pill 44 291
Www Violationinfo Com Login New Orleans
Iban's staff
Agematch Com Member Login
Games R Us Dallas
Philadelphia Inquirer Obituaries This Week
Craigslist Free Manhattan
Easy Pigs in a Blanket Recipe - Emmandi's Kitchen
Doordash Promo Code Generator
The Attleboro Sun Chronicle Obituaries
Wilson Tire And Auto Service Gambrills Photos
Satucket Lectionary
Ucla Basketball Bruinzone
Ajpw Sugar Glider Worth
552 Bus Schedule To Atlantic City
Used Sawmill For Sale - Craigslist Near Tennessee
Lux Funeral New Braunfels
De Donde Es El Area +63
Morgan State University Receives $20.9 Million NIH/NIMHD Grant to Expand Groundbreaking Research on Urban Health Disparities
Gameplay Clarkston
Att Corporate Store Location
Latest Posts
Article information

Author: Wyatt Volkman LLD

Last Updated:

Views: 5881

Rating: 4.6 / 5 (46 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Wyatt Volkman LLD

Birthday: 1992-02-16

Address: Suite 851 78549 Lubowitz Well, Wardside, TX 98080-8615

Phone: +67618977178100

Job: Manufacturing Director

Hobby: Running, Mountaineering, Inline skating, Writing, Baton twirling, Computer programming, Stone skipping

Introduction: My name is Wyatt Volkman LLD, I am a handsome, rich, comfortable, lively, zealous, graceful, gifted person who loves writing and wants to share my knowledge and understanding with you.