1 minute read · security
JWTs are widely misused. Here are the most dangerous mistakes and how to fix them.
Use RS256 Not HS256
// Sign with private key
const token = jwt.sign({ sub: userId }, privateKey, { algorithm: 'RS256', expiresIn: '15m' });
// Verify with public key — safe to distribute publicly
jwt.verify(token, publicKey, { algorithms: ['RS256'] });Never Accept 'none' Algorithm
jwt.verify(token, secret, { algorithms: ['RS256'] }); // whitelist onlyShort Expiry + Refresh Tokens
Access token: 15 minutes. Refresh token: 7 days, stored httpOnly cookie.
Conclusion
RS256, short expiry, httpOnly cookies. These three rules prevent most JWT attacks.