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
Best time to visit Stockholm
7 Things That Affect Small Business Insurance Costs | Harry Levine
Paris 2024: Kellie Harrington has 'no more mountains' as double Olympic champion retires
Prosper TX Visitors Guide - Dallas Fort Worth Guide
Bluegabe Girlfriend
Kent And Pelczar Obituaries
Kostenlose Games: Die besten Free to play Spiele 2024 - Update mit einem legendären Shooter
Milk And Mocha GIFs | GIFDB.com
No Credit Check Apartments In West Palm Beach Fl
William Spencer Funeral Home Portland Indiana
Facebook Marketplace Charlottesville
Craigslist Pets Southern Md
Hillside Funeral Home Washington Nc Obituaries
Caliber Collision Burnsville
Troy Athens Cheer Weebly
The Murdoch succession drama kicks off this week. Here's everything you need to know
978-0137606801
Overton Funeral Home Waterloo Iowa
Dr Manish Patel Mooresville Nc
Youravon Comcom
Payment and Ticket Options | Greyhound
Log in or sign up to view
Lancasterfire Live Incidents
ELT Concourse Delta: preparing for Module Two
Caledonia - a simple love song to Scotland
Wbiw Weather Watchers
Azur Lane High Efficiency Combat Logistics Plan
Www Craigslist Madison Wi
What Are The Symptoms Of A Bad Solenoid Pack E4od?
683 Job Calls
BJ 이름 찾는다 꼭 도와줘라 | 짤방 | 일베저장소
Wat is een hickmann?
Malluvilla In Malayalam Movies Download
Pulitzer And Tony Winning Play About A Mathematical Genius Crossword
Ultra Ball Pixelmon
Spirited Showtimes Near Marcus Twin Creek Cinema
N.J. Hogenkamp Sons Funeral Home | Saint Henry, Ohio
Page 2383 – Christianity Today
Red Sox Starting Pitcher Tonight
Eero Optimize For Conferencing And Gaming
Pch Sunken Treasures
Jambus - Definition, Beispiele, Merkmale, Wirkung
2700 Yen To Usd
Ramsey County Recordease
Postgraduate | Student Recruitment
Luciane Buchanan Bio, Wiki, Age, Husband, Net Worth, Actress
Gotrax Scooter Error Code E2
Pgecom
What is 'Breaking Bad' star Aaron Paul's Net Worth?
Amateur Lesbian Spanking
Motorcycle For Sale In Deep East Texas By Owner
Barback Salary in 2024: Comprehensive Guide | OysterLink
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.