[CRITICAL] Full account takeover using CSRF
The CSRF token (rt parameter) was leaked in a publicly accessible JavaScript file, allowing an attacker to link their own social account to a victim's account and then log in as the victim. The attacker could take over the victim's account by tricking them into visiting a malicious page.
Originally disclosed on HackerOne
- Triaged in 2 days
- Fixed in 9 days
- Paid in 4 days
- Disclosed after 11 days
Hi , I have found a CSRF issue that allows an attacker to link his gmail , facebook ... or any social account to the victim's account and hijack the whole account.
#Details:
When a user tries to link a gmail account with his account , after he authorizes badoo to use his gmail account he will be redirected to https://eu1.badoo.com/google/verify.phtml?rt=<State_param_value>&code=<Code_returned_from_google> , the only thing that protects from CSRF is the rt parameter which is unique for each user/session . I have noticed that the rt parameter is returned on almost all json responses so I tried to find a link that leaks it. After digging for a while , I have found this link https://eu1.badoo.com/worker-scope/chrome-service-worker.js , and I was surprised that it contains the rt parameter value!!
if you open the link https://eu1.badoo.com/worker-scope/chrome-service-worker.js you'll find a string variable url_stats containing the value of the rt parameter:
var url_stats = 'https://eu1.badoo.com/chrome-push-stats?ws=1&rt=<rt_param_value>';
So, now I got a javascript file with the rt param value and I can use it to link any malicious social media account with it.
#Here is a PoC:
Here is a live PoC: http://azzazpp.com/badoo.html which will link a dummy gmail account of mine to your badoo account. Go to https://eu1.badoo.com/settings then check your social accounts and you will see a gmail account with the name Mahmoud Gamal added to your social accounts.
<html>
<head>
<title>Badoo account take over</title>
<script src=https://eu1.badoo.com/worker-scope/chrome-service-worker.js?ws=1></script>
</head>
<body>
<script>
function getCSRFcode(str) {
return str.split('=')[2];
}
window.onload = function(){
var csrf_code = getCSRFcode(url_stats);
csrf_url = 'https://eu1.badoo.com/google/verify.phtml?code=4/nprfspM3yfn2SFUBear08KQaXo609JkArgoju1gZ6Pc&authuser=3&session_state=7cb85df679219ce71044666c7be3e037ff54b560..a810&prompt=none&rt='+ csrf_code;
window.location = csrf_url;
};
</script>
After an attacker links his gmail , facebook or any social account to the victim's account , he can use it to login to the victim's account and do any modifications he wants. Please tell me if you are having any problems reproducing this. Thanks!
Context
The target is Badoo, reached through the eu1.badoo.com host, and the feature under examination is social account linking. A logged-in user can attach an external identity provider account, such as Gmail or Facebook, to their Badoo account. Once linked, that external account can be used to sign in to the Badoo account.
The linking flow for Google runs through a verification endpoint on the Badoo side. After the user authorises Badoo to use their Gmail account, Google redirects the browser back to:
https://eu1.badoo.com/google/verify.phtml?rt=<State_param_value>&code=<Code_returned_from_google>
The rt parameter is the anti-CSRF state value. It is unique per user and session, and it is the only thing protecting the verification request from being forged by a third party. If an attacker can learn a victim's rt value, the attacker can construct a valid verification request and complete a link on the victim's behalf.
Setup
No special tooling is described. The researcher needed a Badoo account, a Google account to link, and the ability to host a page that the victim would visit. The proof of concept used a dummy Gmail account belonging to the researcher, and the live page was hosted at http://azzazpp.com/badoo.html.
The precondition for the attack is that the victim is logged in to Badoo and visits an attacker-controlled page while that session is active. The attacker also needs a Google authorisation code for the linking flow.
Finding it
The researcher observed that the rt parameter is returned in almost all JSON responses from the application. That makes it a broadly exposed value, and the question became whether any response could be reached cross-origin, that is, read by a page on another domain.
Digging through the application's static resources turned up this URL:
https://eu1.badoo.com/worker-scope/chrome-service-worker.js
Opening it revealed that the file embeds the value of the rt parameter in a string variable named url_stats:
var url_stats = 'https://eu1.badoo.com/chrome-push-stats?ws=1&rt=<rt_param_value>';
This is the pivot. A JavaScript file is a classic script resource, so it can be included with a <script src=...> tag from any origin. The browser will fetch and execute it, and the variable it defines is then readable by the including page. The anti-CSRF token, which was supposed to be secret to the victim's session, is therefore readable by any site that includes this script.
Exploitation
Step 1: Include the service worker script cross-origin
The attacker's page loads the Badoo script with a plain script tag. The script is included cross-origin and defines url_stats as a global the attacker's page can read.
<script src=https://eu1.badoo.com/worker-scope/chrome-service-worker.js?ws=1></script>
Step 2: Extract the token from the global variable
The script defines url_stats as a global. The attacker's page splits the string on = and takes the third element, which is the rt value.
function getCSRFcode(str) {
return str.split('=')[2];
}
Step 3: Build the verification URL and navigate the victim
On page load, the attacker's page reads the token and redirects the victim's browser to the Google verification endpoint with the attacker's own authorisation code and the victim's rt.
window.onload = function(){
var csrf_code = getCSRFcode(url_stats);
csrf_url = 'https://eu1.badoo.com/google/verify.phtml?code=4/[redacted]&authuser=3&session_state=[redacted]..a810&prompt=none&rt='+ csrf_code;
window.location = csrf_url;
};
The code parameter is the authorisation code returned by Google for the attacker's dummy Gmail account. The rt parameter is the victim's token, harvested in the previous step. The navigation is a top-level GET to eu1.badoo.com, so the victim's Badoo cookies are sent and the request is processed as the victim.
Step 4: Confirm the link
The full page used for the proof of concept:
<html>
<head>
<title>Badoo account take over</title>
<script src=https://eu1.badoo.com/worker-scope/chrome-service-worker.js?ws=1></script>
</head>
<body>
<script>
function getCSRFcode(str) {
return str.split('=')[2];
}
window.onload = function(){
var csrf_code = getCSRFcode(url_stats);
csrf_url = 'https://eu1.badoo.com/google/verify.phtml?code=4/[redacted]&authuser=3&session_state=[redacted]..a810&prompt=none&rt='+ csrf_code;
window.location = csrf_url;
};
</script>
After the victim loads the page, the researcher instructs them to visit https://eu1.badoo.com/settings and inspect their social accounts. The dummy Gmail account, shown under the name Mahmoud Gamal, appears among the linked accounts. The link has been created without the victim's consent.
Root cause
The verification endpoint relies on a single per-session state value, rt, to distinguish a legitimate linking request from a forged one. That is a reasonable design in principle, but only if the value stays confidential to the user's session.
Here it does not. The application returns rt in almost all JSON responses, and it also embeds it in a JavaScript file served from eu1.badoo.com. JavaScript files are not protected by the same-origin policy in the way JSON responses are: any origin can include them with a <script> tag, and the variables they define become readable globals on the including page. The token therefore leaks to any site the victim visits, and the CSRF defence collapses.
The token was exposed in a resource that any origin can include as a script.
Impact
An attacker who can get a logged-in victim to load an attacker-controlled page can link the attacker's own Gmail, Facebook or any other supported social account to the victim's Badoo account. Once linked, the attacker can sign in to the victim's account through that social account and make any modifications they want. This is a full account takeover.
The attack requires the victim to be logged in and to visit the attacker's page.
Fix
The report does not describe the fix that was applied. The design change that follows from the root cause is to stop exposing rt outside the request that needs it: remove it from general JSON responses and from any script or resource that can be fetched cross-origin, and treat it as a secret tied to the specific linking flow rather than a value embedded in shared resources.
Variants to test
- Token in cross-origin readable resources. Look for anti-CSRF tokens, session identifiers or state values embedded in
.jsfiles, CSS, or other resources that can be included with<script>or<link>. A positive result is a global variable in the included script that contains the token, readable from an attacker page. - Token in JSON responses reachable cross-origin. Check whether JSON endpoints that return the token can be read via JSONP, permissive CORS, or content-type sniffing. A positive result is a response whose body is readable from another origin and contains the token.
- Token in error pages or redirects. Inspect error responses and redirect
Locationheaders for the token. A positive result is the token appearing in a response an attacker page can influence or read. - OAuth state reuse across flows. Test whether the state value from one linking flow is accepted in another, or whether it survives logout and login. A positive result is a state value that remains valid after the session it was issued for has changed.
- Missing state validation. Remove or blank the
rtparameter on the verification endpoint. A positive result is a successful link without a valid state value.
Hunting notes
This bug sits at the intersection of two common weaknesses: a CSRF token that is not treated as a secret, and a static or generated resource that is cross-origin readable. During recon, the signals are tokens appearing in more places than the one form that needs them, especially in JSON responses, and JavaScript files served from the main application host that contain session-specific values.
A practical approach is to capture the token from a normal flow, then search the application's JavaScript and JSON responses for that exact value. Any hit in a resource that can be included cross-origin is a candidate. The researcher demonstrated impact by completing the link end to end with a dummy account and showing the linked account in the victim's settings, which is the kind of concrete, verifiable result that makes a CSRF report convincing.
What happened, in plain words
Badoo is a dating and social website. It lets you sign in not only with a Badoo password but also by connecting an outside account, such as a Gmail or Facebook account, to your Badoo profile. Once that outside account is connected, you can use it to log in to Badoo.
The researcher found that this connecting step could be tricked. If a logged-in Badoo user visited a page the researcher controlled, that page could quietly attach the researcher's own Gmail account to the visitor's Badoo profile. From then on, the researcher could log in to the victim's Badoo account through that Gmail account. That is a full account takeover.
The trick works because of a small security value called rt. Badoo uses rt to make sure a connecting request really comes from the person who started it. The researcher discovered that Badoo was handing this value out in a JavaScript file that any website could load. Once the attacker's page had the value, it could build a valid connecting request and send the victim's browser to it.
Background: the pieces involved
Before the steps make sense, here are the ideas the attack relies on.
Account linking. Many sites let you attach an outside account to your profile. You click "connect Google", Google asks whether you agree to share your account with the site, and then Google sends you back to the site with a short confirmation. Badoo then stores the link so that the outside account can be used to sign in later.
A token. A token is a short string of characters that a website gives to a browser to identify a session or to prove that a request is legitimate. Think of it like the wristband you get at an event: it is not your name or password, but showing it proves you were let in. If someone else copies your wristband, they can walk in as you.
Cookies. A cookie is a small piece of data a website asks your browser to store and send back on every request to that site. Badoo uses a cookie to remember that you are logged in. When your browser talks to eu1.badoo.com, it automatically attaches that cookie, which is why the site knows who you are.
CSRF (Cross-Site Request Forgery). This is the vulnerability class in this report. The idea is that your browser will happily send your Badoo cookie to Badoo even when the request was triggered by a completely different website. So if an attacker can make your browser send a request to Badoo that does something useful to the attacker, Badoo will treat it as if you asked for it. The defence is a secret value that only your own Badoo pages know, which the attacker's page cannot guess. That secret is often called an anti-CSRF token.
The rt parameter. In this report, rt is that anti-CSRF token for the account-linking flow. It is unique per user and per session. The whole defence rests on the attacker not being able to learn it.
Same-origin policy. Browsers have a rule that a page from one website cannot read the contents of a response from another website. This is what normally stops an attacker's page from simply fetching Badoo data and reading it. There is an important exception: JavaScript files loaded with a <script src=...> tag are allowed across sites, and any variables they define become readable by the page that included them. This exception is central to the bug.
A JavaScript file. A .js file is a file of code that a web page can load and run in the browser. When a page includes one with a <script> tag, the browser downloads it and runs it as part of that page.
The linking flow
When a user chooses to connect a Google account, Badoo sends the browser to Google. After the user agrees, Google sends the browser back to Badoo at this address:
https://eu1.badoo.com/google/verify.phtml?rt=<State_param_value>&code=<Code_returned_from_google>
This is a URL with two parameters after the question mark. The code is the confirmation that Google issues for the account being connected. The rt is Badoo's own anti-CSRF token for this flow. Badoo checks rt to decide whether the request really belongs to the user's session. If an attacker knows a victim's rt, the attacker can build a request that Badoo will accept as coming from the victim.
What the researcher needed
No special tools are described. The researcher needed:
- A Badoo account.
- A Google account to connect, which in this case was a dummy Gmail account belonging to the researcher.
- A place to host a web page that a victim would visit. The proof of concept was hosted at
http://azzazpp.com/badoo.html.
The victim has to be logged in to Badoo and has to visit the attacker's page while that login is active. The attacker also needs a Google code that is valid for the linking flow.
Finding the leak
The researcher first noticed that the rt value appears in almost all of Badoo's JSON responses. JSON is a plain text format that websites use to send data back to a page. Seeing the token in many responses made it worth asking whether any of those responses could be read from another website.
While looking through Badoo's static files, the researcher found this address:
https://eu1.badoo.com/worker-scope/chrome-service-worker.js
Opening it showed that the file contains the rt value inside a variable called url_stats:
var url_stats = 'https://eu1.badoo.com/chrome-push-stats?ws=1&rt=<rt_param_value>';
Line by line:
var url_stats = ...;creates a variable namedurl_statsand gives it a value. Because this line is at the top level of the file, the variable becomes global, meaning the page that loaded the file can read it.- The value is a URL string pointing at
https://eu1.badoo.com/chrome-push-stats?ws=1&rt=<rt_param_value>. Thert=part at the end is where the token sits.
This is the turning point. A JavaScript file can be loaded by any website with a <script src=...> tag. The browser fetches it and the variable it defines is readable by the attacker's page. The variable it defines is then readable by the attacker's page. The secret that was supposed to protect the linking request is now available to any site the victim visits.
Building the attack
Step 1: Load the Badoo script from the attacker's page
The attacker's page includes the Badoo script with a plain script tag:
<script src=https://eu1.badoo.com/worker-scope/chrome-service-worker.js?ws=1></script>
This line tells the browser to download that file from Badoo and run it. Because the request goes to eu1.badoo.com, the browser sends the victim's Badoo cookie along with it, so the file that comes back contains the victim's own rt value. The ?ws=1 at the end is part of the address as the researcher used it.
Step 2: Pull the token out of the variable
Once the script has run, the attacker's page can read url_stats. The researcher splits the string on the = character and takes the third piece:
function getCSRFcode(str) {
return str.split('=')[2];
}
Line by line:
function getCSRFcode(str) {defines a small function that takes a piece of text, here calledstr.return str.split('=')[2];splits the text wherever an=appears and returns the third piece. Counting from zero,[2]is the third item. In the URL string, the pieces are the part before the first=, the part between the two=signs, and the token after the second=. So the function returns the token.
Step 3: Send the victim to the verification address
When the page finishes loading, it reads the token and redirects the victim's browser to Badoo's verification address, using the attacker's own Google code and the victim's rt:
window.onload = function(){
var csrf_code = getCSRFcode(url_stats);
csrf_url = 'https://eu1.badoo.com/google/verify.phtml?code=4/[redacted]&authuser=3&session_state=[redacted]..a810&prompt=none&rt='+ csrf_code;
window.location = csrf_url;
};
Line by line:
window.onload = function(){sets up code to run once the page has fully loaded.var csrf_code = getCSRFcode(url_stats);calls the function from Step 2 on the variable from Step 1, storing the victim's token incsrf_code.csrf_url = '...' + csrf_code;builds the full verification address. The fixed part contains the attacker's Googlecodeand other values from the flow. The+ csrf_codeappends the victim's token at the end, afterrt=.window.location = csrf_url;tells the browser to navigate to that address.
Because this is a normal navigation to eu1.badoo.com, the victim's Badoo cookie is sent with it, and Badoo processes the request as the victim. The code belongs to the attacker's dummy Gmail account, and the rt belongs to the victim's session, so Badoo accepts the request and connects the attacker's Gmail account to the victim's profile.
Step 4: The full page
The complete page used for the proof of concept:
<html>
<head>
<title>Badoo account take over</title>
<script src=https://eu1.badoo.com/worker-scope/chrome-service-worker.js?ws=1></script>
</head>
<body>
<script>
function getCSRFcode(str) {
return str.split('=')[2];
}
window.onload = function(){
var csrf_code = getCSRFcode(url_stats);
csrf_url = 'https://eu1.badoo.com/google/verify.phtml?code=4/[redacted]&authuser=3&session_state=[redacted]..a810&prompt=none&rt='+ csrf_code;
window.location = csrf_url;
};
</script>
Line by line:
<html>,<head>,<title>and<body>are the usual structure of a web page. The title is just the text shown in the browser tab.- The
<script src=...>in the head loads Badoo's script, which definesurl_statswith the victim's token. - The
<script>in the body contains the function and the redirect from Steps 2 and 3. It runs after the Badoo script has loaded, sourl_statsis already available.
Step 5: Check the result
After the victim loads the page, the researcher asks them to visit https://eu1.badoo.com/settings and look at their connected social accounts. The dummy Gmail account, shown under the name Mahmoud Gamal, appears in the list. The link was created without the victim's consent.
Why it works
The verification endpoint relies on a single per-session value, rt, to tell a real linking request from a forged one. That is a sensible design, but only if the value stays secret to the user's session.
Here it does not. Badoo returns rt in almost all of its JSON responses, and it also puts the value inside a JavaScript file served from eu1.badoo.com. JavaScript files are not protected by the same-origin policy the way JSON responses are: any website can include them with a <script> tag, and the variables they define become readable by the including page. The token therefore leaks to any site the victim visits, and the CSRF defence falls apart.
The token was exposed in a file that any website can include as a script.
What an attacker could do
An attacker who gets a logged-in victim to load an attacker-controlled page can connect the attacker's own Gmail, Facebook or any other supported social account to the victim's Badoo account. Once connected, the attacker can sign in to the victim's account through that social account and make any changes they want. That is a full account takeover.
The attack needs the victim to be logged in and to visit the attacker's page.
The fix
The report does not describe the fix that was applied. The design change that follows from the cause is to stop exposing rt outside the request that needs it: remove it from general JSON responses and from any script or file that can be fetched from another website, and treat it as a secret tied to the specific linking flow rather than a value written into shared files.
Related things worth testing
- Tokens in files that other sites can load. Look for anti-CSRF tokens, session identifiers or state values inside
.jsfiles, CSS or other files that can be included with<script>or<link>. A positive result is a global variable in the included file that contains the token and can be read from an attacker's page. - Tokens in JSON responses reachable from another site. Check whether JSON endpoints that return the token can be read through JSONP, permissive CORS or content-type sniffing. A positive result is a response whose body can be read from another origin and contains the token.
- Tokens in error pages or redirects. Inspect error responses and redirect
Locationheaders for the token. A positive result is the token appearing in a response an attacker's page can influence or read. - OAuth state reuse across flows. Test whether the state value from one linking flow is accepted in another, or whether it survives logout and login. A positive result is a state value that stays valid after the session it was issued for has changed.
- Missing state validation. Remove or blank the
rtparameter on the verification endpoint. A positive result is a successful link without a valid state value.
Notes for anyone hunting similar bugs
This bug sits where two common weaknesses meet: a CSRF token that is not treated as a secret, and a file that can be loaded from another website. During recon, the signals are tokens appearing in more places than the one form that needs them, especially in JSON responses, and JavaScript files served from the main application host that contain session-specific values.
A practical approach is to capture the token from a normal flow, then search the application's JavaScript and JSON responses for that exact value. Any hit in a file that can be included from another site is a candidate. The researcher showed the impact by completing the link end to end with a dummy account and showing the connected account in the victim's settings, which is the kind of concrete, checkable result that makes a CSRF report convincing.
Glossary
- Account linking: connecting an outside account, such as Gmail or Facebook, to a site's own account so the outside account can be used to sign in.
- Anti-CSRF token: a secret value that a site includes in a request to prove the request came from its own pages and not from another site.
- Badoo: the dating and social website targeted in this report.
- Code (OAuth code): a short confirmation value that Google issues after a user agrees to connect an account, which the site uses to finish the connection.
- Cookie: a small piece of data a site asks the browser to store and send back on every request to that site, often used to keep a user logged in.
- CORS: a set of rules that lets a site choose to allow other sites to read its responses; without it, browsers block such reads.
- CSRF (Cross-Site Request Forgery): an attack where another website makes a logged-in user's browser send a request that the target site treats as the user's own action.
- CSS: a file format that describes how a web page looks; it can be loaded from another site with a
<link>tag. - Content-type sniffing: a browser's habit of guessing what kind of data a response contains from its contents rather than its declared type.
- Dummy account: a throwaway account used for testing.
- Endpoint: a specific address on a website that performs a particular action or returns particular data.
- Global variable: a variable defined at the top level of a script, which any code on the page that loaded the script can read.
- Google: the identity provider whose account linking flow is used in this report.
- Host: the part of a web address that names the server, here
eu1.badoo.com. - JavaScript: the programming language that web pages run in the browser.
- JSON: a plain text format for sending structured data between a site and a page.
- JSONP: an older technique for loading JSON data as a script so that another site can read it.
Locationheader: a response header that tells the browser to go to a different address.- OAuth: the standard way a site asks an outside provider, such as Google, for permission to use an account.
- Parameter: a named value in a URL, appearing after the
?and separated by&, such asrt=.... - Proof of concept (PoC): a working demonstration that shows a vulnerability is real.
- Recon: the information-gathering phase of security testing.
- Redirect: a response that sends the browser to a different address.
rt: the anti-CSRF token used by Badoo's account-linking flow, unique per user and session.- Same-origin policy: a browser rule that stops a page from one site reading responses from another site, with exceptions such as script files.
- Service worker: a script a site can register in the browser to handle background tasks; here it is the file that leaked the token.
- Session: the period during which a site remembers a logged-in user, usually tied to a cookie.
- State value: the value an OAuth flow uses to tie a returning request to the session that started it; here it is
rt. - Token: a short string used to identify a session or prove a request is legitimate.
- URL: the address of a resource on the web.
- Victim: the logged-in user whose account the attacker is trying to take over.