Q14: Explain the JWT `alg: none` security vulnerability and how to defend against it.
The JWT specification includes an alg: none option intended for debugging or unsecured environments. In early JWT libraries, if an attacker modified an existing token payload (e.g., changing role: user to role: admin), stripped the signature section, and set "alg": "none" in the header, naive verification logic would accept the token as valid without checking the signature.
Defense:
- Never allow the verification engine to dynamically accept the
algheader from the unverified incoming token. - Explicitly enforce expected algorithms in server verification configurations (e.g.,
jwt.verify(token, key, { algorithms: ['RS256'] })).
Key Takeaways
The
alg: noneexploit allows attackers to bypass signature validation entirely.Hardcode explicitly allowed verification algorithms in server configuration.