Critical ThreatAuthentication & TokensCWE-287
JWT Security Hardening: Signature Exclusion & Algorithms
Master JWT security hardening by preventing signature exclusion, algorithm confusion, and implementing proper key storage techniques.
Vulnerability Overview
Improper JWT validation can allow attackers to forge tokens by removing signatures or changing algorithms.
Attackers manipulate the header (e.g., alg: none) or use public keys as HMAC secrets to bypass verification.
Vulnerable Code
jwt.verify(token, secret); // No algorithm enforcedFails to enforce a specific algorithm, allowing downgrade attacks.
Remediated Code
jwt.verify(token, secret, { algorithms: ['RS256'] });Explicitly enforces the expected algorithm.
Hardening Rules
- 1Enforce algorithms
- 2Use strong keys
- 3Set short expirations
Frequently Asked Questions
What is alg: none?
A testing feature often left enabled that accepts unsigned tokens.