Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Redirect URI validation

The redirect URI decides where an authorization code lands. This lesson follows a code that a carelessly built authorization server sends to the wrong place, the matching shortcuts that let it happen, and what the photo service and the printer each check so that Ava's codes reach only the printer.

Sending the code somewhere else

An authorization code goes wherever the authorization request asks for it, as long as the authorization server agrees. The printer writes that request, but anyone can write one. It is an ordinary URL, and nothing stops an attacker from copying the printer's client ID into a request of their own and naming a different return address.

Redirects and authorization codes said the photo service compares the requested redirect URI with the registered one exactly, refusing even an added trailing slash. That strictness can look fussy until you see what happens to Ava Archer, who prints her albums with the printer, at a version of the photo service that compares less carefully.

All domains and codes in these examples are fictional. The attacker begins by building a link to the photo service's authorization endpoint:

https://auth.photos.example/authorize
  ?response_type=code
  &client_id=photo-printer
  &redirect_uri=https%3A%2F%2Fprinter.example.attacker.example%2Foauth%2Fcallback
  &scope=photos.read
  &state=demo-attacker-state-1
  &code_challenge=13TUFxsJi_vyUQcynxTDC61Vw6HLxqvpa2jIzPC_fBc
  &code_challenge_method=S256

Everything except the redirect URI is what the printer itself would send. The challenge is one the attacker computed from a verifier of their own.

  1. The attacker sends Ava the link, dressed up as an offer: "Print your summer album free this week."
  2. Ava is already signed in at the photo service. The consent screen names Photo Printer, because the request carries the printer's client ID, and she approves.
  3. This careless version of the photo service checks the redirect URI with a shortcut: does it begin with https://printer.example? It does, so the service sends Ava's browser, with a fresh code, to printer.example.attacker.example, a name under the attacker's domain.
  4. The attacker's server reads the code from the incoming request.

What the code is worth depends on the client it was issued to. Had the request named the printer's phone app, photo-printer-app, the attacker could redeem the code at once. A public client sends only its client ID to the token endpoint, and PKCE offers no protection here, because the attacker wrote the request and holds the verifier behind its challenge. The printer's website is a confidential client, so the attacker cannot redeem the code without the printer's credentials. They can still try to make the printer redeem it for them.

A consent screen that shows the return domain gives Ava a slim chance to notice. The address begins with printer.example precisely so that it passes a glance.

How careless matching goes wrong

The prefix check in step 3 is one of several shortcuts that have let attackers through. In each row below, the printer registered only https://printer.example/oauth/callback, except where noted.

Requested redirect URIShortcut that accepts itWhat the shortcut missed
https://printer.example.attacker.example/oauth/callbackBegins with https://printer.example.The host name keeps going. This host belongs to attacker.example.
https://printer.example/oauth/callback/../../goBegins with the registered address.The browser resolves each .. segment, also when written %2e%2e, and arrives at https://printer.example/go.
https://printer.example/oauth/callback/previewThe registered address or anything below it.A different page, built for a different purpose, receives the code.
https://printer.example/oauth/callback?next=https://attacker.example/Compares the address without its query.The callback receives an instruction the printer never registered, which a callback that follows next would obey.
https://attacker.example\.printer.example/oauth/callbackThe host, as read by the server's own parser, ends with .printer.example.Browsers treat \ as / in web addresses, so the host is attacker.example.
https://promo.printer.example/oauth/callback, with https://*.printer.example/oauth/callback registeredAny subdomain of printer.example.The subdomain may no longer be under the printing company's control.
http://printer.example:8080/oauth/callbackThe port may vary and plain HTTP is allowed, rules meant for loopback addresses.A different service on another port receives the code over an unencrypted connection.

Begins with https://printer.example

The registered address
Accepted
printer.example.attacker.example
Accepted
/oauth/callback/../../go
Accepted
PRINTER.example, upper case
Refused

Ava's code can reach the attacker

The same sequence of characters

The registered address
Accepted
printer.example.attacker.example
Refused
/oauth/callback/../../go
Refused
PRINTER.example, upper case
Refused

Only the registered address gets a code

Refusing a harmless variant costs a developer one corrected setting.

Four of the requested addresses above, checked by a prefix shortcut and by exact comparison against the printer's one registration.

The wildcard row needs one more idea. A subdomain takeover happens when a DNS record still points a name such as promo.printer.example at an outside hosting service the printing company has stopped using. Anyone who opens an account with that service under the old name can then serve pages at the printer's subdomain, and a wildcard registration would send them codes.

The backslash row belongs to a family of tricks that work because the validator and the browser read the same text differently. Percent-encoding, unusual characters, and letter case all give two parsers a chance to disagree. Exact comparison avoids the question. The requested value must be the same sequence of characters as a registered value, so even https://PRINTER.example/oauth/callback is refused, although it leads to the same place. Refusing a harmless variant costs a developer one corrected setting.

Ordinary web callback addresses are registered and compared exactly. Installed applications can use a literal loopback address, with the operating system choosing an available port, under the protocol's installed-app rules. That port flexibility does not make a changed host or path equivalent. A private-use scheme has a different risk: another installed app can claim the same scheme, which is why PKCE is essential.

Leaks from the printer's own pages

Suppose the printer's site has a page at https://printer.example/go that sends the browser to whatever address appears in its to parameter, used for "continue to our partner" links. That is an open redirect, the kind of page Correlating requests and responses warned against.

If the photo service accepted any address on printer.example, the attacker could ask for the code to be returned to /go, with to pointing at attacker.example. The validation passes, because the address really is on the printer's domain, and the printer's own page then forwards the browser onward. Whether a code in the query survives the second hop depends on the redirector: some pass the remaining parameters along, and one that redirects with script can expose its full address in the Referer header if its referrer policy allows it. A response carried in the URL fragment, as the implicit grant carried access tokens, fares worse. When an HTTP redirect names no fragment of its own, the browser carries the original fragment along to the new address. Exact matching closes this route, because /go is not a registered address, and current guidance goes further: clients and authorization servers must not run open redirectors at all.

Even with exact matching, the code still arrives at a page, and that page can leak it. Redirects and authorization codes asked for a callback without third-party resources, and the reasons are concrete. Any script running on the callback page can read the full address, so an analytics or advertising script there would receive every code. Requests the page makes to other sites carry a Referer header. Current browsers send only the site's origin to other sites by default, but a page can choose a policy that sends the full address. The printer's callback therefore loads nothing from other sites, sets its own referrer policy, exchanges the code, and moves the browser to a clean address straight away. A 303 See Other response is a redirect that tells the browser to load the new address with an ordinary GET request:

HTTP/1.1 303 See Other
Location: https://printer.example/photo-book
Referrer-Policy: no-referrer
Cache-Control: no-store

The code's own properties help as well. It is single-use and short-lived, so a copy that reaches someone after the printer has redeemed it is worth very little.

Who checks what

Both sides share the work, and neither can do the other's part.

PartyResponsibility
Authorization serverCompares the requested redirect URI with each registered value as an exact string, before showing anything or redirecting. The only exception is a loopback port for a native app.
Authorization serverOn a mismatch or an unknown client, shows an error on its own page and never redirects, as Errors and denied access described.
Authorization serverRefuses redirect URIs that use plain http, apart from a native app's loopback address, and refuses wildcard registrations. A native app's private-use scheme remains allowed.
Authorization serverStores the redirect URI with the code and checks the token request against it.
ClientRegisters each exact callback, with test sites under their own registrations.
ClientRuns no open redirects on its domains and validates any return destination after the callback.
ClientKeeps the callback free of third-party content, sets a strict referrer policy, and moves to a clean address.
ClientRemoves DNS records for services it no longer uses.

The authorization server's check decides where a code can go, and the client's care decides whether it stays there. When both fail and a code for the printer's website escapes, the attacker still cannot redeem it without the printer's credentials, and an attempt to have the printer redeem it for them fails its PKCE check, because the code is bound to the challenge the attacker wrote, not to any attempt the printer started.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

The photo service accepts any redirect URI that begins with https://printer.example. What can an attacker do? 1 of 4

Choose one answer.

A careless matcher sends a code for the printer's public phone app to an address the attacker chose. The attacker wrote that authorization request. Why does PKCE not protect the code? 2 of 4

Choose one answer.

The printer's callback address is registered and matched exactly, but the callback page also loads an analytics script from another company. What is the concern? 3 of 4

Choose one answer.

The printer registers https://*.printer.example/oauth/callback so its promotions can use subdomains. Months later, promo.printer.example still points at a hosting service the company stopped using. What is the risk? 4 of 4

Choose one answer.

Try it in the Lab

Try a Capture the Flag challenge

Apply this lesson against an isolated, intentionally vulnerable application. Capture a flag, explain the mistake, then repair and retest it.

  1. Redirect Me Difficulty 2 of 5 · About 35 minutes · Browser application

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity