-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JWT::ExpiredSignature raised for non-JSON payloads #350
Comments
Did you turn off the token expires validation check? You can do that by passing options to |
Indeed by setting |
@volmer the JWT spec (https://tools.ietf.org/html/rfc7519) specifies that the payload is a JSON object. If the payload is not parseable to a JSON object, then it is not a valid JWT.... The specific method you're using - I would agree that the specific error raised may be incorrect, but would suggest that the There is a good case for splitting out a |
Very good point @danleyden. I think in the end what I'm really looking for is a pure |
@volmer - something to consider (in case you don't find what you're looking for)... With some (probably not too much) effort https://github.com/jwt/ruby-jwt/blob/master/lib/jwt/decode.rb could be refactored. I think the key thing that you would need to do is to split that in to two classes... something like below (not tested) class JWSDecode
# everything in the current decode class except:
def payload
@payload ||= JWT::Base64.url_decode(@segments[1])
end
# no verify_claims method
# this method is very similar to the original... only one line different
def decode_segments
validate_segment_count!
if @verify
decode_crypto
verify_signature
# verify_claims is not needed for JWS
end
raise(JWT::DecodeError, 'Not enough or too many segments') unless header && payload
[payload, header]
end
end
class Decode << JWSDecode
# the only thing this needs to do extra is to verify the claims and ensure that the payload
# is valid
def decode_segments
payload, header = *super
verify_claims if @verify
[payload, header]
end
# this is the original method
def verify_claims
Verify.verify_claims(payload, @options)
end
# in this class, the payload must be decoded as a token
def payload
@payload ||= parse_and_decode @segments[1]
end
end |
For anyone getting here by searching for the error in the title, here is the 2021-09 current configurations you can pass. |
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: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.
The text was updated successfully, but these errors were encountered: