Common Attacks in OAuth 2.0

Common Attacks in OAuth 2.0

OAuth 2.0 was designed to keep your password safe from third-party apps — but the protocol itself has become a favorite target for attackers, precisely because it moves so much trust between so many moving parts. Here's how the most common attacks actually work, and what stops them.

A bank vault can have the thickest steel door in the world, and it will still be robbed if someone leaves a side window unlocked. OAuth 2.0 is very much like that vault: the core protocol is well-designed and battle-tested, but almost every real-world OAuth breach happens through a side window — a misconfigured setting, a skipped verification step, or a corner cut for convenience. This article walks through the most common attacks against OAuth 2.0 systems, explains exactly how each one works using plain language, and shows the specific defense that closes each door.

01

WWhy OAuth Is a Popular Attack Target

OAuth 2.0 sits at a uniquely valuable intersection: it hands out access to real user data, it moves through browsers and redirects that attackers can influence, and it’s implemented slightly differently by thousands of different companies. That combination makes it a rich target.

Unlike attacking a single server directly, attacking OAuth often means attacking the handshake between systems — the moment when trust is being established and handed off from one party to another. Every redirect, every token, and every consent screen is a small opportunity for something to go subtly wrong. Most successful OAuth attacks don’t break any cryptography at all; they exploit a missing check, a loose comparison, or a developer’s reasonable-sounding shortcut.

i
Key Idea

Almost every attack described in this article targets an implementation mistake, not a flaw in OAuth 2.0’s core design. The specification itself, when followed precisely, closes each of these doors — which is exactly why understanding the “why” behind each rule matters so much.

6
ATTACK PATTERNS IN THIS GUIDE
0
CRYPTOGRAPHIC BREAKS REQUIRED
1
MISCONFIGURATION OFTEN ENOUGH
02

AAuthorization Code Interception

The authorization code is meant to be a brief, one-time-use hop between the Authorization Server and the Client. If an attacker can grab it during that hop, they may be able to trade it for a real access token.

Everyday Analogy

Imagine a runner passing a baton in a relay race. The baton (the authorization code) is only meant to travel from one specific runner to the very next one. If a stranger jumps onto the track and grabs the baton mid-handoff, they can potentially carry it across the finish line themselves — receiving whatever prize (the access token) was meant for the real team.

On mobile devices, this interception often happens through malicious apps registering the same custom URL scheme as the legitimate app, so the operating system delivers the redirect — and the code inside it — to the attacker’s app instead of (or in addition to) the real one.

DEFENSE — PKCE RECOMMENDED
How It Works

Before starting the login, the Client generates a random secret value and sends a scrambled (hashed) version of it with the initial request. Later, when exchanging the authorization code for a token, the Client must present the original, unscrambled secret.

Why It Stops the Attack

Even if an attacker intercepts the authorization code itself, they don’t have the original secret value that only the legitimate app generated and kept — so their attempt to redeem the code for a token fails.

03

OOpen Redirect & Redirect URI Manipulation

If an Authorization Server checks a redirect address loosely — say, only the domain, not the full exact path — an attacker can smuggle the authorization code out to a server they control.

Everyday Analogy

Picture a delivery company that only checks the street name on a package, not the house number. An attacker who lives on the very same street as the real recipient could receive a package clearly meant for someone else at “23 Oak Street,” simply because their address happens to be “99 Oak Street” and nobody double-checked the number.

The classic version of this attack uses an “open redirect” — a page on the legitimate site that forwards visitors to any URL supplied in a query parameter. An attacker crafts a login request whose redirect URI points to this forwarding page, then sets the forwarding target to their own server, catching the authorization code as it passes through.

Defense 1

Exact-Match Validation

Authorization Servers must compare the full redirect URI — scheme, host, port, and path — character for character, never just the domain.

Defense 2

No Open Redirects Nearby

Clients should avoid having any page that forwards to arbitrary URLs anywhere near their registered callback path.

Defense 3

Explicit Registration

Every valid redirect address should be listed individually, with no wildcard patterns that could quietly cover unintended pages.

Defense 4

Short-Lived Codes

Authorization codes that expire within seconds shrink the window during which any intercepted code could be redeemed.

04

CCross-Site Request Forgery (CSRF) on the Callback

In this attack, someone tricks your browser into completing an OAuth login flow that was actually started by the attacker — potentially linking your account to the attacker’s identity instead of your own.

Here’s the trick: the attacker begins their own login flow with a legitimate service, gets as far as receiving a valid authorization code addressed to the real callback URL, but instead of finishing it themselves, they send that exact callback link to a victim — perhaps embedded in an image tag on a malicious webpage. If the victim’s browser loads that link, the victim’s session gets bound to the attacker’s authorization flow, sometimes resulting in the victim’s account becoming linked to the attacker’s third-party account without realizing it.

Everyday Analogy

Imagine someone filling out a “link my rewards card” form at a coffee shop, then handing the half-finished receipt to a stranger and saying “just hand this to the cashier for me.” If the cashier doesn’t check whose card is actually in front of them, the stranger’s purchase could get linked to the wrong rewards account entirely.

DEFENSE — STATE PARAMETER REQUIRED
How It Works

The Client generates a unique, unpredictable value (the “state” parameter) at the start of each login attempt, ties it to the current user’s browser session, and sends it along with the authorization request. When the callback arrives, the Client checks that the returned state value matches the one it originally generated for that exact browser session.

Why It Stops the Attack

An attacker’s borrowed callback link carries the attacker’s own state value, not one tied to the victim’s session — so the mismatch is caught immediately, and the flow is rejected before anything is linked.

05

TToken Leakage Through Browser History & Logs

Some older or poorly configured OAuth setups pass tokens directly in the URL, where they can linger in browser history, server logs, or the “Referer” header sent to other websites.

Everyday Analogy

Writing your house key’s shape on a postcard and mailing it works — the key-cutter down the street could technically read it too, along with anyone who handles the postcard along the way, or keeps a photocopy in a filing cabinet. A private, sealed envelope handed directly to one trusted person is a very different level of exposure.

This is one of the core reasons the modern, recommended flow uses a short-lived authorization code exchanged through a direct, server-to-server call, rather than putting the actual access token straight into the browser’s address bar. An older variant called the “Implicit flow” did exactly that, returning tokens directly in the URL fragment — and it’s now widely discouraged for this very reason.

Where Leaked Tokens Can End Up

  • Browser history, accessible to anyone with physical or remote access to the device
  • Web server access logs, often kept for months by hosting providers
  • Browser extensions with broad permissions that can read page URLs
  • Third-party analytics tools that record full page addresses

How Modern Practice Avoids This

  • Use the Authorization Code flow, never the deprecated Implicit flow
  • Exchange codes for tokens via a direct backend call, never through the browser bar
  • Keep access tokens out of URLs entirely — send them only in request headers
  • Apply PKCE so even a leaked authorization code alone isn’t enough to obtain a token
“Most OAuth breaches aren’t clever — they’re a token that traveled somewhere it never should have, quietly logged by a system nobody was thinking about.”
06

SScope Escalation & Consent Phishing

Not every attack targets the protocol’s mechanics — some target the human standing in front of the consent screen, tricking them into approving far more access than they realize.

In a consent phishing attack, an attacker registers their own legitimate-looking application with a real Authorization Server (such as Google or Microsoft’s platform), then sends victims a convincing email urging them to “verify their account” or “view a shared document” through a link that starts a real OAuth consent flow — for the attacker’s app. Because the login screen and domain genuinely belong to the trusted provider, victims often don’t notice that the permissions being requested (read all email, access all files, send messages as you) are far broader than anything a document viewer would need.

Real-World Pattern: Fake “Document Viewer” Apps

Several large-scale phishing campaigns have used exactly this technique — registering an OAuth app with an innocent-sounding name, then mass-emailing consent links that request full mailbox and contact access, all wrapped in a completely legitimate login page belonging to the real provider.

!
Why This Slips Past Technical Defenses

None of the protocol-level protections in this article — PKCE, exact-match redirect URIs, or state parameters — stop this attack, because every technical step of the flow is legitimate. The only real defense is careful review of exactly which scopes are being requested, and healthy suspicion of unsolicited “click to approve” links, even when the domain looks correct.

07

FFrequently Asked Questions

Q1Is OAuth 2.0 itself insecure?
No. The core specification, implemented correctly with recommended protections like PKCE, exact redirect URI matching, and the state parameter, is considered secure and is used by essentially every major technology company. Nearly all real-world breaches trace back to implementation shortcuts rather than a flaw in the protocol itself.
Q2What’s the single most important defense covered here?
There isn’t one silver bullet — PKCE, exact redirect URI matching, and the state parameter each defend against a different attack. Skipping any one of them reopens a specific door, so all three are considered baseline requirements in modern OAuth deployments.
Q3How can an everyday user protect themselves from consent phishing?
Always read the exact list of permissions on a consent screen before clicking Allow, be suspicious of unsolicited emails urging you to “view a document” or “verify your account” through a login link, and periodically review the list of third-party apps connected to your major accounts, removing anything unfamiliar.
Q4Does using HTTPS everywhere prevent all of these attacks?
HTTPS is essential and prevents attackers from eavesdropping on network traffic, but it doesn’t stop attacks like consent phishing, open redirect abuse, or CSRF — those exploit logic and human trust rather than unencrypted network traffic, so they need their own specific defenses.
Q5Why do so many attacks target the redirect step specifically?
The redirect step is the one moment in the entire flow where control temporarily passes through the user’s browser — a component the Authorization Server and Client don’t fully control — making it the most exposed seam in the whole system.
08

SSummary and Key Takeaways

What to Remember

  • Most OAuth 2.0 attacks exploit implementation mistakes, not weaknesses in the protocol’s core design.
  • Authorization code interception is countered by PKCE, which requires a secret only the legitimate Client ever knew.
  • Open redirect and redirect URI manipulation are stopped by exact, full-path matching against a pre-registered list — never a domain-only or wildcard check.
  • CSRF on the callback is prevented by the state parameter, which ties each login attempt to the specific browser session that started it.
  • Token leakage through browser history or logs is avoided by using the Authorization Code flow instead of the deprecated Implicit flow, and by never placing tokens directly in a URL.
  • Consent phishing and scope escalation target human judgment, not code — the only defense is carefully reading requested permissions and staying skeptical of unsolicited consent links.
  • Layering all of these defenses together — PKCE, exact redirect matching, state parameters, the Authorization Code flow, and user vigilance — is what makes a real-world OAuth deployment genuinely secure.