Assess your understanding of JWT signature verification and essential security checks in token-based authentication systems. This quiz covers signing algorithms, signature validation, vulnerabilities, and best practices for robust JWT security.
In the context of JWT signature verification, why is it crucial for an application to always verify the token’s signature before trusting its claims in an API scenario?
Explanation: Verifying the JWT signature guarantees that a trusted party issued the token and that its contents remain unchanged, which is essential for security. Compressing token size is unrelated to signature verification. Token expiration is managed by claims, not by signature checking itself. Generating random tokens is also not a function of signature verification, but of token creation.
Which of the following best describes the 'algorithm confusion' vulnerability when validating JWTs in an authentication server?
Explanation: Algorithm confusion occurs when a server inadvertently accepts unsigned tokens by permitting 'alg: none', allowing attackers to bypass authentication. Simply refusing HMAC algorithms is not the core issue. Ignoring expiry or always using elliptic curve verification does not directly represent this vulnerability; those are unrelated misconfigurations.
When validating JWTs signed with asymmetric keys (for example, RS256), what is the most secure method for the server to obtain the public key needed for signature verification?
Explanation: Best practice is for the server to obtain and manage the public key securely from a trusted source, ensuring authenticity. Generating a new key on every request breaks the trust model and is unnecessary. Allowing the JWT payload to provide the public key lets an attacker specify their own verification key, defeating security. Using any public key on the server ignores proper key management and may result in validation failures or vulnerabilities.
If an application receives a JWT and detects that its signature is invalid during verification, what should it do next for proper security?
Explanation: An invalid JWT signature means the token cannot be trusted; the correct action is to reject it and deny access. Stripping the signature and trusting the payload defeats the purpose of signatures. Re-signing the token is insecure since the original authenticity is lost. Automatically changing the algorithm does not fix or validate the original token.
Which of the following is considered a best practice for performing robust security checks on JWTs in production environments?
Explanation: Best practice is to validate both the cryptographic signature and standard claims to ensure the token is genuine and not expired. Storing payloads unencrypted client-side can expose sensitive information. Omitting claims like 'iat' and 'exp' can lead to replay or abuse. Accepting tokens solely based on structure ignores authentication and verification requirements.