API security tool • 2026 standards
Header: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
Payload: eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ
Signature: SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
JSON Web Tokens (JWT) are compact, URL-safe tokens that enable secure information exchange between parties. They consist of three parts separated by dots: header, payload, and signature.
Best Practices:
Impact: Proper JWT handling improves API security, enables stateless authentication, and enhances user session management.
| Claim | Value | Type |
|---|---|---|
| Decode a token to see claims | ||
JSON Web Tokens consist of three parts separated by dots: header, payload, and signature. Each part is Base64Url encoded.
Header: Contains token type and signing algorithm
Payload: Contains claims (user data and metadata)
Signature: Verifies token integrity and authenticity
Structure: encodedHeader.encodedPayload.signature
Proper JWT handling improves API security, enables stateless authentication, enhances user session management, prevents CSRF attacks, and provides secure information exchange.
How many parts does a JWT token have?
The answer is C) Three parts. A JWT token consists of three parts separated by dots: header, payload, and signature. Each part is Base64Url encoded.
JWTs follow the structure: encodedHeader.encodedPayload.signature. The header contains metadata about the token, the payload contains the claims (data), and the signature verifies the token's authenticity and integrity.
JWT: JSON Web Token
Header: Token metadata (algorithm, type)
Payload: Claims (user data and metadata)
• Three parts separated by dots
• Header and payload are encoded
• Signature verifies integrity
• All parts are Base64Url encoded
• Remember: Header.Payload.Signature
• Use JWT libraries for production
• Always verify signatures
• Thinking header and payload are encrypted
• Not verifying signatures
• Storing sensitive data in payload
Which claim represents the expiration time of a JWT token?
The answer is A) exp. The "exp" (expiration time) claim identifies the time after which the JWT must not be accepted for processing. It's a Unix timestamp representing when the token expires.
Standard JWT claims (registered claims) have specific meanings. The "exp" claim is crucial for security as it prevents tokens from being used indefinitely. The value is a numeric date representing seconds since epoch.
exp: Expiration time claim
iat: Issued at time claim
nbf: Not before time claim
• exp is mandatory for security
• Check expiration before accepting
• Value is Unix timestamp
• Always validate in production
• Always validate exp claim
• Use leeway for clock differences
• Refresh tokens before expiry
• Not validating expiration
• Using expired tokens
• Not handling clock skew
You're reviewing a JWT implementation where the application stores sensitive user information like SSN and credit card numbers in the JWT payload. What security vulnerability does this represent?
This represents a serious security vulnerability where sensitive data is stored in the JWT payload. The issue is:
Best practice: Never store sensitive information in JWT payloads. Only include non-sensitive data that can be safely exposed.
JWTs are often misunderstood as encrypted tokens, but the header and payload are only Base64Url encoded, not encrypted. This means anyone with the token can decode and read the payload contents.
Encoding: Transforming data format (reversible)
Encryption: Securing data with a key (requires key to decrypt)
JWT Payload: Contains claims (data) in the token
• JWT payloads are encoded, not encrypted
• Never store sensitive data in payloads
• Treat JWTs as potentially readable
• Use server-side storage for sensitive data
• Store only public user ID
• Fetch sensitive data server-side
• Use JWE for encrypted payloads
• Thinking JWTs are encrypted
• Storing sensitive data in payloads
• Not understanding encoding vs encryption
A malicious user modifies the payload of a JWT token to change their role from "user" to "admin". What prevents this tampering from being successful?
The signature prevents this tampering. The JWT signature is created by hashing the header and payload with a secret key. When the payload is modified:
However, this only works if the server properly verifies the signature before trusting the token.
The signature is the security mechanism that ensures JWT integrity. It's computed as: HMACSHA256(base64UrlEncode(header) + "." + base64UrlEncode(payload), secret). Any change to header or payload invalidates the signature.
Signature: Hash proving token integrity
Integrity: Data hasn't been altered
HMAC: Hash-based Message Authentication Code
• Always verify signatures
• Never trust unsigned tokens
• Use strong secrets
• Rotate secrets periodically
• Use JWT libraries for verification
• Implement proper error handling
• Log signature failures
• Not verifying signatures
• Using weak secrets
• Accepting "none" algorithm
Which JWT algorithm is considered the most secure for production applications?
The answer is B) RS256 (asymmetric). While all the listed algorithms (except "none") are secure, RS256 is generally preferred for production because it uses asymmetric cryptography. This allows the issuer to sign tokens with a private key while allowing verification with a public key, which is safer for distributed systems.
HS256 (HMAC) uses symmetric keys - both signing and verification require the same secret. RS256 (RSA) uses asymmetric keys - different keys for signing and verification. Asymmetric algorithms are preferred for distributed systems where you don't want to share secrets.
HS256: HMAC with SHA-256 (symmetric)
RS256: RSA with SHA-256 (asymmetric)
ES256: ECDSA with SHA-256 (asymmetric)
• Never use "none" algorithm
• Use strong algorithms (HS256+, RS256+)
• Protect signing keys
• Consider key rotation
• Use RS256 for distributed systems
• HS256 for simpler setups
• ES256 for performance
• Using "none" algorithm
• Weak secret keys
• Not rotating keys
Q: What's the difference between JWT and JWS/JWE?
A: The differences are:
JWT (JSON Web Token): A compact, URL-safe means of representing claims to be transferred between two parties. It's a specification that can use JWS or JWE.
JWS (JSON Web Signature): Provides integrity protection for JSON content. JWTs are typically implemented using JWS for signed tokens.
JWE (JSON Web Encryption): Provides encryption for JSON content. Use JWE when you need confidentiality (encrypted payload).
Standard JWTs use JWS (signed), while encrypted JWTs use JWE. Most JWT implementations are JWS-based, meaning the payload is signed but not encrypted.
Q: How should I handle JWT expiration and refresh tokens?
A: Implement JWT expiration and refresh tokens as follows:
Access Token:
Refresh Token:
Best practices:
This approach balances security (short-lived access tokens) with usability (refresh tokens).