ruby-jwt icon indicating copy to clipboard operation
ruby-jwt copied to clipboard

ExpiredSignature should perhaps not be a subclass of DecodeError

Open joelmichael opened this issue 2 years ago • 5 comments

This caused some confusion for us. If a JWT token is expired, this doesn't mean it failed to decode. We were checking for when JWT tokens don't decode correctly due to a formatting error, but this was also catching the case where a (perfectly legitimately encoded) JWT token simply had expired. Thus it affected our error handling for expired tokens unexpectedly.

image

joelmichael avatar Jul 23 '24 17:07 joelmichael

Currently all the errors are subclasses of this DecodeError, so your suggestion (that is perfectly reasonable) applies for all the errors. I agree that some kind of intermediate subclassing logic would make sense.

Think revamping the error hierarchy could be a chore for the next major release, to allow possible breaking changes.

anakinj avatar Jul 23 '24 18:07 anakinj

Thanks @anakinj! I just wanted to second this - because we use Rails' rescue_from on both DecodeError in general and ExpiredSignature in particular but have different handling for each error. Because ExpiredSignature inherits from DecodeError we now have to order the rescue_from blocks in a specific order which feels pretty brittle.

Appreciate this library, which has been great overall!

jkarmel avatar Jul 24 '24 16:07 jkarmel

Structure to the errors would be great. Some help trying to create some hierarchy appreciated.

anakinj avatar Sep 29 '24 20:09 anakinj

Some Friday night fiddling in https://github.com/jwt/ruby-jwt/pull/722 related to this. Would appreciate if @jkarmel or/and @joelmichael would be able to take a look. Goal was to keep the errors backwards compatible.

anakinj avatar Mar 27 '26 19:03 anakinj

Hiya - we moved to Python for our project so we aren't actively developing on this anymore. Appreciate this awesome lib though!

jkarmel avatar Mar 31 '26 20:03 jkarmel