📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What is the JWT algorithm confusion attack, and how do ASP.NET Core and Microsoft.IdentityModel protect you against alg none and RS256/HS256 confusion?

Intermediate Theory Intermediate

🎯 Key points

  • alg none skips the signature in naive libraries
  • RSA public key bytes used as an HS256 secret
  • Key types bound to algorithms in Microsoft.IdentityModel
  • RequireSignedTokens default true
  • Pin ValidAlgorithms; keys from issuer metadata
  • Never hand-roll validation

⏱ 30-second answer

Older JWT libraries chose the verification algorithm from the token's own alg header. With alg: none an attacker removed the signature and the library skipped verification. With RS256/HS256 confusion the attacker took the server's RSA public key (published in the JWKS), used its bytes as an HMAC secret to sign a forged token with alg: HS256, and a library that passed 'the key' to whatever algorithm the header named verified it successfully. Microsoft.IdentityModel ties algorithms to key types (an RsaSecurityKey can't be used to verify an HMAC signature), RequireSignedTokens (default true) rejects unsigned tokens, and you should pin ValidAlgorithms to what your issuer actually uses. Beyond that: get keys from the issuer's metadata rather than configuring them by hand, validate issuer and audience, and never write your own validation.

🔍 What the interviewer is checking

Checks awareness of classic JWT validation attacks

↩ Usually asked after

More in Authentication

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me