Exact redirect URI matching

The redirect URI is where the authorization code goes. A wildcard, a prefix, or a match that trusts the caller’s host sends that code to someone else.

Lesson 26 of 29 · 15 min read · practice only with authorization

Diagram

From a registered redirect to the code

Follow the path. One example at a time.

Step 1 of 4

Register

The application is registered with one or more exact redirect URIs.

Illustration: the redirect was registered exactly
# The application registered a list of redirect URLs.
# Each one is a full URL, not a prefix.
What changes the outcome
Register

A prefix or a wildcard is stored.

Request

A different path or host is accepted.

Code

The code is sent to a place you did not mean.

The example on the open step is one illustration, or the fix you can paste into an application you own.

What this page is made of

4 pieces. Each one says what fails, who is affected, what you would notice, and what you change.

  1. The code is a secret in flight

    What fails
    An authorization code is how the client becomes the user for a few minutes. Whoever receives the redirect receives that capability.
    Who is affected
    The person who consented, and the data the grant can reach.
    What you would notice
    A registration of https://app.example/* or a check that only compares hosts.
    What you change
    Store exact URIs. Reject the request on any difference, including path, query, and port.
  2. Local development is a separate client

    What fails
    A wildcard added so laptops can log in is a production wildcard. Development clients belong to a development issuer.
    Who is affected
    Anyone who can stand up a matching URL if the pattern is broad.
    What you would notice
    localhost and production sharing one client id with a loose redirect.
    What you change
    Register the development URI on a development client. Keep production exact.
  3. Mix-up across apps

    What fails
    If two clients share a redirect or the server trusts a client id from the browser without binding, a code for one app can be delivered to another.
    Who is affected
    The person whose code is delivered to the wrong client.
    What you would notice
    A redirect URI reused by two registrations, or a token endpoint that does not bind the code to the client.
    What you change
    One exact URI per client. Bind the code to the client id that requested it.
  4. What you log

    What fails
    Log the client id and that the redirect was rejected. Do not log a full URI that contains a code or a state secret from a successful flow in a shared debug sink.
    Who is affected
    The account, if logs become a copy of the code.
    What you would notice
    An access log of the redirect with the query string retained forever.
    What you change
    Scrub codes from logs. Keep the rejection counter.

Exact means the whole URI

OAuth sends the user’s browser to a redirect URI with a code. That URI is not a brand hint. It is the mailbox the code is dropped into. If your match allows any path under a host, any subdomain, or any URI the client supplies as long as the host “looks right,” someone who can put a page there receives the code. Exact match is string equality against a list you stored at registration.

Query parameters differ too. A registration that ignores the query string will accept a redirect the attacker added parameters to, which matters when an open redirect lives on an otherwise exact path. Register the URI you intend. Compare all of it. Reject the rest with a generic error.

One client, one purpose

Development redirect URIs on the production client are how wildcards sneak back. Make a different client for local development, on the issuer you use for development, with its own secret or its own public-client settings. Production registration should be boring and short: the real callback, maybe a second for a real second app, nothing with a star.

Bind the issued code to the client id that asked for it. At the token endpoint, the client has to be the same one. A code intercepted for client A must not be redeemable by client B. That binding is the mix-up control next to the exact redirect. State and PKCE, from the current OAuth guidance, belong in the same implementation. This page will not restate their wire format. It will say they are part of the same “do not hand the code to the wrong party” decision.

What you would notice

In the registration database, look for stars, trailing paths that were meant as prefixes, and shared redirect strings across clients. In code, look for a comparison on hostname only, or a startsWith on the URI. In logs, look for codes stored in query strings. Each of those is a finding on its own.

The person affected is whoever consented to the client. The data is whatever scope that code can become. Say both. Do not include a captured code or a working redirect in the ticket. Name the client id and the match rule you will replace.

What you change

Migrate registrations to exact URIs. Fail closed during the migration: a client that only had a wildcard needs a human to type the real callback, not an automatic “allow all paths we have seen.” Add a test that a URI which differs by one path segment is rejected.

Scrub codes from logs and from referrer policies on the callback page. Then read the audience page. A code that arrives at the right place and is traded for a token with the wrong audience is the next bug, not a reason to loosen the redirect.

Check yourself

Recognition and the fix. Nothing here is a procedure.

1 / 3

The client is registered for a prefix of a URL, and the authorization server accepts any longer path. What failed?

Sibling techniques

Pages at the same depth, plus a lab and a glossary card for this one.

  1. MapOAuth 2.0 and delegated access: scopes, flows, and tokens explainedHow OAuth lets an app act for a user without the password: the authorization code flow with PKCE, what scopes and consent mean, access versus refresh tokens, and the review points that catch common mistakes.
  1. 01Token audience and the smallest scopeA token is a capability for a specific API, for a specific set of actions, for a limited time.

Practice

  1. LabOAuth redirect URI matcherTest attacker-chosen redirect URIs against exact, prefix, host, and wildcard matching, and see which strategies leak an authorization code.

Glossary

  1. CardOAuth consent abuseA user approves an application that then reads mail or files under their identity.