CSRF in the "Add restaurant picture" function
The photo upload request for a restaurant lacked a valid CSRF token because the X-CSRF-TOKEN header was set to 'Undefined', and the second form had no CSRF protection. An attacker could trick a victim into uploading arbitrary photos to their restaurant page.
- Disclosed after 12 months
##Overview
I found a CSRF vulnerability within the process responsible for adding photos for a restaurant which can lead to tricking victims into adding arbitrary photos to their restaurant's page.
##Details
The CSRF vulnerability exists due to a misconfiguration on your part in which your X-CSRF-TOKEN header is set to "Undefined" which leads to any request being accepted and processed.
Uploading a picture to your restaurant is a two step process, when you start the process you first have to upload a picture off your device to the server, after that you'll be presented with another form which will allow you to add any captions or descriptions you want to the photo. The misconfiguration in question resides in the first request (The photo upload request) which allows attackers to forge a picture upload request to the server, however the photo will not be added to the restaurant's page unless the second request from the second form (the captions and description form) is also submitted.
It's also worth noting that there're no CSRF protections in place on the second form.
##PoC
To carry out a successful attack the attacker needs to obtain two values which will tie the requests to the victim's account. these values are namely res_id and user_id. After obtaining these two values (Which are publicly available for any user and restaurant) all the attacker will have to do is to fill these values in the GET parameters in the first request with the values of the victim and the res_id parameter in the body of the second POST request. I'll provide a PoC HTML file below in order to make it easier for you to reproduce the flaw, the PoC couldn't be included here due to the huge size of it (because the first request has the binary form of the photo being uploaded in the code itself.)
After modifying the values in the two requests, click the button that says "Request 1" to submit the first request and then "Request 2" the submit the second. By this point you can now visit the photos page in your restaurant's page and you'll find a picture of a star added there.
##PoC Code:
You can download the exploit code from Mega.nz here, The file is protected so there's no need to worry about accidental disclosure.
Context
The target is the Eternal program on HackerOne, and the feature under review is the "Add restaurant picture" function. Adding a picture to a restaurant page is a two step process. First the user uploads a picture from their device to the server. After that the user is shown a second form where captions or descriptions can be added to the photo. The photo only appears on the restaurant's page once that second form is submitted as well.
Setup
The report does not describe any special accounts, roles, tools or versions. The only precondition that matters is that the attacker knows two values that tie the requests to the victim's account: res_id and user_id. The researcher states that both values are publicly available for any user and any restaurant.
Finding it
The researcher noticed that the X-CSRF-TOKEN header is set to the literal string Undefined. Because of this misconfiguration, any request carrying that header is accepted and processed. The flaw sits in the first request, the photo upload request, which lets an attacker forge a picture upload request to the server. On its own that is not enough: the photo is not added to the restaurant's page unless the second request, the one from the captions and description form, is also submitted. The researcher also notes that there are no CSRF protections in place on the second form.
Exploitation
To carry out a successful attack the attacker needs res_id and user_id for the victim. Once those are obtained, the attacker fills them into the GET parameters of the first request using the victim's values, and puts the victim's res_id into the body of the second POST request.
Step 1: Prepare the two requests
The researcher provides a PoC HTML file to make reproduction easier. The PoC itself could not be included in the report because of its size: the first request contains the binary form of the photo being uploaded inside the code. The exploit code is hosted externally:
[You can download the exploit code from Mega.nz here](https://mega.nz/#!0wpkhLJL![redacted])
The file is protected, so there is no risk of accidental disclosure. The report does not reproduce the individual requests, their parameters or their responses, so the exact URLs, headers and bodies are not available here.
Step 2: Submit the first request
After modifying the values in the two requests, the attacker clicks the button labelled "Request 1" to submit the first request. This is the photo upload request, with the victim's res_id and user_id in its GET parameters. The server accepts it because the X-CSRF-TOKEN header is set to Undefined.
Step 3: Submit the second request
Next the attacker clicks the button labelled "Request 2" to submit the second request, the captions and description form, with the victim's res_id in the body. This form has no CSRF protections in place.
Step 4: Confirm the result
At this point the attacker visits the photos page on the restaurant's page and finds a picture of a star added there. That confirms the forged upload was tied to the victim's restaurant.
Root cause
The X-CSRF-TOKEN header is set to the string Undefined, which leads to any request being accepted and processed. The second form has no CSRF protection at all. Together, the two requests that make up the upload flow can both be forged, so the whole feature is exposed to cross-site request forgery.
Impact
An attacker who knows a victim's res_id and user_id, both of which are publicly available, can trick the victim into adding arbitrary photos to their restaurant's page. The report frames this as tricking victims into the action; the photo only lands on the page once both forged requests are submitted.
Fix
The report does not describe any fix that was applied.
Variants to test
- Send a request with
X-CSRF-TOKEN: Undefinedand see whether it is processed. A positive result is a state change on the account despite the invalid token. - Look for multi step flows where only the first step is protected. A positive result is a second step that accepts a forged submission with no token.
- Check whether identifiers such as
res_idanduser_idare exposed publicly and accepted from GET parameters or request bodies. A positive result is a request that acts on another user's object using those values.
Hunting notes
This kind of bug tends to hide in multi step upload or edit flows, where protection is applied to one request and forgotten on the next. During recon, watch for CSRF tokens that are missing, empty or set to placeholder strings such as Undefined, and for identifiers that are publicly visible and accepted as request parameters. The researcher showed impact by walking through the full two request flow and confirming that a picture of a star appeared on the restaurant's page.
What happened, in plain words
A security researcher found a way to make a website add a photo to a restaurant's page without the restaurant owner ever meaning to do it. The trick relies on a weakness called CSRF, short for Cross-Site Request Forgery. In everyday terms: imagine a form at a bank that lets you transfer money, and someone else can fill in that form and get your browser to send it for you, because the bank never checks that the request really came from you. Here the "form" is the photo upload on a restaurant page, and the "someone else" is an attacker who gets your browser to send the upload for you.
The report was filed on HackerOne, a platform where researchers report security bugs to companies and sometimes get paid for them. This one was filed against a program called Eternal, by a researcher using the name 0xamir, and a bounty of 50.00 USD was paid. It was disclosed publicly on 14 September 2017. The weakness is classified as Cross-Site Request Forgery (CSRF).
Before going further, a few words that come up constantly:
- A server is the computer that runs the website and stores its data. Your browser (the client) asks it for pages and sends it information.
- A request is one message your browser sends to the server, for example "here is a photo, please save it". A response is the server's reply.
- A GET request carries its information in the address bar, the part of the URL after a question mark. A POST request carries its information in the body, a hidden part of the message that is not shown in the address bar. Think of GET as writing details on the outside of an envelope and POST as putting them inside.
- A parameter is one named piece of information in a request, like a labelled field on a form:
res_idis one,user_idis another. - A header is extra information attached to a request, separate from the address and the body, a bit like the "from" and "subject" lines on an envelope.
- A token is a short secret value the server gives your browser and expects back on later requests, so it can tell your genuine request apart from one forged by someone else. A CSRF token is exactly that kind of token, used to prove a request came from your own session.
- A session is the server's memory of you being logged in. A cookie is the small piece of data your browser stores and sends back so the server can recognise your session.
- An API is the set of addresses and rules a website exposes so that programs (and the site's own pages) can talk to it, like a service counter with specific windows for specific jobs.
- HTML is the language web pages are written in. A PoC, or proof of concept, is a small demonstration that shows a bug is real, here an HTML file.
Context
The target is the Eternal program on HackerOne, and the feature under review is the "Add restaurant picture" function. This is the part of the site where a restaurant owner puts a photo on their restaurant's page.
Adding a picture is a two step process:
- First the user uploads a picture from their device to the server.
- After that the user is shown a second form where captions or descriptions can be added to the photo.
The photo only appears on the restaurant's page once that second form is submitted as well. So the server holds the uploaded file after step one, but does not publish it until step two confirms it. Keep this two step shape in mind, because the whole bug lives in the gap between the two steps.
Setup
The report does not describe any special accounts, roles, tools or versions. You do not need to be an administrator or install anything unusual to follow it.
The only precondition that matters is that the attacker knows two values that tie the requests to the victim's account: res_id and user_id. The researcher states that both values are publicly available for any user and any restaurant. In plain terms, res_id is the identifier of a restaurant and user_id is the identifier of a user account. They are the labels the site uses to say "this photo belongs to this restaurant, uploaded by this user". Because anyone can see them, an attacker does not need to break into anything to learn them.
Finding it
The researcher noticed that the X-CSRF-TOKEN header is set to the literal string Undefined. That header is the place where the browser is supposed to send the CSRF token described above, the secret that proves the request is genuine. Instead of a real secret, the value was the word Undefined, which looks like a placeholder left behind by a programming mistake, the way a form might show "undefined" when a field was never filled in.
Because of this misconfiguration, any request carrying that header is accepted and processed.
The flaw sits in the first request, the photo upload request, which lets an attacker forge a picture upload request to the server. To forge a request means to build one that looks like it came from the victim, when in fact the attacker built it.
On its own that is not enough: the photo is not added to the restaurant's page unless the second request, the one from the captions and description form, is also submitted. The researcher also notes that there are no CSRF protections in place on the second form. So the first request accepts forged uploads and the second form has no CSRF protection.
Exploitation
To carry out a successful attack the attacker needs res_id and user_id for the victim. Once those are obtained, the attacker fills them into the GET parameters of the first request using the victim's values, and puts the victim's res_id into the body of the second POST request.
The first request takes its identifiers from the address (GET parameters), and the second takes the restaurant identifier from the hidden body (POST body). Putting the victim's values there makes the server believe the upload belongs to the victim's restaurant and account.
Step 1: Prepare the two requests
The researcher provides a PoC HTML file to make reproduction easier. The PoC itself could not be included in the report because of its size: the first request contains the binary form of the photo being uploaded inside the code. Binary form means the raw bytes of the image file, which are long and not readable as text, so the file was too big to paste into the report.
The exploit code is hosted externally:
[You can download the exploit code from Mega.nz here](https://mega.nz/#!0wpkhLJL![redacted])
Line by line, this is a single line of text: a link to a file sharing service, Mega.nz, where the PoC file was uploaded. The part after the #! is the file's identifier on that service. The researcher says the file is protected, so there is no risk of accidental disclosure, meaning it is not openly downloadable by anyone who stumbles on the link.
The report does not reproduce the individual requests, their parameters or their responses, so the exact URLs, headers and bodies are not available here.
Step 2: Submit the first request
After modifying the values in the two requests, the attacker clicks the button labelled "Request 1" to submit the first request. This is the photo upload request, with the victim's res_id and user_id in its GET parameters. The server accepts it because the X-CSRF-TOKEN header is set to Undefined.
Why a button in an HTML file? Because the attacker's goal is to get the victim's own browser to send the request. A page the attacker controls can contain a button, or code that presses it automatically, and when the victim's browser sends the request it also sends the victim's cookies, so the server sees a logged-in user. The broken token check is what stops the server from rejecting it.
Step 3: Submit the second request
Next the attacker clicks the button labelled "Request 2" to submit the second request, the captions and description form, with the victim's res_id in the body. This form has no CSRF protections in place.
This second step is the one that actually publishes the photo, which is why the attack needs both. Skipping it would leave the upload sitting on the server without ever appearing on the page.
Step 4: Confirm the result
At this point the attacker visits the photos page on the restaurant's page and finds a picture of a star added there. That confirms the forged upload was tied to the victim's restaurant. Seeing the star is the visible proof that both forged requests went through and the server treated them as the victim's own actions.
Root cause
The X-CSRF-TOKEN header is set to the string Undefined, which leads to any request being accepted and processed. Origin here means which site the request came from; normally a server should refuse state-changing requests that did not originate from its own pages.
The second form has no CSRF protection at all. Together, the two requests that make up the upload flow can both be forged, so the whole feature is exposed to cross-site request forgery.
Impact
An attacker who knows a victim's res_id and user_id, both of which are publicly available, can trick the victim into adding arbitrary photos to their restaurant's page. Arbitrary here means any picture the attacker chooses, not one the owner picked. The report frames this as tricking victims into the action; the photo only lands on the page once both forged requests are submitted.
Fix
The report does not describe any fix that was applied. In everyday terms: the server should check that the token is a genuine, unexpired secret tied to the user's session, and refuse the request if it is missing, empty, or a placeholder like Undefined.
Variants to test
If you want to look for the same kind of bug yourself, these are the checks the write-up suggests. Each one is a small experiment with a clear sign of success.
- Send a request with
X-CSRF-TOKEN: Undefinedand see whether it is processed. A positive result is a state change on the account despite the invalid token. A state change means something actually changed, such as a new photo appearing, rather than the server politely refusing. - Look for multi step flows where only the first step is protected. A positive result is a second step that accepts a forged submission with no token. Multi step means a task split across two or more requests, like the upload and then the caption here.
- Check whether identifiers such as
res_idanduser_idare exposed publicly and accepted from GET parameters or request bodies. A positive result is a request that acts on another user's object using those values. An object is simply a thing the site stores, such as a restaurant page or a photo.
Hunting notes
This kind of bug tends to hide in multi step upload or edit flows, where protection is applied to one request and forgotten on the next. During recon, watch for CSRF tokens that are missing, empty or set to placeholder strings such as Undefined, and for identifiers that are publicly visible and accepted as request parameters. Recon means the early exploration of a site to see how it is built and where its parts connect.
The researcher showed impact by walking through the full two request flow and confirming that a picture of a star appeared on the restaurant's page.
Glossary
- API: the set of addresses and rules a website exposes so that programs and its own pages can talk to it, like a service counter with specific windows for specific jobs.
- Binary form: the raw bytes of a file such as an image, as opposed to readable text.
- Body: the hidden part of a request that carries data, not shown in the address bar.
- Bounty: a payment a company makes to a researcher for a valid security report.
- Browser: the program on your computer that displays web pages and sends requests to servers.
- Client: the program making requests, usually your browser, as opposed to the server answering them.
- Cookie: a small piece of data your browser stores and sends back to a site so the server can recognise your session.
- Cross-Site Request Forgery (CSRF): a weakness where another site can make your browser send a request the target site treats as your own action.
- CSRF token: a secret value the server gives your browser and expects back on state-changing requests, used to prove the request is genuine.
- GET request: a request that carries its information in the URL, after a question mark.
- HackerOne: a platform where researchers report security bugs to companies and may receive bounties.
- Header: extra information attached to a request or response, separate from the address and the body.
- HTML: the language web pages are written in.
- Identifier: a value such as
res_idoruser_idthat names a specific record, here a restaurant or a user account. - Misconfiguration: a setting or piece of code left in a wrong state, often by mistake, that weakens security.
- Multi step flow: a task split across two or more requests, where later steps depend on earlier ones.
- Object: a thing the site stores, such as a restaurant page or a photo.
- Origin: which site a request came from; servers normally refuse state-changing requests that did not come from their own pages.
- Parameter: one named piece of information in a request, like a labelled field on a form.
- PoC (proof of concept): a small demonstration, here an HTML file, that shows a bug is real.
- POST request: a request that carries its information in the body rather than the URL.
- Recon: early exploration of a site to understand how it is built and where its parts connect.
- Request: one message a browser sends to a server.
- Response: the server's reply to a request.
- Server: the computer that runs a website and stores its data.
- Session: the server's memory of you being logged in.
- State change: an actual modification on the server, such as a new photo being added, as opposed to a request that changes nothing.
- Token: a short secret value used to prove identity or authenticity.
- URL: the address of a page or resource on the web.