Hello!
I'm working with tokens produced in JWS to sign payloads that are not necessarily JSON, as allowed by the JWS spec.
I noticed however that when trying to decode a JWS that has a String payload that includes the "exp" substring, the JWT gem raises a JWT::ExpiredSignature error:
irb(main):007:0> rsa_private = OpenSSL::PKey::RSA.generate(2048)
irb(main):008:0> rsa_public = rsa_private.public_key
irb(main):009:0> token = JWT.encode('string payload with exp substring', rsa_private, 'RS256')
irb(main):010:0> JWT.decode(token, rsa_public, true, algorithm: 'RS256')
Traceback (most recent call last):
12: from /Users/volmer/.rubies/ruby-2.7.1/bin/irb:23:in `<main>'
11: from /Users/volmer/.rubies/ruby-2.7.1/bin/irb:23:in `load'
10: from /Users/volmer/.rubies/ruby-2.7.1/lib/ruby/gems/2.7.0/gems/irb-1.2.3/exe/irb:11:in `<top (required)>'
9: from (irb):10
8: from /Users/volmer/.gem/ruby/2.7.1/gems/jwt-2.2.1/lib/jwt.rb:28:in `decode'
7: from /Users/volmer/.gem/ruby/2.7.1/gems/jwt-2.2.1/lib/jwt/decode.rb:27:in `decode_segments'
6: from /Users/volmer/.gem/ruby/2.7.1/gems/jwt-2.2.1/lib/jwt/decode.rb:64:in `verify_claims'
5: from /Users/volmer/.gem/ruby/2.7.1/gems/jwt-2.2.1/lib/jwt/verify.rb:20:in `verify_claims'
4: from /Users/volmer/.gem/ruby/2.7.1/gems/jwt-2.2.1/lib/jwt/verify.rb:20:in `each'
3: from /Users/volmer/.gem/ruby/2.7.1/gems/jwt-2.2.1/lib/jwt/verify.rb:22:in `block in verify_claims'
2: from /Users/volmer/.gem/ruby/2.7.1/gems/jwt-2.2.1/lib/jwt/verify.rb:15:in `block (2 levels) in singleton class'
1: from /Users/volmer/.gem/ruby/2.7.1/gems/jwt-2.2.1/lib/jwt/verify.rb:41:in `verify_expiration'
JWT::ExpiredSignature (Signature has expired)
Apparently the gem is assuming the payload is always a JSON, which is not always true. What would be the best fix for this case?
Thank you in advance.
Hello!
I'm working with tokens produced in JWS to sign payloads that are not necessarily JSON, as allowed by the JWS spec.
I noticed however that when trying to decode a JWS that has a String payload that includes the "exp" substring, the JWT gem raises a
JWT::ExpiredSignatureerror:Apparently the gem is assuming the payload is always a JSON, which is not always true. What would be the best fix for this case?
Thank you in advance.