Loading...
Loading...
JWT verification accepts "none" algorithm, allowing tokens to be forged.
1const jwt = require('jsonwebtoken');23function verifyToken(token) {4 const decoded = jwt.decode(token, { complete: true });5 const algorithm = decoded.header.alg;67 return jwt.verify(token, secret, { algorithms: [algorithm] });8}
The application trusts the algorithm specified in the JWT header. An attacker can change the algorithm to "none" and remove the signature, creating a valid-looking token that bypasses verification entirely.
Attacker modifies JWT header to bypass signature verification
Original token:
eyJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOjV9.signature
Forged token (alg: none):
eyJhbGciOiJub25lIn0.eyJ1c2VySWQiOiJhZG1pbiIsInJvbGUiOiJhZG1pbiJ9.Decoded forged token:
Header: {"alg":"none"}
Payload: {"userId":"admin","role":"admin"}
Signature: (empty)
✓ No signature to verify
✓ Server accepts attacker as admin
✓ Complete authentication bypass