Skip to content

Why does the existence of a signature algorithm entail a required verification? #24

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

Closed
TheQuantumPhysicist opened this issue May 31, 2018 · 9 comments

Comments

@TheQuantumPhysicist
Copy link
Contributor

TheQuantumPhysicist commented May 31, 2018

In my code, I have parts where I need to extract the data from a token without verifying it (and without the key being available). Basically because the verification was done before and the token was authorized.

Now check out this part of the code:

if (dparams.verify) {

In line 698, the code gets the message from the user that a verification is not necessary, so that block is skipped. But then in line 709, this block completely ignores whether the user wants to verify, and simply checks the header and whether there's an algorithm associated with the header. This basically means that it's impossible to extract information from a token without a key. For me, I'm getting an error code DecodeErrc::KeyNotPresent, because there's no key associated with the object, although I'm not willing to verify.

The fix I suggest is to put this block inside the other block in line 698. Only if the user is willing to verify, then the algorithm should be checked.

The reason I haven't created a pull-request for this is that I'm not sure why this was done this way, and there's the possibility that there's something I'm misunderstanding here. So kindly explain whether my reasoning is correct.

Best.

@arun11299
Copy link
Owner

How about using "NONE" algorithm for such cases ? Setting an algorithm and not using a key does not sound a realistic scenario to me.

@TheQuantumPhysicist
Copy link
Contributor Author

The thing is that the token is already there. It's not my choice of what algorithm goes into the token anymore. What I'd like to do is just decode an existing token. You're assuming that the dev who wants to extract contents from a token also has the power to decide the algorithm, which is not generally the case, unless one has to tamper with the token before extracting data from it. Also remember that verification costs computation that may not be necessary depending on the application.

What puzzles me in all this is: Why is it OK to ignore the dev's will to verify? Isn't that the point of having the parameter params::verify(false)? Is there something I'm missing here?

@arun11299
Copy link
Owner

arun11299 commented May 31, 2018

So the payload of the token anyways cannot be decoded without the key. But the user can still get the decoded header which is the only thing that can be decoded in this case.
Am I missing something ?

@TheQuantumPhysicist
Copy link
Contributor Author

I feel what you said is a little ambiguous, but I guess my answer is yes. That's the situation. In the current state, the payload is unreachable through the API if no key was set, and in general, why is someone who wants to read the payload required to enter a key? I don't understand this.

Please remember that the payload is not encrypted. So decoding has nothing to do with the key being present. The algorithm is just for the signature.

@arun11299
Copy link
Owner

Payload is also available in decoded form in the object. Sorry I missed that.

@arun11299
Copy link
Owner

I will provide a fix to not do the signature verification.

Repository owner deleted a comment from TheQuantumPhysicist May 31, 2018
@arun11299
Copy link
Owner

@TheQuantumPhysicist Sorry I accidentally deleted your comment instead of mine and I dont know how to undo. Can you please add it back ? Really sorry for that.

@TheQuantumPhysicist
Copy link
Contributor Author

TheQuantumPhysicist commented May 31, 2018

I was just suggesting that you review my suggestion on how to fix this. It just costs a cut and paste.

@arun11299
Copy link
Owner

Yes thats what needs to be done. I have few tests to fix which depended on that.

interfector18 pushed a commit to interfector18/cpp-jwt that referenced this issue Jun 1, 2020
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

No branches or pull requests

2 participants