Intermediate LevelWeb Security & Cyber Defense
How do signature forgery attacks work against JWT implementations and how do you secure verification?
❓ Interview Prompt: Explain JWT vulnerabilities (`"alg": "none"` attack, Key Confusion HS256 vs RS256), signature verification, and enforcing algorithm whitelists.
Exploiting weak JWT implementation libraries:
2 Classic Signature Forgery Attacks:
1
The 'none' Algorithm Attack: Attacker modifies JWT header to '{ "alg": "none" }' and strips the signature. Vulnerable libraries skip signature verification entirely!
2
RS256 $\rightarrow$ HS256 Key Confusion: Attacker changes algorithm from RS256 to HS256 and signs the token using the server's PUBLIC key as the secret. Vulnerable servers verify with the public key as an HMAC secret!
Defense:
Explicitly enforce a strict algorithm whitelist ('algorithms: ['RS256']') during token verification.
Code Implementation Example
typescript
import jwt from 'jsonwebtoken';
// ✅ SECURE: Enforce explicit algorithm whitelist during verification!
export function verifyUserToken(token: string, publicKey: string) {
return jwt.verify(token, publicKey, {
algorithms: ['RS256'] // Rejects 'none' and 'HS256' algorithm switching!
});
}💡Enforcing explicit RS256 algorithm whitelisting during JWT verification.
🎯 Interview Key Takeaway
Enforce explicit algorithm whitelists during JWT verification to prevent alg: none and HMAC/RSA key confusion attacks.
#JWT Security#Signature Forgery#Tokens#Intermediate
Back to all Web Security & Cyber Defense Questions→