-
-
Notifications
You must be signed in to change notification settings - Fork 436
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
fix(oauth): sort parameters in a standard way as per the specs #721
fix(oauth): sort parameters in a standard way as per the specs #721
Conversation
the signature is now calculated a bit differently to match other implementations. BREAKING CHANGE: existing OAuth applications may encounter some issues leading to `invalid_signature` 401 errors from Magento due to the removal of natural sorting for parameters when generating the signature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems "using lexicographical byte value ordering" from the official spec is pretty clear.
Thanks for the feedback. |
Yes, thus my approval. :) It is hard to say if anyone is relying on this incorrect behavior but as this hasn't been reported yet I would say the chances are very slim and it is better to fix it and make it correct than leave it incorrect. |
Awesome. Thanks for your quick feedback! |
Hi! It's been a few months since @colinmollenhour's approval. Would it be possible to have a 2nd review for this PR please? It is a blocking issue for headless implementations of M1 (that has to be patched in userland code for now) (ping @sreichel @Flyingmana) |
Thank you very much! 🎉 |
BREAKING CHANGE: existing OAuth applications may encounter some issues leading to `invalid_signature` 401 errors from Magento due to the removal of natural sorting for parameters when generating the signature
Hi folks!
We have detected what seems to be a flaw in the way the OAuth signature is calculated to ensure the received request is correct.
From our understanding it seems to be a bug, but I’d really appreciate if someone more used to this standard could have a look :)
The symptom is: 401 errors with an
invalid_signature
error for requests containing numerical indexes.Example:
Given the following params:
limit
=>21
filter[0][attribute]
=>sku
filter[0][in][0]
=>msj000
filter[0][in][1]
=>msj001
filter[0][in][2]
=>msj002
filter[0][in][3]
=>msj000xs
filter[0][in][4]
=>msj000xl
filter[0][in][5]
=>msj003xs
filter[0][in][6]
=>msj003xl
filter[0][in][7]
=>msj006
filter[0][in][8]
=>msj007
filter[0][in][9]
=>msj008
filter[0][in][10]
=>msj006xl
filter[0][in][11]
=>msj006xs
Magento will use
natsort
to sort them before generating the signature. The order will thus be:filter[0][attribute]
=>sku
filter[0][in][0]
=>msj000
filter[0][in][1]
=>msj001
filter[0][in][2]
=>msj002
filter[0][in][3]
=>msj000xs
filter[0][in][4]
=>msj000xl
filter[0][in][5]
=>msj003xs
filter[0][in][6]
=>msj003xl
filter[0][in][7]
=>msj006
filter[0][in][8]
=>msj007
filter[0][in][9]
=>msj008
filter[0][in][10]
=>msj006xl
<------filter[0][in][11]
=>msj006xs
<------limit
=>21
The library we use in nodeJS uses a standard sort (see https://github.com/ddo/oauth-1.0a/blob/d2ec1e2820ff60e99da4444deae630d8eac31d91/oauth-1.0a.js#L366) and will generate a signature with the following order:
filter[0][attribute]
=>sku
filter[0][in][0]
=>msj000
filter[0][in][1]
=>msj001
filter[0][in][10]
=>msj006xl
<-------filter[0][in][11]
=>msj006xs
<-------filter[0][in][2]
=>msj002
filter[0][in][3]
=>msj000xs
filter[0][in][4]
=>msj000xl
filter[0][in][5]
=>msj003xs
filter[0][in][6]
=>msj003xl
filter[0][in][7]
=>msj006
filter[0][in][8]
=>msj007
filter[0][in][9]
=>msj008
limit
=>21
As a consequence, signatures will not match…
Resources
Our researches led us to the OAuth spec which says:
From our understanding it seems that the Zend_Oauth is the wrong implementation…
Also, it seems that other implementations such as https://github.com/thephpleague/oauth1-client/blob/master/src/Client/Signature/HmacSha1Signature.php#L73 are also sorting parameters as the node library linked above.
Breaking change
This IS a breaking change, also I am not sure whether you think it could be merged or not in its current state.
Tests
This is my first contribution here, so I am relying on the CI process to see if it breaks things. I could add tests later if you think it is necessary.
Please let me know if you need further information.