You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JWT::EncodedToken calls key_finder before checking the token's algorithm #781
JWT.decode rejects a token with a disallowed alg before looking up a key. JWT::EncodedToken#verify_signature! calls key_finder first, so tokens that could never pass still trigger the lookup.
Signature verification still fails correctly, so this isn't a bypass. The concern is that key finders often fetch a remote JWKS, which lets an unauthenticated alg: none or HS256 token cause outbound requests when the application expects only RS256.
rsa=OpenSSL::PKey::RSA.generate(2048)token=JWT.encode({'sub'=>'x'},'secret','HS256')calls=0finder=lambda{ |_token|
calls += 1rsa.public_key}JWT::EncodedToken.new(token).verify_signature!(algorithm: 'RS256',key_finder: finder)# => JWT::VerificationError: Signature verification failed (calls == 1)JWT.decode(token,nil,true,algorithm: 'RS256'){ |_header| rsa.public_key}# => JWT::IncorrectAlgorithm: Expected a different algorithm (block not called)
Reproduced on 3.3.1, and an alg: none token behaves the same way. lib/jwt/encoded_token.rb is unchanged on main.
Cause:EncodedToken#valid_signature? evaluates key_finder.call(self) before creating the verifiers from the allowed algorithms.
Suggestion: When algorithm: is given, check the token's alg against it before calling key_finder, and raise JWT::IncorrectAlgorithm if it isn't allowed. Calls that rely on a JWK to supply the algorithm would need to keep working.
Activity