Course contentsShow
← Security
Lesson 762 of 3,05216. Web Security - Authentication MechanismsFree lesson

OAuth 2.0 Redirect URI Validation

Critical importance of strict redirect URI matching, open redirect vulnerabilities, and wildcard dangers in OAuth.

OAuth 2.0 Redirect URI Validation

You'll learn why sloppy redirect URI validation creates catastrophic security holes in OAuth implementations.

The Critical Problem

When an OAuth authorization server completes the authorization flow, it redirects the user back to the client application with sensitive tokens or authorization codes. The redirect_uri parameter tells the server where to send these secrets. If this validation is weak, an attacker can redirect tokens to their own server instead of the legitimate application.

Why Exact Matching Matters

Think of the redirect URI like a locked mailbox address. You wouldn't want the post office to deliver your sensitive documents to "123 Main Street" when you only authorized "123 Main St" — or worse, to "123 Main Street Evil Apartment."

OAuth servers must perform exact string matching on redirect URIs. Even tiny differences are dangerous:

  • https://app.com/callback ≠ https://app.com/callback/
  • https://app.com/callback ≠ https://app.com/callback?extra=param
  • https://app.com/callback ≠ https://attacker.com/callback

The Wildcard Trap

Never allow wildcards or pattern matching (like https://app.com/*). An attacker could exploit this with an open redirect vulnerability elsewhere in your app:

If https://app.com/redirect?url=evil.com redirects anywhere, and wildcards are allowed, attackers can chain: OAuth redirects to app.com/redirect?url=evil.com, which immediately forwards tokens to the attacker's domain.

Subdomain Dangers

Even allowing https://*.app.com/callback is risky. If attackers can register or compromise any subdomain, they receive the tokens.

Key Takeaway: Always enforce exact, pre-registered redirect URI matching in OAuth — no wildcards, no substring matching, no creative pattern matching. A single character difference must fail validation.