Skip to content
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

End of Toshl Oauth flow sometimes fails at the state parsing stage #12

Closed
mzogheib opened this issue Mar 27, 2018 · 3 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@mzogheib
Copy link
Owner

mzogheib commented Mar 27, 2018

Looks like the queryParams parser is not carrying out uri decoding properly but this only happens sometimes, e.g. = at the end of the base64 encoded string is returned as %25D or whatever.

Can recreate with the following state object
{id: "toshl", token: "z38ph0sozo"}

@mzogheib mzogheib added the bug Something isn't working label Mar 27, 2018
@mzogheib mzogheib self-assigned this Mar 27, 2018
@mzogheib
Copy link
Owner Author

mzogheib commented May 12, 2018

@mzogheib
Copy link
Owner Author

mzogheib commented May 12, 2018

Here's what's happening:

  1. {id: "toshl", token: "z38ph0sozo"} is first Base 64 encoded to eyJpZCI6InRvc2hsIiwidG9rZW4iOiJ6MzhwaDBzb3pvIn0='. Note the = on the end, which is to pad the string to its required length
  2. This Base 64 encoded value is then uriEncoded to be added as the state query param: encodeURIComponent('eyJpZCI6InRvc2hsIiwidG9rZW4iOiJ6MzhwaDBzb3pvIn0=') -> eyJpZCI6InRvc2hsIiwidG9rZW4iOiJ6MzhwaDBzb3pvIn0%3D. Note = is encoded as %3D
  3. The final url that the user is redirected to is https://toshl.com/connect/app/?client_id=98e9ca50-9b4c-432d-88eb-68a13ac3dceb30e117cd-9614-464f-90af-58979a9e6c11&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A3000&state=eyJpZCI6InRvc2hsIiwidG9rZW4iOiJ6MzhwaDBzb3pvIn0%3D
  4. On Toshl auth page, user authorises the app and is redirected back to http://localhost:3000/?code=a0452fb5-9e90-4c1c-b3a4-4a1abcc414509954826d-1089-48e0-ab5e-93be0ae1ec5a&state=eyJpZCI6InRvc2hsIiwidG9rZW4iOiJ6MzhwaDBzb3pvIn0%253D. Note %253D on the end. It appears Toshl is encoding the % to %25 in the state param it received.
  5. Client then uriDecodes this the state param value, expecting it to be a Base 64 encoded string. decodeURIComponent('eyJpZCI6InRvc2hsIiwidG9rZW4iOiJ6MzhwaDBzb3pvIn0%253D') -> eyJpZCI6InRvc2hsIiwidG9rZW4iOiJ6MzhwaDBzb3pvIn0%3D.
  6. This final value cannot be Base 64 decoded. The %3D breaks it.

@mzogheib
Copy link
Owner Author

mzogheib commented May 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant