Reputation: 53
Imagine this attack
Questions
What prevents the attacker intercepting the first call to the authorization server? This is what is meant to make authorization code + PKCE more secure than implicit flow.
Perhaps it does not matter if the call is intercepted because the code-challenge is hashed and therefore the attacker does not have the code-verifier required for the 2nd call. But what if the code-challenge is not hashed?
Upvotes: 5
Views: 2511
Reputation: 86779
PKCE is meant to address the threat of the access token / authorization code being leaked from URL, which is relatively likely compared to an attacker intercepting SSL traffic:
That said, its recommended that the code challenge be a SHA256 hash of the code verifier, therefore even if the attacker were to intercept the code challenge, they would be unable to complete the token exchange without being able to reverse SHA256.
Also see: What is PKCE actually protecting?
Upvotes: 3
Reputation: 23486
PKCE is meant to assure that the client that requested the user to be authenticated, it the same client that exchanges the authorization code for an access token.
All communication with the authorization server is using HTTPS, go it's difficult to intercept. But some mobile platforms allow (malicious) apps to register the same redirect_uri as the legitimate client. This meant that when the authorization server redirected back to the client with the authorization code, both the legitimate client and the malicious client would be called with the code. This allowed the malicious client to exchange the code for an access token, since no client authentication is done.
PKCE solves this by including the code_challenge in the authentication request, which is a hash of the code verifier. It then requires the actual verifier in the token exchange call. The malicious client does not have the verifier and can therefore not authenticate itself and thus not exchange the code for a token.
Upvotes: 4