JSON CSRF attack on a social networking site
The mobile site accepted JSON-formatted POST requests for sensitive actions like deleting an account or erasing contacts without any CSRF token. An attacker could craft an HTML form that submits a JSON payload using text/plain encoding, so when a logged-in victim opened the page, their account or contacts would be deleted.
Published on medium.com
Before describing the actual attack scenario let us first discuss what is CSRF attack ?
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.
Context
Badoo is a social networking site, and the mobile web application at m.badoo.com exposes an API endpoint, api.phtml, that takes a query string parameter naming the action to perform. The researcher was testing the Badoo program on HackerOne and found two of these actions interesting: one that deletes the account of a registered user and one that resets the trusted network, which removes all of a user's contacts on the site.

The report opens with a short explanation of CSRF for context. If a victim has an active session on a site and the requests that leave a settings page carry no CSRF token, an attacker can craft an HTML file or an image containing the values to be written into the victim's settings, using <form>, <input> and similar elements. As soon as the victim opens the file, the settings are updated with the attacker's content. Two conditions must hold for the attack: no token travels with the requests from the site, and the victim has an active session on that site.
Setup
The work was done by browsing m.badoo.com with Burp Suite as an intercepting proxy, looking at the requests the application sends. The attack needs the victim to be logged in to m.badoo.com when the crafted page is opened, and the requests to carry no CSRF token. No special account, role or tool version is described beyond Burp Suite.
Finding it
While searching for bugs on m.badoo.com, the researcher found this request in Burp Suite:
https://m.badoo.com/api.phtml?SERVER_DELETE_ACCOUNT
Its data was sent in JSON format, and it deleted the account of a registered user. A second request did the same kind of thing:
https://m.badoo.com/api.phtml?SERVER_RESET_TRUSTED_NETWORK
This one was meant to delete all the contacts of a user on the site. Neither request carried a CSRF token. The obstacle was that the body was JSON, so an ordinary HTML form could not produce it, and the researcher had to find a way to build an HTML file for the CSRF proof of concept. Two files were crafted, one for erasing imported contacts and one for deleting the account.
Exploitation
Step 1: Build the form around the JSON body
The content type was JSON, and the parser introduced = at the end of the content in the header, which prevented the attack from triggering. The bypass is to add your own pair of values at the end, as the researcher did with "ignore_me":"' value='test". The HTML for erasing contacts is:
<html><head><meta name="DNT" content="1"><meta name="Connection" content="close"></head><body><form action="https://m.badoo.com/api.phtml?SERVER_RESET_TRUSTED_NETWORK" method="POST" enctype="text/plain"><input name='{"$gpb":"badoo.bma.BadooMessage","version":1,"message_type":327,"body":[],"is_background":false, "ignore_me":"' value='test"}' type="hidden"><input type="submit"></body></html>
The form posts to the SERVER_RESET_TRUSTED_NETWORK action. The JSON payload sits in the name attribute of a hidden input, and the added ignore_me pair is the researcher's bypass for the = the parser appends. The enctype is text/plain, which is the detail the researcher stresses: the JSON payload in the name parameter is not accepted as JSON content type unless enctype="text/plain" is set on the form. That makes it a little different from a basic HTML form generated for CSRF.
Step 2: Victim opens the page
When the victim, with an active session on m.badoo.com, opens the HTML file in the browser, the form is submitted to the API and the action runs. The response shown in the browser was:
"Your contacts are being erased, this could take up to 5 minutes."
Step 3: Result
The researcher received a 280 USD bounty from Badoo through HackerOne for this bug.

Root cause
The API actions on m.badoo.com accepted state-changing requests without any CSRF token. The JSON body was not a defence: with enctype="text/plain" the crafted form still triggered the action. and the trailing = that the parser appends can be neutralised with an extra key. The report does not describe any other defence, such as origin checks, that was in place.
Impact
An attacker who gets a logged-in victim to open the crafted page can erase the victim's imported contacts or delete the victim's account, depending on which action is targeted. The attack requires the victim to have an active session on m.badoo.com and to open the attacker's HTML file; the report does not describe any other precondition.
Fix
The obvious fix is to require a CSRF token on these API actions and to reject state-changing requests that do not carry it, together with checking the request origin.
Variants to test
- Look for API endpoints that take JSON bodies and perform state changes, such as account deletion, contact removal or settings updates, and check whether a token is sent. A positive result is a request that succeeds when replayed from a page on another origin with the victim's session.
- Try the
enctype="text/plain"form with the JSON payload in an inputname, adding a dummy key at the end to absorb the appended=. A positive result is the server parsing the body as JSON and performing the action. - Try the same technique against endpoints that accept other structured bodies, adjusting the dummy key so the appended character lands inside a string value. A positive result is the action executing without a token.
What happened, in plain words
Badoo is a social networking site, a place where people create a profile, add contacts and chat. Like most sites it has a mobile version, m.badoo.com, which is the version you get in a phone browser. Behind that mobile site there is an API: a set of addresses the browser calls to do things, such as loading your profile or deleting your account. Think of an API as a service counter in a shop. Your browser walks up to the counter, shows a stamp proving who you are, and asks for something to be done. The counter does not ask many questions; it trusts the stamp.
A security researcher was testing Badoo through HackerOne, a platform where companies invite researchers to look for bugs and pay for good findings. He found two counter requests that did serious things: one deleted a user's account, and one erased all of a user's contacts. Neither request carried a special one-time code that proves the request really came from the site's own pages. That missing code is the bug, and it has a name: CSRF, or cross-site request forgery.

The idea behind CSRF is simple. Your browser keeps a stamp for each site you are logged in to, usually a cookie, which is a small piece of data the site stored in your browser earlier. Every time your browser talks to that site, it shows the stamp automatically. The site cannot tell whether the request came from its own page or from a page some attacker made you open, because the stamp looks the same either way. So if an attacker can make your browser send a request to the site, the site will do what the request says, believing it was you.
The researcher's report starts by explaining this in his own words. If you have an active session on a site, meaning you are logged in, and the requests leaving a settings page carry no CSRF token, an attacker can build an HTML file or an image containing the values to be written into your settings, using <form>, <input> and similar elements. As soon as you open that file, your settings are updated with the attacker's content. Two conditions must hold: no token travels with the requests, and you have an active session on the site.
A CSRF token is a random value the site puts into its own pages and expects back with every state-changing request. Because an attacker's page cannot read that value, it cannot include it, and the site can reject the request. It is like a shop that asks for a password written on today's receipt: a stranger can copy your face but not the receipt.
Setting up
The researcher browsed m.badoo.com with Burp Suite running as an intercepting proxy. A proxy is a program that sits between your browser and the internet and lets you read and change everything that passes. Think of it as a post office clerk who opens every letter, reads it, and can rewrite it before sending it on. With Burp Suite in that position, the researcher could see the exact requests the mobile site sent, including the ones that delete an account or erase contacts.
The attack needs the victim to be logged in to m.badoo.com when the crafted page is opened, and the requests to carry no CSRF token. No special account, role or tool version is described beyond Burp Suite.
Finding it
While searching for bugs on m.badoo.com, the researcher found this request in Burp Suite:
https://m.badoo.com/api.phtml?SERVER_DELETE_ACCOUNT
Line by line: https:// is the secure web protocol. m.badoo.com is the mobile site. /api.phtml is the single page that acts as the service counter for many actions. The ? starts the query string, the part of the address that carries extra instructions. SERVER_DELETE_ACCOUNT is the name of the action being asked for, and its name says it deletes the account of a registered user. The data for the action travelled in JSON format, which is a way of writing structured data as text, using curly brackets, quoted names and values, much like a labelled form.
A second request did the same kind of thing:
https://m.badoo.com/api.phtml?SERVER_RESET_TRUSTED_NETWORK
Same counter, same style of address, but the action is SERVER_RESET_TRUSTED_NETWORK, which was meant to delete all the contacts of a user on the site. Neither request carried a CSRF token. That is the finding: neither request carried a CSRF token.
The obstacle was that the body, the part of the request carrying the data, was JSON. An ordinary HTML form, the kind you fill in on a web page, cannot produce a JSON body; it can only send simple name and value pairs. So the researcher had to find a way to build an HTML file for the CSRF proof of concept, a small demonstration that proves the attack works. Two files were crafted, one for erasing imported contacts and one for deleting the account.
Exploitation
Step 1: Build the form around the JSON body
The content type was JSON, and the parser, the part of the server that reads the incoming data, introduced = at the end of the content in the header. That extra character broke the JSON, so the attack would not trigger. The bypass is to add your own pair of values at the end, as the researcher did with "ignore_me":"' value='test". The researcher bypassed the appended = by adding an extra pair of values at the end. The HTML for erasing contacts is:
<html><head><meta name="DNT" content="1"><meta name="Connection" content="close"></head><body><form action="https://m.badoo.com/api.phtml?SERVER_RESET_TRUSTED_NETWORK" method="POST" enctype="text/plain"><input name='{"$gpb":"badoo.bma.BadooMessage","version":1,"message_type":327,"body":[],"is_background":false, "ignore_me":"' value='test"}' type="hidden"><input type="submit"></body></html>
Line by line. <html> opens the page. <head> holds information about the page rather than visible content. <meta name="DNT" content="1"> and <meta name="Connection" content="close"> are small hints to the browser. <body> starts the visible part. <form action="https://m.badoo.com/api.phtml?SERVER_RESET_TRUSTED_NETWORK" method="POST" enctype="text/plain"> creates a form that will send its contents to the SERVER_RESET_TRUSTED_NETWORK action using the POST method, which is the method used to submit data, and with the encoding type text/plain, which sends the data as plain text rather than as the usual form encoding. <input name='{"$gpb":"badoo.bma.BadooMessage","version":1,"message_type":327,"body":[],"is_background":false, "ignore_me":"' value='test"}' type="hidden"> is a hidden field, invisible to the user, whose name is the JSON payload itself. The JSON contains a $gpb field naming the message type, a version, a message_type number, an empty body, an is_background flag, and the added ignore_me key whose value is ' value='test. That last key is the trick that absorbs the = the parser appends. <input type="submit"> is the button that sends the form. The closing tags end the page.
The form posts to the SERVER_RESET_TRUSTED_NETWORK action. The JSON payload sits in the name attribute of a hidden input, and the ignore_me key with its ' value='test tail absorbs the = that the parser appends. The enctype is text/plain, which is the detail the researcher stresses: the JSON payload in the name parameter is not accepted as JSON content type unless enctype="text/plain" is set on the form. That makes it a little different from a basic HTML form generated for CSRF.
Why does this work? A browser will happily send a form to any site, and it will attach that site's cookies automatically. The attacker's page never reads the response; it only needs the request to arrive. The server receives a POST to its own API with the victim's session and performs the action.
Step 2: The victim opens the page
When the victim, with an active session on m.badoo.com, opens the HTML file in the browser, the form is submitted to the API and the action runs. The response shown in the browser was:
"Your contacts are being erased, this could take up to 5 minutes."
That message is the site confirming the action. The victim did nothing except open a file; the request was sent by the browser on the attacker's behalf.
Step 3: The result
The researcher received a 280 USD bounty from Badoo through HackerOne for this bug.

Why it worked
The API actions on m.badoo.com accepted state-changing requests without any CSRF token. Authorise here means the server decided the request was allowed. The JSON body was not a defence: with enctype="text/plain" the crafted form still triggered the action. and the trailing = that the parser appends can be neutralised with an extra key. The report does not describe any other defence, such as origin checks, that was in place. An origin check is a server rule that looks at which site the request came from and refuses requests from other sites.
What an attacker could do
An attacker who gets a logged-in victim to open the crafted page can erase the victim's imported contacts or delete the victim's account, depending on which action is targeted. The attack requires the victim to have an active session on m.badoo.com and to open the attacker's HTML file; the report does not describe any other precondition. The victim did nothing except open the file, and the site showed its confirmation message.
The fix
The obvious fix is to require a CSRF token on these API actions and to reject state-changing requests that do not carry it, together with checking the request origin. In plain terms: the counter should ask for the password written on today's receipt, and should also check that the person at the counter came from the shop's own door.
Other places to look
- Look for API endpoints that take JSON bodies and perform state changes, such as account deletion, contact removal or settings updates, and check whether a token is sent. A positive result is a request that succeeds when replayed from a page on another origin with the victim's session.
- Try the
enctype="text/plain"form with the JSON payload in an inputname, adding a dummy key at the end to absorb the appended=. A positive result is the server parsing the body as JSON and performing the action. - Try the same technique against endpoints that accept other structured bodies, adjusting the dummy key so the appended character lands inside a string value. A positive result is the action executing without a token.
Glossary
- API: a set of addresses a program calls to ask a service to do something, like a service counter in a shop.
- Badoo: a social networking site where people create profiles, add contacts and chat.
- Bounty: money a company pays a researcher for reporting a valid security bug.
- Browser: the program you use to visit web pages, such as Chrome or Firefox.
- Burp Suite: a tool that sits between your browser and the internet so you can read and change requests.
- Cookie: a small piece of data a site stores in your browser and that your browser sends back automatically, often used to keep you logged in.
- CSRF (cross-site request forgery): an attack where a page on one site makes your browser send a request to another site where you are logged in, and that site acts on it.
- CSRF token: a random value a site puts into its own pages and expects back with state-changing requests, so a foreign page cannot forge them.
- Content type: a label on a request or response saying what format the data is in, such as JSON or plain text.
- Encoding type (
enctype): the setting on an HTML form that decides how its data is formatted when sent. - Endpoint: a specific address on a server that performs a specific action.
- Form: the part of an HTML page that collects data and sends it to a server.
- HackerOne: a platform where companies invite researchers to test their systems and report bugs.
- HTML: the language web pages are written in.
- HTTP: the protocol browsers and servers use to exchange requests and responses.
- Input: a field in an HTML form that holds a value to be sent.
- JSON: a way of writing structured data as text, using curly brackets, quoted names and values.
- Method (POST): the part of an HTTP request that says what kind of action is wanted; POST is used to submit data.
- Origin check: a server rule that looks at which site a request came from and refuses requests from other sites.
- Parser: the part of a server that reads incoming data and turns it into something the program can use.
- Payload: the data carried inside a request.
- Proof of concept: a small demonstration that proves an attack works.
- Proxy: a program that sits between your browser and the internet and lets you read and change traffic.
- Query string: the part of a web address after the
?that carries extra instructions. - Request: a message a browser sends to a server asking it to do something.
- Response: the message a server sends back.
- Session: the period during which a site remembers you as logged in.
- State-changing request: a request that changes something on the server, such as deleting data or updating settings.
- Trusted network: in this report, the set of a user's contacts on the site, which the
SERVER_RESET_TRUSTED_NETWORKaction erases.