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
Plain Ruby error from JWT.decode for a non-numeric exp/nbf or a payload that is not a JSON object #793
I've run into a problem where JWT.decode raises NoMethodError and TypeError instead of JWT::Error for specific tokens. Specifically, when a correctly signed token carries an exp or nbf that is a Boolean, Array or Hash, or a payload that is not a JSON object. The error escapes rescue JWT::DecodeError, so a caller that rescues the gem's errors to reject the token gets an unhandled error instead.
Seen on jwt 3.3.0 with Ruby 4.0.10.
Reproduction
JWT.encode refuses a non-numeric exp, so the tokens are signed by hand.
exp Array: NoMethodError: undefined method 'to_i' for an instance of Array
exp true: NoMethodError: undefined method 'to_i' for true
nbf Hash: NoMethodError: undefined method 'to_i' for an instance of Hash
payload Array: TypeError: no implicit conversion of String into Integer
payload Integer: TypeError: no implicit conversion of String into Integer
payload null: NoMethodError: undefined method '[]' for nil
Expected
Each case raises a JWT::DecodeError subclass, for example JWT::InvalidPayload for a non-numeric exp or nbf and JWT::MalformedTokenError for a payload that is not a JSON object.
Activity