SlideShare a Scribd company logo
@yonlabs#jfokus #jwtsecurity #yonlabs
The Hacker’s Guide
to JWT Security
Patrycja Wegrzynowicz
Yon Labs
@yonlabs#jfokus #jwtsecurity #yonlabs
About Me
! 20+ professional experience
– Software engineer, researcher,
head of software R&D
! Author and speaker
– JavaOne, Devoxx, JavaZone, …
! Top 10 Women in Tech 2016 PL
! Founder and CTO Yon Labs
– Automated detection and refactoring of
software defects
– Consulting, trainings, code audits
– Security, performance, databases
@yonlabs#jfokus #jwtsecurity #yonlabs
Agenda
! Introduction to JSON Web Tokens
! Demo
– 4 demos
– Problems: RFC, algorithms, implementations, applications
! Best practices
@yonlabs#jfokus #jwtsecurity #yonlabs
The First Caveat of JWT…
How to pronounce JWT?
@yonlabs#jfokus #jwtsecurity #yonlabs
RFC 7519, JSON Web Token
source: https://tools.ietf.org/html/rfc7519
@yonlabs#jfokus #jwtsecurity #yonlabs
RFC 7519, JSON Web Token
source: https://tools.ietf.org/html/rfc7519
@yonlabs#jfokus #jwtsecurity #yonlabs
JSON Web Token
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwiaWF0IjoxNTczMDk2NT
U4LCJpc3MiOiJqd3QtZGVtbyIsImV4cCI6MTU3NTY4ODU1OH
0.wf50qNmdWNSw2e3OeAvjUdH50hX4ak6S47nh7VNn6Vk
@yonlabs#jfokus #jwtsecurity #yonlabs
JSON Web Token
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwiaWF0IjoxNTczMDk2NT
U4LCJpc3MiOiJqd3QtZGVtbyIsImV4cCI6MTU3NTY4ODU1OH
0.wf50qNmdWNSw2e3OeAvjUdH50hX4ak6S47nh7VNn6Vk
@yonlabs#jfokus #jwtsecurity #yonlabs
JSON Web Token
source: https://jwt.io
BASE64URL
@yonlabs#jfokus #jwtsecurity #yonlabs
HTTP Request with JSON Web Token
@yonlabs#jfokus #jwtsecurity #yonlabs
Demo #1
None Algorithm
@yonlabs#jfokus #jwtsecurity #yonlabs
Demo #1, None Algorithm
NO SIGNATURE
@yonlabs#jfokus #jwtsecurity #yonlabs
io.jsonwebtoken
parseClaimsJws
@yonlabs#jfokus #jwtsecurity #yonlabs
Another Library with None Problem
! National Vulnerability Database
source: https://nvd.nist.gov/vuln/detail/CVE-2018-1000531
@yonlabs#jfokus #jwtsecurity #yonlabs
Demo #1, None Algorithm, Problems
! RFC problem
– none available
! Implementation problem
– Libraries and their APIs
! Application developers’ problem
– Know your tools
@yonlabs#jfokus #jwtsecurity #yonlabs
Library API Problem
! Examples
– parse vs. parseClaimsJws
– decode vs. verify
! Best practices
– Understand your JWT library
– Check out NVD
– Require a specific algorithm and a key during verification
@yonlabs#jfokus #jwtsecurity #yonlabs
Why to Require Algorithm and Key?
! HMAC-SHA signed with RSA public key
@yonlabs#jfokus #jwtsecurity #yonlabs
HMAC-SHA signed with RSA public key
JWT
Algorithm: RS (asymmetric RSA + SHA)
signed with a server RSA private key
verified with a server RSA public key
server JWT
Changed algorithm: HS (symmetric HMAC + SHA)
signed with a server RSA public key as an HMAC secret
(RSA public keys often available)
verified with a server key (RSA public key used in HMAC)
@yonlabs#jfokus #jwtsecurity #yonlabs
Why to Require Algorithm and Key?
! Key provided in JWT header (sic!)
@yonlabs#jfokus #jwtsecurity #yonlabs
Key provided in JWT header (sic!)
JWT
Algorithm: RS (asymmetric)
signed with a server’s RSA private key
verified with a server’s RSA public key
server JWT
Algorithm: RS (asymmetric)
signed with a hacker’s RSA private key
A hacker’s RSA public key provided in a JWT header
verified with a hacker’s RSA public key (!)
@yonlabs#jfokus #jwtsecurity #yonlabs
Good API Design: auth0:java-jwt
@yonlabs#jfokus #jwtsecurity #yonlabs
Demo #2
HS256 Password/Key Cracking
@yonlabs#jfokus #jwtsecurity #yonlabs
Demo #2, hashcat
@yonlabs#jfokus #jwtsecurity #yonlabs
Demo #2, Problems
! Only one token needed
– No communication with a verification server
– All cracking done offline
– A victim/a system are unaware of the attack
! Weak key problem
! Complications
– Many algorithms
– Different kinds of keys
@yonlabs#jfokus #jwtsecurity #yonlabs
JWT, Algorithms
! HS Family
– HMAC with SHA
– Symmetric
! RS Family
– RSA with SHA
– Asymmetric
! ES/PS Families
– Elliptic Curves with SHA
– RSA Probabilistic Signature Schema with SHA
@yonlabs#jfokus #jwtsecurity #yonlabs
JWT, HS Family
! HMAC with SHA
– 256, 384, 512
– Symmetric, shared key
! Key size
– https://auth0.com/blog/brute-forcing-hs256-is-possible-the-importance-of-using-
strong-keys-to-sign-jwts/
– „As a rule of thumb, make sure to pick a shared-key as long as the length of the
hash.”
– HS256 => 32 bytes minimum
! Scalability
– More servers => larger attack surface
– One server compromised => the entire system compromised
@yonlabs#jfokus #jwtsecurity #yonlabs
JWT, RS Family
! RSA-PKCS1.5 with SHA
– 256, 384, 512
– Asymmetric, public/private keys
! Key size
– https://www.nist.gov (US DoC) recommendation
– 2048 bits => 256 bytes
– 3072 bits for security beyond 2030
! Scalability and performance
– Authentication server/servers => private key
– Verification servers => public key
– The longer key => the slower verification
@yonlabs#jfokus #jwtsecurity #yonlabs
Demo #3
Packet Sniffing
@yonlabs#jfokus #jwtsecurity #yonlabs
Demo #3, Problems
! Lack of encryption
– HTTPS
! Token sidejacking
– Stolen tokens can be freely used
– Used as long as they are valid (expiration time!)
– “Replay” attack
@yonlabs#jfokus #jwtsecurity #yonlabs
Demo #4
XSS to Steal a Token
@yonlabs#jfokus #jwtsecurity #yonlabs
XSS Attack Vector
@yonlabs#jfokus #jwtsecurity #yonlabs
Demo #4, Problems and Solutions
! XSS
! No way to block access to a session storage for JS
! Best practices anti-XSS
– Content Security Policy
– Code audits/pen-testing to discover XSS
– Good libraries and smart usage
! Hardened cookie as a storage mechanism for JWT
– No server-side state
– Flags: secure, httpOnly, sameSite
– But… CSRF L
@yonlabs#jfokus #jwtsecurity #yonlabs
OWASP Token Sidejacking Solution
! https://cheatsheetseries.owasp.org/cheatsheets/JSON_Web_Token
_Cheat_Sheet_for_Java.html
! Fingerprint
– Random secure value
– Hashed and added to JWT claims
– Raw value set as a hardened cookie
! JWT in session storage
! Verification
– Verifies JWT
– Hashes a cookie value
– Verifies if a hashed cookie and JWT fingerprint values are equal
@yonlabs#jfokus #jwtsecurity #yonlabs
Token Sidejacking Solution:
Fingerprinting with Cookie
JWT
Fingerprint claim: Hash(RANDOM)
server
Stolen JWT
No cookie/no RANDOM available!
Cookie
Fingerprint: raw RANDOM
Verification
JWT verification
Hash(cookie) == Fingerprint claim in JWT
@yonlabs#jfokus #jwtsecurity #yonlabs
Basic Hygiene: Timeouts and Logouts
! Logouts
– No built-in feature to revoke a
token
– User must be able to explicitly
stop a session
! Timeouts
– No built-in feature to implement
an inactivity timeout
– To avoid re-logging often we use a
long-expiration time Photo by Piron Guillaume on Unsplash
@yonlabs#jfokus #jwtsecurity #yonlabs
Basic Hygiene: Timeouts and Logouts
! Logouts
– Blacklist/invalidation store on the
server-side
! Timeouts
– Shorter token expiration times
– Accepting re-logging or refreshing
access tokens
STATE
@yonlabs#jfokus #jwtsecurity #yonlabs
JWT Security
@yonlabs#jfokus #jwtsecurity #yonlabs
A fool with a tool is only a fool
@yonlabs#jfokus #jwtsecurity #yonlabs
Continuous Learning
@yonlabs#jfokus #jwtsecurity #yonlabs
Q&A
! patrycja@yonlabs.com
! @yonlabs

More Related Content

PDF
Introduction to API Security - Intergalactic
PPTX
Learn SoapUI
PDF
Credential store using HashiCorp Vault
PPT
Secure code practices
PDF
OWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
PDF
Postman: An Introduction for Testers
PDF
Tech Talk #5 : Code Analysis SonarQube - Lương Trọng Nghĩa
PDF
Secure coding presentation Oct 3 2020
Introduction to API Security - Intergalactic
Learn SoapUI
Credential store using HashiCorp Vault
Secure code practices
OWASP AppSecEU 2018 – Attacking "Modern" Web Technologies
Postman: An Introduction for Testers
Tech Talk #5 : Code Analysis SonarQube - Lương Trọng Nghĩa
Secure coding presentation Oct 3 2020

What's hot (20)

PPT
Introduction to CSS
PPTX
Web Cache Poisoning
PPTX
A presentation on front end development
PDF
Broken access controls
PDF
Introduction to JMeter
ODP
Secure coding in C#
PDF
Data Driven Testing
PPTX
QSpiders - Selenium Webdriver
PPTX
Api gateway : To be or not to be
PDF
Styled Components & React.js
PPT
WebLogic Scripting Tool Overview
PPT
Introduction to BOOTSTRAP
PPTX
Attacking thru HTTP Host header
PPTX
JSON: The Basics
PDF
Postman: An Introduction for Testers
PPT
Selenium
PDF
REST API Best (Recommended) Practices
PDF
Php introduction
PDF
Ekoparty 2017 - The Bug Hunter's Methodology
Introduction to CSS
Web Cache Poisoning
A presentation on front end development
Broken access controls
Introduction to JMeter
Secure coding in C#
Data Driven Testing
QSpiders - Selenium Webdriver
Api gateway : To be or not to be
Styled Components & React.js
WebLogic Scripting Tool Overview
Introduction to BOOTSTRAP
Attacking thru HTTP Host header
JSON: The Basics
Postman: An Introduction for Testers
Selenium
REST API Best (Recommended) Practices
Php introduction
Ekoparty 2017 - The Bug Hunter's Methodology

Similar to The Hacker's Guide to JWT Security (20)

PDF
The Hacker's Guide to JWT Security
PDF
Anastasia Vixentael - Don't Waste Time on Learning Cryptography: Better Use I...
PDF
Jwt == insecurity?
PDF
REST API Pentester's perspective
PDF
You wanna crypto in AEM
PPTX
OWASP Poland Day 2018 - Andrzej Dyjak - Zero Trust Theorem
PDF
The Emergent Cloud Security Toolchain for CI/CD
PDF
Alfresco Security Best Practices 2014
PDF
Threat stack aws
PPTX
Ten Commandments of Secure Coding - OWASP Top Ten Proactive Controls
PPTX
Ten Commandments of Secure Coding
PDF
How to hide your browser 0-days
PPTX
Cqcon2015
PDF
"Crypto wallets security. For developers", Julia Potapenko
PPTX
JavaScript Static Security Analysis made easy with JSPrime
PPTX
Protect Your Payloads: Modern Keying Techniques
PPTX
Dmk sb2010 web_defense
PPT
Top Ten Proactive Web Security Controls v5
PPTX
Building Secure User Interfaces With JWTs
PPTX
Passwords & security
The Hacker's Guide to JWT Security
Anastasia Vixentael - Don't Waste Time on Learning Cryptography: Better Use I...
Jwt == insecurity?
REST API Pentester's perspective
You wanna crypto in AEM
OWASP Poland Day 2018 - Andrzej Dyjak - Zero Trust Theorem
The Emergent Cloud Security Toolchain for CI/CD
Alfresco Security Best Practices 2014
Threat stack aws
Ten Commandments of Secure Coding - OWASP Top Ten Proactive Controls
Ten Commandments of Secure Coding
How to hide your browser 0-days
Cqcon2015
"Crypto wallets security. For developers", Julia Potapenko
JavaScript Static Security Analysis made easy with JSPrime
Protect Your Payloads: Modern Keying Techniques
Dmk sb2010 web_defense
Top Ten Proactive Web Security Controls v5
Building Secure User Interfaces With JWTs
Passwords & security

More from Patrycja Wegrzynowicz (11)

PDF
The Hacker's Guide to Kubernetes: Reloaded
PDF
The Hacker's Guide to Kubernetes
PDF
The Hacker's Guide to XSS
PDF
The Hacker's Guide to NoSQL Injection
PDF
The Hacker's Guide to Session Hijacking
PDF
Second Level Cache in JPA Explained
PPTX
Thinking Beyond ORM in JPA
PDF
The Hacker's Guide To Session Hijacking
PDF
Lazy vs. Eager Loading Strategies in JPA 2.1
PDF
Secure Authentication and Session Management in Java EE
PPTX
Thinking Beyond ORM in JPA
The Hacker's Guide to Kubernetes: Reloaded
The Hacker's Guide to Kubernetes
The Hacker's Guide to XSS
The Hacker's Guide to NoSQL Injection
The Hacker's Guide to Session Hijacking
Second Level Cache in JPA Explained
Thinking Beyond ORM in JPA
The Hacker's Guide To Session Hijacking
Lazy vs. Eager Loading Strategies in JPA 2.1
Secure Authentication and Session Management in Java EE
Thinking Beyond ORM in JPA

Recently uploaded (20)

PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
medical staffing services at VALiNTRY
PPTX
Essential Infomation Tech presentation.pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
System and Network Administration Chapter 2
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
wealthsignaloriginal-com-DS-text-... (1).pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
medical staffing services at VALiNTRY
Essential Infomation Tech presentation.pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
VVF-Customer-Presentation2025-Ver1.9.pptx
Understanding Forklifts - TECH EHS Solution
Odoo POS Development Services by CandidRoot Solutions
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
System and Network Administration Chapter 2
Upgrade and Innovation Strategies for SAP ERP Customers
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Reimagine Home Health with the Power of Agentic AI​
Softaken Excel to vCard Converter Software.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf

The Hacker's Guide to JWT Security