Skip to content
Account takeover Write-up Intermediate

How i Hacked Scopely with “Sign in with Google”

The login flow used a client-side generated preregistration ID (preregId) to later fetch an authentication token, allowing an attacker to pre-register a chosen UUID and then trick a victim into logging in with that ID, thereby obtaining the victim's auth token. The attacker could also leak the victim's Google access token via an open redirect and CORS misconfiguration.

Ph.Hitachi Follow

Published on ph-hitachi.medium.com

Ph.Hitachi

Ph.Hitachi, on ph-hitachi.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

Scopely runs a HackerOne program, and the target here is a web application that has no registration flow at all: the only entry point is a login, and that login is handled through Google OAuth2 with the familiar "Sign in with Google" button. The researcher's stated methodology is to always test the authentication flow first, and that is exactly where this write-up starts.

The application is a front end backed by an API. Two JavaScript files carry the interesting logic: AuthService.js and TeamworkApi.js. The API endpoints referenced in the report live under /user/ and under https://teamwork.games.scopely.io/api/.

Setup

The work was done on 30 October 2021, a Saturday, after a long break from bug bounty. The only tooling mentioned is Burp Suite, used to capture requests one by one, and the Burp Collaborator client, used later to observe out-of-band requests. The researcher notes being a web developer, which made reading the front-end source straightforward. No accounts, roles or versions beyond a normal Google account used for the OAuth login are described.

Finding it

Logging in with Google and logging out both behaved normally, so the researcher turned to the source code. In AuthService.js, the loginWithGoogle function uses only window.location to obtain the Google access token, which looked wrong enough to analyse further.

The login function generates a UUIDv4 as preregId, described in the report as basically the ID of the user. The finishLogin function takes a preregId and returns an auth token. In TeamworkApi.js, that auth token is fetched from /user/fullfilledAuthToken/{prepregId}.

The problem the researcher identifies is that preregId is generated on the client side, at line 32 of AuthService.js, not by the back end. Because of that, an attacker can generate their own custom preregId and use it to obtain an auth token from that endpoint. The server cannot validate the preregId itself; at most it can validate the UUIDv4 format, and it can only check whether a UUIDv4 already exists in the database, which does not help when the value originates on the client.

Exploitation

Step 1: register a chosen preregId

Sending a request to /user/preregister with a preregistrationId of your choosing registers that value:

Text
POST /user/preregister {preregistrationId: 'xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx'}

The report confirms that a custom UUIDv4 can be entered this way, so the chosen value now exists in the database.

Step 2: collect the auth token

The token is then retrievable from the second endpoint, keyed by the same value:

Text
GET /user/fullfilledAuthToken/xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx
Text
{   authToken: 'access_token',   ...}

The response returns an authToken field. The open question the researcher poses at this point is how the application knows which user is behind a preregId that was generated client side and carries no credentials.

Step 3: follow the OAuth redirect

After the custom UUIDv4 is registered as preregId, it is passed to the Google OAuth2 endpoint. The response redirects to:

Text
https://teamwork.games.scopely.io/api/googlelogin?state=/_xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx&code=[access_token]&scope=profile+https://www.googleapis.com/auth/userinfo.profile

This is how the application identifies which user owns the preregId: the value appears in the state parameter, and the code parameter carries the token returned by Google. The report describes that code as also being an access token for the account. In other words, the redirect returns both the preregId and the Google code.

The consequence is that when you log in with a given preregId using your Gmail account, the authToken you later get from /user/fullfilledAuthToken/{preregId} belongs to that Gmail account. The loginWithGoogle code passes both fromPath and preregId.

Step 4: force a victim to log in

Because of the above, a victim can be made to authenticate by sending them a crafted Google authorisation link:

Text
https://accounts.google.com/o/oauth2/v2/auth?client_id=145493605239-[redacted].apps.googleusercontent.com&scope=profile&response_type=code&state=/_[preregid]&redirect_uri=https://teamwork.games.scopely.io/api/googlelogin

If the victim clicks the link and already has an account with their Gmail session active in the browser, they are forced to log in to their account through that visit. The state parameter carries the attacker-chosen preregId, and the redirect_uri points at the application's googlelogin handler.

Step 5: open redirect through fromPath

fromPath is described as the path the user is redirected to after a successful login. Adding double slashes to it produces an open redirect. The report notes that a preregId cannot be reused once it has been used, so this part required a lot of testing.

Step 6: token leak through the Referer header

After testing the open redirect, the researcher checked the Burp Collaborator client and found that the access token from the Gmail account leaks in the Referer header. The report states that this means the Google account used to sign in to Scopely can be compromised.

Step 7: CORS

Because the data comes from an API, the researcher then checked for CORS misconfiguration and reports another confirmed vulnerability. The write-up says the findings were combined to increase impact and that a simple script was created, but the script itself is not included in the report.

Root cause

The core mistake is that preregId, the value that ties an OAuth login to a user, is generated on the client rather than by the server. The server accepts an attacker-supplied UUIDv4, stores it, and later hands out an auth token for whatever Google account completes the flow with that value in state. Format validation of a UUIDv4, or a database existence check, does not establish that the value was issued by the application to a legitimate session.

The open redirect in fromPath and the CORS misconfiguration compound this: the redirect gives a way to send the browser somewhere attacker-controlled after login, and the access token leaks in the Referer header. The report does not describe any server-side control that would have prevented the client-generated identifier from being trusted.

Impact

An attacker can force a victim who is already signed in to Google, and who has a Scopely account, to authenticate through a crafted link, and can then obtain the resulting auth token. With the open redirect and the Referer leak, the Google account's access token can be exposed to an attacker-controlled destination, which the report frames as compromising the Google account used to sign in to Scopely. The CORS issue is reported as a further confirmed weakness combined with the rest. The report does not give a severity rating or a bounty amount.

The report ends by noting the submission was triaged and then closed as informative.

Fix

Based on the root cause, the preregId should be generated server side and bound to the session that initiated the login, so that a client cannot supply its own value; fromPath should be restricted to relative paths so that double slashes cannot turn it into an open redirect; and the CORS policy on the API should not allow arbitrary origins to read token-bearing responses.

Variants to test

  1. Register a client-chosen identifier and see whether the server accepts it: a positive result is the same value later resolving to a token.
  2. Check whether the OAuth state parameter is reflected and used to look up a user: a positive result is a redirect whose state contains your value and whose subsequent token request succeeds.
  3. Try double slashes and absolute URLs in any post-login redirect parameter: a positive result is a redirect to a host you control.
  4. Watch the Referer header on requests leaving the application after login: a positive result is a token or code appearing in it.
  5. Test the API's CORS policy with an arbitrary Origin.
  6. Reuse a preregId after a completed login to confirm the one-time behaviour described in the report.

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

What happened, in plain words

A security researcher found a way to take over accounts on a website run by a company called Scopely. The website had no normal sign-up form. The only way in was a "Sign in with Google" button, which is a common shortcut: instead of creating a username and password on the site, you tell Google to confirm who you are, and the site trusts Google's word.

The researcher read the website's own code (the JavaScript files that run in your browser) and noticed that a key piece of information used to identify a login was created by the browser, not by the company's server. Because the browser makes it, an attacker can make up their own value. That let the attacker tie a victim's Google login to a value the attacker chose, and then collect the resulting login token. Combined with a redirect flaw and a leak of the token in a browser header, the researcher could expose the victim's Google access token.

The report was submitted to HackerOne, a platform where companies run bug bounty programmes. It was triaged (looked at and categorised) and then closed as informative, meaning the company did not treat it as a security bug worth acting on.

This article walks through the same steps the researcher took, but explains every idea from scratch. You only need to know how to use a browser.

The target and the ground rules

Scopely runs a programme on HackerOne. A bug bounty programme is a deal: a company says "if you find a security problem in our systems and tell us privately, we may pay you". The programme page lists the rules (the policy) and the systems you are allowed to test (the scope). Testing outside the scope is not allowed.

The researcher picked one programme, Scopely, read the policy and the scopes, and chose a domain within scope. A domain is a website address, like example.com. The report stresses that choosing the right target matters more than finding a bug: the bug is a bonus.

The application itself has no registration. There is only a login, and that login uses Google OAuth2. OAuth2 is a standard way for one website to ask another (here, Google) to confirm your identity without ever seeing your Google password. When you click "Sign in with Google", Google checks that you are signed in to your Google account, asks whether you agree to share basic profile information with the site, and then sends the site a short-lived proof that you are you.

The site is a front end (the part you see in the browser) talking to an API. An API is the back end's menu of actions: the browser sends a request to an address like /user/something, and the server sends back data, usually in a format called JSON, which looks like { "name": "value" }. Two JavaScript files hold the interesting logic: AuthService.js and TeamworkApi.js. JavaScript is the programming language browsers run; these files are downloaded to your browser and can be read by anyone.

How the researcher got started

The work happened on 30 October 2021, a Saturday, after a long break from bug bounty. The researcher mentions having a day job and returning to hunting because they missed it. The only tools named are Burp Suite, used to capture requests one by one, and later the Burp Collaborator client, used to watch for requests arriving at a server the researcher controls. Burp Suite is a program that sits between your browser and a website so you can see and edit every request. The researcher also notes being a web developer, which made reading the front-end code easy.

The stated methodology is to always test the authentication flow first. Authentication is the process of proving who you are when you log in. It is the front door, so it is worth checking before anything else.

Logging in with Google looked normal, and logging out looked normal too. So the researcher opened the source code. In a browser you can do this with the developer tools, usually opened with F12, and read the JavaScript files the page loaded.

The suspicious code

In AuthService.js, the loginWithGoogle function uses only window.location to obtain the Google access token. window.location is the browser's built-in object that represents the current address bar; reading it tells you the current URL. Using only the address bar to get a token looked wrong enough to analyse further.

The login function generates a UUIDv4 as preregId. A UUIDv4 is a random-looking identifier in a fixed pattern of letters, digits and hyphens, like xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx. The report describes preregId as basically the ID of the user. The finishLogin function takes a preregId and returns an auth token. An auth token is a short string that acts like a temporary pass: whoever holds it is treated as logged in, so it must be kept secret.

In TeamworkApi.js, that auth token is fetched from /user/fullfilledAuthToken/{prepregId}. The {prepregId} part is a placeholder: whatever value you put there is used to look up the token.

The problem the researcher identifies is that preregId is generated on the client side, at line 32 of AuthService.js, not by the back end. "Client side" means it happens in your browser; "server side" means it happens on the company's computer. Because the browser makes the value, an attacker can make up their own preregId and use it to obtain an auth token from that endpoint. The server cannot validate that the preregId was issued by the application; at most it can check that the value looks like a UUIDv4, and it can only check whether a UUIDv4 already exists in the database, which does not help when the value originates in the browser.

A useful comparison: imagine a hotel where, instead of the reception desk writing your room number on a key card, you write the room number yourself and hand it in. The hotel can check that the number is written in the right format, and that the room exists, but it cannot know that the hotel gave you that room.

Exploitation

Step 1: register a chosen preregId

Sending a request to /user/preregister with a preregistrationId of your choosing registers that value:

Text
POST /user/preregister {preregistrationId: 'xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx'}

Line by line: POST is the HTTP method used when you send data to a server to create something. /user/preregister is the address on the server. The part in braces is the body of the request, the data being sent: a field named preregistrationId whose value is a UUIDv4 pattern. The xxxxxxxx groups are placeholders for any characters that fit the pattern.

The report confirms that a custom UUIDv4 can be entered this way, so the chosen value now exists in the database. The researcher used Burp Suite to capture the requests one by one and confirm this.

Step 2: collect the auth token

The token is then retrievable from the second endpoint, keyed by the same value:

Text
GET /user/fullfilledAuthToken/xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx
Text
{   authToken: 'access_token',   ...}

Line by line: GET is the HTTP method for asking a server for something. The address ends with the UUIDv4 you registered. The response is JSON: a field called authToken whose value is shown as access_token, with ... standing for other fields the report does not list.

The open question the researcher poses at this point is how the application knows which user is behind a preregId that was generated in the browser and carries no credentials. Credentials are the things that prove identity, like a password or a signed-in Google session.

Step 3: follow the OAuth redirect

After the custom UUIDv4 is registered as preregId, it is passed to the Google OAuth2 endpoint. The response redirects to:

Text
https://teamwork.games.scopely.io/api/googlelogin?state=/_xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx&code=[access_token]&scope=profile+https://www.googleapis.com/auth/userinfo.profile

Line by line: this is a URL. The part before the ? is the address of the application's Google login handler. After the ? come parameters, written as name=value and separated by &. state carries the preregId, prefixed with /_. code carries the value Google returned, shown here as [access_token] (a placeholder, not a real token). scope lists what was requested: profile and the Google userinfo profile permission.

This is how the application identifies which user owns the preregId: the value appears in the state parameter, and the code parameter carries the token returned by Google. The report describes that code as also being an access token for the account. In other words, the redirect returns both the preregId and the Google code.

The consequence is that when you log in with a given preregId using your Gmail account, the authToken you later get from /user/fullfilledAuthToken/{preregId} belongs to that Gmail account. The loginWithGoogle code passes both fromPath and preregId.

Step 4: force a victim to log in

Because of the above, a victim can be made to authenticate by sending them a crafted Google authorisation link:

Text
https://accounts.google.com/o/oauth2/v2/auth?client_id=145493605239-[redacted].apps.googleusercontent.com&scope=profile&response_type=code&state=/_[preregid]&redirect_uri=https://teamwork.games.scopely.io/api/googlelogin

Line by line: this is Google's authorisation address. client_id identifies the application asking Google for permission (here, Scopely's registered application). scope=profile asks only for basic profile information. response_type=code asks Google to return a code. state carries the attacker-chosen preregId, shown as [preregid]. redirect_uri tells Google where to send the result: the application's googlelogin handler.

If the victim clicks the link and already has an account with their Gmail session active in the browser, they are forced to log in to their account through that visit. A session is the state of being signed in; browsers keep it with a cookie, a small piece of data the site stores in your browser so it recognises you on the next request.

Step 5: open redirect through fromPath

fromPath is described as the path the user is redirected to after a successful login. A path is the part of a URL after the domain, like /dashboard. Adding double slashes to it produces an open redirect. An open redirect is a flaw where a site will send your browser to any address you supply, including one controlled by an attacker. Double slashes matter because browsers and servers often treat //example.com as a full address rather than a path.

The report notes that a preregId cannot be reused once it has been used, so this part required a lot of testing.

Step 6: token leak through the Referer header

After testing the open redirect, the researcher checked the Burp Collaborator client and found that the access token from the Gmail account leaks in the Referer header. A header is extra information attached to every HTTP request and response, like the label on a parcel. Referer is a header the browser adds automatically, telling the destination which page you came from. If the address of that previous page contains a token, the token travels with you to the next site.

The report states that this means the Google account used to sign in to Scopely can be compromised.

Step 7: CORS

Because the data comes from an API, the researcher then checked for CORS misconfiguration and reports another confirmed vulnerability. CORS stands for Cross-Origin Resource Sharing. It is the browser rule that decides whether a page from one site may read responses from another site. A misconfiguration means the API's cross-origin rules are too permissive, which is dangerous when those responses contain tokens.

The write-up says the findings were combined to increase impact and that a simple script was created, but the script itself is not included in the report.

Root cause

The core mistake is that preregId, the value that ties an OAuth login to a user, is generated in the browser rather than by the server. The server accepts an attacker-supplied UUIDv4, stores it, and later hands out an auth token for whatever Google account completes the flow with that value in state. Checking that a value looks like a UUIDv4, or that it exists in the database, does not establish that the application issued it to a legitimate session.

The open redirect in fromPath and the CORS misconfiguration compound this: the redirect gives a way to send the browser somewhere attacker-controlled after login, and the access token leaks in the Referer header. The report does not describe any server-side control that would have prevented the client-generated identifier from being trusted.

Impact

An attacker can force a victim who is already signed in to Google, and who has a Scopely account, to authenticate through a crafted link, and can then obtain the resulting auth token. With the open redirect and the Referer leak, the Google account's access token can be exposed to an attacker-controlled destination, which the report frames as compromising the Google account used to sign in to Scopely. The CORS issue is reported as a further confirmed weakness combined with the rest. The report does not give a severity rating or a bounty amount.

The report ends by noting the submission was triaged and then closed as informative.

Fix

Based on the root cause, the preregId should be generated on the server and bound to the session that started the login, so that a browser cannot supply its own value; fromPath should be restricted to relative paths so that double slashes cannot turn it into an open redirect; and the CORS policy on the API should not allow arbitrary origins to read token-bearing responses.

Variants to test

  1. Register a client-chosen identifier and see whether the server accepts it: a positive result is the same value later resolving to a token.
  2. Check whether the OAuth state parameter is reflected and used to look up a user: a positive result is a redirect whose state contains your value and whose subsequent token request succeeds.
  3. Try double slashes and absolute URLs in any post-login redirect parameter: a positive result is a redirect to a host you control.
  4. Watch the Referer header on requests leaving the application after login: a positive result is a token or code appearing in it.
  5. Test the API's CORS policy with an arbitrary Origin.
  6. Reuse a preregId after a completed login to confirm the one-time behaviour described in the report.

Glossary

  • API: the back end's menu of actions; the browser sends requests to addresses and gets data back.
  • Auth token: a short string that acts as a temporary pass; whoever holds it is treated as logged in.
  • Authentication: the process of proving who you are when you log in.
  • Bug bounty programme: a deal where a company invites people to report security problems privately, sometimes for a reward.
  • Burp Collaborator: a tool that gives you a server you control so you can see requests arriving at it.
  • Burp Suite: a program that sits between your browser and a website so you can see and edit requests.
  • Client side: code that runs in your browser.
  • Cookie: a small piece of data a site stores in your browser so it recognises you on the next request.
  • CORS: Cross-Origin Resource Sharing; the browser rule deciding whether a page from one site may read responses from another.
  • Credentials: the things that prove identity, like a password or a signed-in Google session.
  • Domain: a website address, like example.com.
  • Front end: the part of a site you see and interact with in the browser.
  • GET: the HTTP method for asking a server for something.
  • Header: extra information attached to every HTTP request and response.
  • HackerOne: a platform where companies run bug bounty programmes.
  • HTTP: the language browsers and servers use to exchange requests and responses.
  • JSON: a text format for data, looking like { "name": "value" }.
  • OAuth2: a standard way for one website to ask another to confirm your identity without seeing your password.
  • Open redirect: a flaw where a site will send your browser to any address you supply.
  • Parameter: a name=value pair in a URL after the ?, separated by &.
  • Path: the part of a URL after the domain, like /dashboard.
  • POST: the HTTP method used when you send data to a server to create something.
  • preregId: the identifier the application uses to tie an OAuth login to a user.
  • Referer: a header the browser adds automatically, telling the destination which page you came from.
  • Scope: the list of systems a programme allows you to test; also, in OAuth, the permissions requested.
  • Server side: code that runs on the company's computer.
  • Session: the state of being signed in.
  • Triaged: looked at and categorised by the programme.
  • UUIDv4: a random-looking identifier in a fixed pattern of letters, digits and hyphens.
  • window.location: the browser's built-in object representing the current address bar.

More by Ph.Hitachi

View all

9 more disclosed reports, best first.

More from Scopely

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Account takeover

The lesson behind this report.

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.