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

Fix token verification where original token was encoded with whitespace #110

Merged
merged 1 commit into from
Dec 5, 2016
Merged

Conversation

jshayes
Copy link
Contributor

@jshayes jshayes commented Nov 1, 2016

Fixes #109

Currently, the original token string it not stored anywhere. This token is decoded and those decoded values are stored. When you try to verify the signature, the header and payload are then re-encoded and checked against the signature. The issue with this is that the original formatting is lost when re-encoding the token. This change uses the original token, if present, to verify the signature against.

Currently, the original token string it not stored anywhere. This token is decoded and those decoded values are stored. When you try to verify the signature, the header and payload are then re-encoded and checked against the signature. The issue with this is that the original formatting is lost when re-encoding the token. This change uses the original token, if present, to verify the signature against.
return sprintf('%s.%s', $parts[0], $parts[1]);
}

return $this->generateSigninInput();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @jshayes thanks for this! Any reason we would need to fallback to the original generateSigninInput?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@odino I just did it this way to not impact the existing interface. If the token is generated using the load method, then it should never reach this line. However, it is possible to create the token without going through the load method, in which case it is possible $this->originalToken was not set and it will fallback to the original generateSigninInput method.

I can handle this differently if you'd like.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how can we create the token without going through the load method? Sorry, just trying to remember :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the methods to build the state of the token are publicly exposed, so you can call them to create a token manually. For example, you can create a new instance of JWS and then call setHeader and setPayload to build the token.

@odino odino merged commit 89a24d7 into namshi:master Dec 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants