Skip to content
OAuth / SSO Write-up Intermediate

OAuth misconfiguration

The OAuth callback lacked a CSRF token, allowing an attacker to bind their social media account to a victim's account. However, the linking failed because the SDK required a postMessage with a language parameter, which the attacker bypassed by crafting a URL to initialise the SDK and then triggering the callback.

Yasser Mohammed Follow

Published on neroli.medium.com

Hi Every one, My name is Yasser (AKA Neroli in CTF’s) and I wanted to share this Finding with you :)

Yasser Ali (@n3r0li), on neroli.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. 6 min read.

Context

The target is a private Bugcrowd program, which the author refers to as example.com. The feature under test is authentication: the application lets users sign in either with a classic password-based mechanism or by linking their account to a social media profile through OAuth. The author's interest was in the OAuth flow itself, because OAuth integrations tend to carry misconfigurations that developers do not recognise.

The write-up was published on 13 February 2021 by Yasser Mohammed (@boomneroli).

Setup

The tooling is minimal: Burp Suite to log and intercept requests, a browser, and a Chrome extension that logs postMessage traffic between windows (the author links to the opnsec/postMessage-logger extension on GitHub). The author also used a video by STÖK on tracing JavaScript and an article on cross-window communication from javascript.info.

Finding it

After logging in and linking a profile to a social media account, the author reviewed the request history in Burp and found the OAuth callback request.

The OAuth Callback From the original on neroli.medium.com

The callback carries no CSRF token. That is the whole finding at first sight: if the application does not bind the callback to the user's session with an unguessable token, an attacker could potentially hijack a victim's account on the client application by binding it to the attacker's own social media account.

Exploitation

Step 1: a CSRF proof of concept against the callback

The author intercepted the callback request and dropped it, then built a simple CSRF page that redirects to the intercepted link. The response to that page is shown below.

the csrf POC response From the original on neroli.medium.com

On the surface the attack succeeded. But when the author opened the account and looked at the profile page, the social account was not there. Retrying produced the same result every time, so the callback alone was not enough to complete the linking.

Step 2: logging the cross-window messages

The author's first debugging step is to log all communication between windows with the postMessage logger extension. The console filled with data, and after some filtering a flaw became visible.

From the original on neroli.medium.com

When the link button is clicked, a postMessage with a click event is sent. After the user presses accept, the SDK loads and the interesting part begins. Something has to load before the linking action is actually taken, which explains why the dropped callback link did nothing on its own.

Step 3: tracing the callback resolver

Opening the dropped callback link directly produced an error in the console.

Error in linking account Callback link From the original on neroli.medium.com

Following the tracing approach from STÖK's video, the author opened the callback resolver and found the failing line.

callback resolver From the original on neroli.medium.com

Breakpoints were set to see why it fails.

Callback resolver From the original on neroli.medium.com

The problem is that settingsService.qsParams is undefined. The process cannot continue and stops there. The only way that value gets written is through one of the postMessage calls sent earlier, which carries the data that fills the parameter.

Looking back at the messages, when the SDK triages the click event it receives a parameter called language.

From the original on neroli.medium.com

The error occurs because lang is not present, so supplying it through the message flow should solve the problem.

Step 4: the first attempt and the failed triage

The author first tried to simulate the postMessage and send a similar one. The page was vulnerable to clickjacking, but that was out of scope and therefore not fixed. The plan was to create an iframe and send data into it, using the javascript.info article on cross-window communication, but the author could not work out how to send the custom event.

At that point the author gave up on the clean approach and built a clickjacking page where the user first has to click the link button, after which the page redirects to the OAuth link. The triager took a long time, asked why someone would click the button, hit a browser problem that prevented reproduction, and closed the report as NotReproducible. The author considered the bug valid and went back to rethink the bypass.

Step 5: the bypass

A post by the author's friend Sayed (dPhoeniixx) provided the idea for the bypass.

From the original on neroli.medium.com

Following the trace callbacks, the author asked whether the data comes from the static page or only starts when the button is clicked and the popup appears. As expected, the data comes from the popup page.

the connectRoute is the popup endpoint From the original on neroli.medium.com

The popup endpoint is the connectRoute, and it has no dynamic tokens or CSRF tokens. That makes it possible to craft a URL with the parameters needed:

Text
https://examble.com/init?appId=staticID&lang=en-GB&genomeId=StaticID&ssoId=anyID&nextUrl=https%3A%2F%2Fexample.com%2F

Opening that URL initialises the SDK.

the SDK loaded and the Trigger pageevent From the original on neroli.medium.com

The final page loads the crafted URL in a hidden iframe, waits for the SDK to initialise, and then writes a second hidden iframe pointing at the OAuth callback with the attacker's code and client id:

HTML
<html><head> <title></title></head><body>  <iframe src="https://examble.com/init?appId=staticID&lang=en-GB&genomeId=StaticID&ssoId=anyID&nextUrl=https%3A%2F%2Fexample.com%2F" onload="setTimeout(myFunction, 9000)" style="opacity: 0.0;"></iframe><script>function myFunction() {  document.write('<iframe name="cksl7" src="https://example/oauthCallBack?code={code}&cid={id}" style="opacity: 0.0;""></iframe>');}</script></body></html>

The first iframe is invisible and its onload schedules myFunction after 9000 ms. myFunction then writes the callback iframe, which performs the linking with the attacker's code and cid. The author reports that it worked. The OAuth login also had no 2FA available, so the account was taken over.

Root cause

The callback endpoint accepts the OAuth linking without a CSRF token. On its own that is not enough: the linking logic depends on settingsService.qsParams, which is populated from the popup page through postMessage, and without it the resolver throws because lang is missing and the process stops. The popup endpoint (connectRoute) that supplies this data has no dynamic or CSRF tokens, so an attacker can load it directly with chosen parameters and initialise the SDK. The two weaknesses combine: the tokenless popup provides the state the callback needs, and the tokenless callback performs the link. The clickjacking issue on the page was out of scope and left unfixed, but the final exploit does not depend on a user click.

Impact

An attacker who can get a victim to load the crafted page can bind the victim's account on the client application to the attacker's own social media account, which results in full account takeover. Because the OAuth login path had no 2FA, the second factor did not protect the account. The attack requires the victim to visit the attacker's page; the original clickjacking variant additionally required a click and was rejected as NotReproducible, while the final bypass removed that requirement.

Fix

Variants to test

  1. OAuth callback without a state or CSRF parameter: intercept the callback, drop it, and replay it from a page on another origin. A positive result is the social account appearing on the victim profile.
  2. Popup or SDK initialisation endpoints with static parameters: request the endpoint with your own appId, lang, genomeId, ssoId and nextUrl values. A positive result is the SDK initialising and sending its postMessage data without any per-session token.
  3. postMessage handlers that accept data from any origin: log messages with a postMessage logger and check whether the receiving page validates event.origin and event.source. A positive result is the handler acting on messages from an attacker-controlled frame.
  4. OAuth login paths that skip 2FA: link a social account and sign in through OAuth on an account with 2FA enabled. A positive result is a session without the second factor.
  5. Clickjacking on linking pages: frame the page and check for X-Frame-Options or CSP frame-ancestors. A positive result is the page rendering inside your frame and its buttons being clickable.

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 people sign in two ways: with a normal username and password, or by connecting their account to a social media profile (for example, "Sign in with Google"). The second way is called OAuth. The researcher noticed that the step where the website finishes connecting the social account did not include a secret check value. Without that value, a page on another website could trigger the same step on behalf of a logged-in visitor, and connect the visitor's account to the attacker's social media profile. That is called account takeover: the attacker ends up controlling the victim's account.

The first attempt did not work. The connection step ran, but the social account never appeared on the profile. The researcher then used a browser extension to watch the messages that the page's different windows send to each other, found that a second piece of the flow had to run first, and discovered that this second piece could also be started by anyone with a hand-made link. Combining the two gave a working attack that needed no click from the victim. The OAuth sign-in also skipped two-factor authentication, so the second lock on the account did not help.

Background you need first

A few ideas come up again and again below, so here they are before the story starts.

  • Request: when your browser asks a website for something (a page, an image, an action), it sends a request. Tools like Burp Suite sit between the browser and the website and let you read, pause and change those requests.
  • Cookie / session: after you log in, the website gives your browser a small piece of data that proves who you are on every later request. Think of it as a wristband at an event: show it and you are let back in without showing your ID again.
  • CSRF token: a second, random value that a well-built website puts into important forms and links. The server checks it before doing anything sensitive. It exists so that a page on a different website cannot forge the action, because that other page cannot know the random value. Think of a bank teller asking for a code that changes every time, printed only on your own receipt.
  • CSRF (Cross-Site Request Forgery): an attack where a malicious page makes your browser send a request to another site while you are logged in there. Your browser automatically attaches your wristband (cookie), so the other site thinks the request came from you.
  • OAuth: the "Sign in with X" system. A website sends you to the social network, you approve, and the social network sends you back with a short-lived code. The website exchanges that code for proof of who you are. The step where you come back is called the callback.
  • postMessage: a way for one window (or frame) on a page to send a message to another window. Websites use it to talk between a main page and a popup. If the receiving side does not check who sent the message, anyone can send one.
  • iframe: a window embedded inside a page, showing another page. It can be made invisible.
  • SDK: a bundle of JavaScript provided by a company that a website loads to get a feature working (here, the social login).
  • Clickjacking: tricking a visitor into clicking a button on a page that is hidden under or inside the attacker's page.
  • 2FA (two-factor authentication): a second proof of identity, usually a code from a phone app, asked after the password.
  • Account takeover: an attacker gains control of someone else's account.

The target and the feature

The target is a private program on Bugcrowd, a platform where companies invite researchers to test their systems. The researcher calls the target example.com to keep it private. The feature under test is login: the site accepts a normal password, or lets you link your account to a social media profile through OAuth.

The researcher's reason for looking at OAuth is that these integrations are often set up with mistakes that developers do not notice. The write-up was published on 13 February 2021 by Yasser Mohammed (@boomneroli).

The tools

The setup is small:

  1. Burp Suite, to record and pause requests.
  2. A browser.
  3. A Chrome extension that logs postMessage traffic between windows, the opnsec/postMessage-logger extension on GitHub.

The researcher also used a video by STÖK about tracing JavaScript and an article on javascript.info about communication between windows.

Finding it

After logging in and linking a profile to a social media account, the researcher looked through the request history in Burp and found the OAuth callback request.

The OAuth Callback From the original on neroli.medium.com

The screenshot shows that callback request. The important detail is that it carries no CSRF token. That is the finding at first sight: if the site does not tie the callback to the logged-in user with an unguessable value, an attacker could potentially hijack a victim's account by binding it to the attacker's own social media account.

Trying it: a CSRF page against the callback

The researcher intercepted the callback request and dropped it, then built a simple CSRF page that redirects to the intercepted link. The response to that page is shown below.

the csrf POC response From the original on neroli.medium.com

On the surface the attack worked. But when the researcher opened the account and looked at the profile page, the social account was not there. Trying again gave the same result every time. So the callback on its own was not enough to finish the linking.

Watching the messages between windows

The first debugging step was to log all communication between windows with the postMessage logger extension. The console filled with data, and after some filtering a flaw became visible.

From the original on neroli.medium.com

When the link button is clicked, a postMessage carrying a click event is sent. After the user presses accept, the SDK loads and the interesting part begins. Something has to load before the linking action is actually taken, which explains why the dropped callback link did nothing by itself.

Tracing the callback resolver

Opening the dropped callback link directly produced an error in the console.

Error in linking account Callback link From the original on neroli.medium.com

Following the tracing approach from STÖK's video, the researcher opened the callback resolver (the piece of JavaScript that handles the callback) and found the failing line.

callback resolver From the original on neroli.medium.com

Breakpoints were set to see why it fails. A breakpoint pauses the code at a chosen line so you can inspect the values at that moment.

Callback resolver From the original on neroli.medium.com

The problem is that settingsService.qsParams is undefined. In JavaScript, undefined means "this value has not been set". The process cannot continue and stops there. The only way that value gets written is through one of the postMessage calls sent earlier, which carries the data that fills the parameter.

Looking back at the messages, when the SDK triages the click event it receives a parameter called language.

From the original on neroli.medium.com

The error happens because lang is not present, so supplying it through the message flow should solve the problem.

The first attempt and the failed triage

The researcher first tried to simulate the postMessage and send a similar one. The page was vulnerable to clickjacking, but that was out of scope and therefore not fixed. The plan was to create an iframe and send data into it, using the javascript.info article on cross-window communication, but the researcher could not work out how to send the custom event.

At that point the researcher gave up on the clean approach and built a clickjacking page where the user first has to click the link button, after which the page redirects to the OAuth link. The triager (the person at the company who reviews reports) took a long time, asked why someone would click the button, hit a browser problem that prevented reproduction, and closed the report as NotReproducible. The researcher considered the bug valid and went back to rethink the bypass.

The bypass

A post by the researcher's friend Sayed (dPhoeniixx) provided the idea for the bypass.

From the original on neroli.medium.com

Following the trace callbacks, the researcher asked whether the data comes from the static page or only starts when the button is clicked and the popup appears. As expected, the data comes from the popup page.

the connectRoute is the popup endpoint From the original on neroli.medium.com

The popup endpoint is the connectRoute, and it has no dynamic tokens or CSRF tokens. That makes it possible to craft a URL with the parameters needed:

Text
https://examble.com/init?appId=staticID&lang=en-GB&genomeId=StaticID&ssoId=anyID&nextUrl=https%3A%2F%2Fexample.com%2F

Line by line:

  • https://examble.com/init is the page that starts the SDK. The spelling examble is as it appears in the report.
  • lang=en-GB is the language. This is the parameter whose absence caused the error earlier.
  • The %3A and %2F are the encoded forms of : and /, because a URL cannot contain a second full URL without encoding it.

Opening that URL initialises the SDK.

the SDK loaded and the Trigger pageevent From the original on neroli.medium.com

The final page loads the crafted URL in a hidden iframe, waits for the SDK to initialise, and then writes a second hidden iframe pointing at the OAuth callback with the attacker's code and client id:

HTML
<html><head> <title></title></head><body>  <iframe src="https://examble.com/init?appId=staticID&lang=en-GB&genomeId=StaticID&ssoId=anyID&nextUrl=https%3A%2F%2Fexample.com%2F" onload="setTimeout(myFunction, 9000)" style="opacity: 0.0;"></iframe><script>function myFunction() {  document.write('<iframe name="cksl7" src="https://example/oauthCallBack?code={code}&cid={id}" style="opacity: 0.0;""></iframe>');}</script></body></html>

Line by line:

  • <html><head> <title></title></head><body> opens a normal, empty page.
  • The first <iframe> loads the crafted init URL. style="opacity: 0.0;" makes it invisible, so the visitor sees nothing.
  • onload="setTimeout(myFunction, 9000)" means: when this iframe has finished loading, wait 9000 milliseconds (9 seconds) and then run myFunction. The wait gives the SDK time to initialise.
  • function myFunction() { ... } is the function that runs after the wait.
  • document.write('<iframe name="cksl7" src="https://example/oauthCallBack?code={code}&cid={id}" style="opacity: 0.0;""></iframe>') writes a second invisible iframe into the page. Its address is the OAuth callback, carrying the attacker's code and cid (client id). Loading it performs the linking.
  • </script></body></html> closes the page.

The researcher reports that it worked. The OAuth login also had no 2FA available, so the account was taken over.

Why it worked

The callback endpoint accepts the OAuth linking without a CSRF token. On its own that is not enough: the linking logic depends on settingsService.qsParams, which is filled from the popup page through postMessage, and without it the resolver throws because lang is missing and the process stops. The popup endpoint (connectRoute) that supplies this data has no dynamic or CSRF tokens, so an attacker can load it directly with chosen parameters and initialise the SDK. The two weaknesses combine: the tokenless popup provides the state the callback needs, and the tokenless callback performs the link. The clickjacking issue on the page was out of scope and left unfixed, but the final exploit does not depend on a user click.

What an attacker could do

An attacker who can get a victim to load the crafted page can bind the victim's account on the client application to the attacker's own social media account, which results in full account takeover. Because the OAuth login path had no 2FA, the second factor did not protect the account. The attack requires the victim to visit the attacker's page; the original clickjacking variant additionally required a click and was rejected as NotReproducible, while the final bypass removed that requirement.

How to fix it

Things to try on other sites

  1. OAuth callback without a state or CSRF parameter: intercept the callback, drop it, and replay it from a page on another origin. A positive result is the social account appearing on the victim profile.
  2. Popup or SDK initialisation endpoints with static parameters: request the endpoint with your own appId, lang, genomeId, ssoId and nextUrl values. A positive result is the SDK initialising and sending its postMessage data without any per-session token.
  3. postMessage handlers that accept data from any origin: log messages with a postMessage logger and check whether the receiving page validates event.origin and event.source. A positive result is the handler acting on messages from an attacker-controlled frame.
  4. OAuth login paths that skip 2FA: link a social account and sign in through OAuth on an account with 2FA enabled. A positive result is a session without the second factor.
  5. Clickjacking on linking pages: frame the page and check for X-Frame-Options or CSP frame-ancestors. A positive result is the page rendering inside your frame and its buttons being clickable.

Glossary

  • Breakpoint: a pause point set in a browser's developer tools so you can inspect the code and values at that line.
  • Bugcrowd: a platform where companies invite researchers to test their systems and report problems.
  • Burp Suite: a tool that sits between your browser and a website so you can read, pause and change requests.
  • Callback: the step where the social network sends you back to the website after you approve a login, carrying a code.
  • Clickjacking: tricking a visitor into clicking a button on a page hidden inside or under the attacker's page.
  • Cookie / session: a small piece of data your browser keeps after login and sends with later requests to prove who you are.
  • CSRF (Cross-Site Request Forgery): a malicious page making your browser send a request to another site while you are logged in there.
  • CSRF token: a random value added to important requests and checked by the server, so another site cannot forge them.
  • connectRoute: the popup endpoint that supplies the data the callback needs.
  • iframe: a window embedded inside a page, showing another page; it can be made invisible.
  • lang / language: the language parameter whose absence caused the resolver error.
  • nextUrl: the address to go to after the SDK initialises.
  • OAuth: the "Sign in with X" system where a social network vouches for who you are.
  • postMessage: a way for one window or frame to send a message to another.
  • qsParams: the settings value that the callback resolver reads and that is filled from the popup through postMessage.
  • Request: what your browser sends to a website to ask for a page or an action.
  • SDK: a bundle of JavaScript a website loads to get a feature working, here the social login.
  • Triager: the person at the company who reviews a security report and decides whether it is valid.
  • undefined: in JavaScript, a value that has not been set.
  • X-Frame-Options / CSP frame-ancestors: response headers that tell the browser whether a page may be shown inside a frame.

More by Yasser Mohammed

View all

3 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.