-
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
Missing HMAC_SECRET When HMAC Encoding Not Raising Proper Error #526
Comments
Agree that it should be handled better. Think the behaviour has changed somewhere along the way. |
I'd be happy to submit a PR if I can get some guidance on what is expected. Would the following be appropriate to raise in https://github.com/jwt/ruby-jwt/blob/main/lib/jwt/algos/hmac.rb? sign:
verify:
|
@jonmchan |
@excpt yes, I will also write the tests too. Is the error and behavior I describe above acceptable? |
Now thinking some more about this I think the behaviour is intended (#312). Also to be noted that the behaviour (EVP_PKEY_new_mac_key error) with an empty key is is now fixed for the openssl gem and OpenSSL 3.0. ruby/openssl#538 Also maybe the behaviour should be:
But this behaviour change probably needs to happen in a major version with documented breaking changes. |
@anakinj I would argue that as it stands, it is very inconsistent behavior. We had a hard time tracking this error down because I wasn't getting any errors on my linux machine while my coworkers on mac with different versions of openssl were seeing the error. I believe this can be extremely frustrating for developers to track down. This is already "broken" and I would argue a minor version fix would be appropriate because if someone was using nil values and they upgrade OpenSSL, it would magically break for them at that point. This at least needs to be documented, which I suppose is already accomplished by this issue. I am still amicable to submit a PR if we can have some consensus on what the behavior should be and you guys can release it in whatever version you deem fit. |
I agree with you that the current way it behaves with different OpenSSL versions is not the most optimal. The challenge is what the underlying OpenSSL 3.0 functionality in Ruby is supporting. There are other similar changes in OpenSSL 3.0 that are affecting what you can and cannot do via the openssl gem interfaces. For example generating RSA keys from parameters is very restricted currently in the openssl gem combined with OpenSSL 3.0 (#523). I would not like to change the current behaviour with OpenSSL 1.1 and signing with a empty string as the key in a minor version of this gem. The unfortunate thing is that currently it's not possible to do have the exact same with certain OpenSSL 3.x versions, apparently the behaviour will be different depending on what openssl version you are using. Maybe the best would be to change the behaviour for everyone and not allow signing with a empty key, as suggested. We have a history breaking stuff doing these kind of "trivial" changes so I therefore I would like to play it safe. |
I totally can respect that. What about this proposal for a minor fix: Rescue the Pros:
|
That is a great idea. Better feedback for OpenSSL 3.0 users. |
According to the documentation, when utilizing the HMAC algorithm, a JWT::DecodeError should be raised if the hmac_secret is not provided.
https://github.com/jwt/ruby-jwt#hmac
As it stands, there is inconsistent behavior between what version of Openssl is installed on the system. For example, for the following systems:
This should not be succeeding. Not sure what is being used to generate the HMAC.
However, on newer versions of OpenSSL, we observe the following:
Neither of these is the proper
JWT::DecodeError
as defined by the documentation. Catching this properly would be good.The text was updated successfully, but these errors were encountered: