-
Notifications
You must be signed in to change notification settings - Fork 133
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
HMAC validation is broken in 6.0.4+ on PHP 5.5 and below #82
Comments
hey @curtisdf, ouch, sorry to hear that :( would you mind adding a test to reproduce the bug? I thought we already had something that would get us covered on travis, but apparently we missed this. Once we have it, it's easier for us to look into it. cheers! |
I tried for over 2 hours tonight to come up with a test that would demonstrate this problem, but for some reason I can't. But it still fails in our codebase using the sample code I gave above. I've also checked again using PHP 5.6. Inside
even though If $known and $input are both equal to: If $known and $input are both equal to: If $known and $input are equal to: That's about the best I can say right now. :-( I hope this provides some meaningful clues. |
I might have found the smoking gun. I played around a bit with So, is your test suite in TravisCI using mb_internal_encoding() == "ISO-8859-1"? I don't understand why the need to call mb_strlen() once with '8bit' and once with whatever random default charset PHP happens to be using. Is this intended? If not, what should it be here? Should this be hard-coded to "ISO-8859-1"? As in this below?
|
@curtisdf as far as I know there are no specific reason, I think we just missed the second parameter sorry. |
Awesome, thanks @cirpo! |
@curtisdf I reopened the issue because there is no stable release out with the fix :) |
Oh. Okay I see. |
@curtisdf could you please try 6.1.1? It should fix the issue. Thanks |
Works for me. Thanks @cirpo!! :-D I really appreciate your responsiveness over the weekend. One never knows when working with 3rd-party libraries how fast they will be able to respond if any issues come up. |
😆 |
Ha ha, you guys are funny. :-P I've been accused of being a bot myself too. |
closing this now :) thanks guys |
Release 6.0.4 introduced a change in
HMAC::timingSafeEquals()
which usesmb_strlen()
to calculate string lengths when available, instead ofstrlen()
. Unfortunately, this seems to have broken the function. The problem only becomes apparent in PHP 5.5 and below, since in 5.6.0 and onward it uses PHP's built-inhash_equals()
function instead. Commenting out lines 54-57 inNamshi/JOSE/Signer/OpenSSL/HMAC.php
fixes it for me:But the original commit by @cirpo which introduced this code indicates that
strlen()
also has problems. I'm not sure what the real fix should be...?FWIW, here's how I am generating tokens:
And here is what I'm doing to validate them:
Any thoughts?
The text was updated successfully, but these errors were encountered: