This repository has been archived by the owner on Dec 14, 2017. It is now read-only.
Fixes a potential authentication vulnerability #54
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was going to copy your code for my own use (needing this exact same scenario in my OWIN app) but fortunately had just come across this piece of advice in my research.
I saw the correct approach on this blog post earlier, and put two and two together. :) I may be wrong (I'm no expert!), but I think the scenario here is that an attacker could, reasonably, obtain the public key you were using to encrypt the sensitive data (e.g. the session cookie) with. For example, if an IdentityServer is using the SSL certificate to also protect the data, then the attacker already has the public key. In that case the attacker could craft any desired token and likewise encrypt it with the public key, and the original code here would accept it as genuine since it is able to decrypt it. The PR fixes this by first signing the plaintext -- with the private key -- before encrypting it (again with the private key).
Just a suggestion. If that's actually wrong, or there's a better way to do this, please let me know! I'm still learning. :)