A developer uses JSON Web Tokens and stores the role claim ('role': 'admin') in the payload. An attacker modifies the payload and changes the role to 'admin'. The server uses asymmetric RS256 signing. Will this attack succeed?
- A.Yes - JWT payloads are only base64 encoded and can be changed freely
- B.Yes - if the server does not check the 'alg' header, the attacker can switch to 'none'
- C.No - with RS256, the signature is created using the private key. Modifying the payload invalidates the signature. The server verifies the signature using the public key; a modified payload will produce a signature mismatch and the JWT will be rejected
- D.It depends on whether the role claim is in the header or payload
Why C is correct
RS256 uses a private/public key pair. The issuer signs with the private key; verifiers check with the public key. If a payload is modified without access to the private key, the signature becomes invalid. The server's verification step will detect the mismatch and reject the token. The distinct attack (alg:none) exploits servers that don't validate the algorithm header - those servers can be tricked into skipping signature verification entirely, not bypassing a valid RS256 signature.
Know someone studying for Web App Fundamentals? Send them this one.