part 5Security: the attack behind each rule·lesson 5.1 of 5·2 min read
Authorization code theft and interception
The OAuth authorization code travels in a redirect URL, and anything that passes through the browser can be seen. This lesson shows where an authorization code can leak, how an interception attack plays out, and the three defenses MCP authorization requires: PKCE, an exact redirect_uri, and short-lived single-use codes.
In this lesson
Identify the places where an authorization code can be stolen.
Name the three defenses and what each one covers.
Where the code leaks
The code travels in a redirect URL. It can leak through:
Another local app that listens on the same port or registers the same custom URL scheme.
A badly validated redirect_uri that points to the attacker.
Without PKCE, this step would have returned a token.
The three defenses
Defense
What it covers
PKCE (mandatory)
An intercepted code is useless without the verifier
Exact redirect_uri, localhost or HTTPS
The AS does not send the code where it should not go
Single-use, short-lived code
A copy seen in a log no longer works
The last two try to stop the attacker from getting the code at all; PKCE makes sure that, if they do get it, it is worthless. See lesson 2.5 for how PKCE works and lesson 2.7 for the redirect_uri rules.
Summary
The code travels over the front channel and can leak.
PKCE makes it useless; an exact redirect and a short lifetime reduce exposure.
quiz · 3 questions
1. Which defense still protects you even if the attacker obtains the code?
The others try to stop the attacker from getting the code; PKCE makes the code useless to them if they do.
2. A malicious local app intercepts the redirect and calls the token endpoint with the code. Why does it fail when PKCE is used?
The AS compares the code_verifier with the code_challenge sent at the start; without the verifier, the exchange is rejected with invalid_grant.
3. What does making authorization codes single-use and short-lived protect against?
A code that has already been used or has expired cannot be redeemed, so a leaked copy is worthless.