Full access to any list
The endpoint that adds a collaborator to a shopping list did not check whether the caller owned or had access to that list. Any logged-in user could add their own email to an arbitrary list and then read, edit or delete it.
Originally disclosed on HackerOne
- Triaged in 10 days
- Fixed in 15 days
- Paid in 15 days
- Disclosed after 45 days
Summary by the researcher
Big thanks to @cxmcc-instacart for helping out. And big no thanks to @hitomikt for zero communication and no apology.
The report
Overview
The endpoint for adding a list collaborator lacks authorization checks. A regular Instacart user can add themselves as a collaborator to any list and thus get full control over that list.
How to Reproduce
-
Choose a list that you want to edit, for example the one with id = 10.
-
Log in to Instacart.
-
Copy the cookie and anti-CSRF headers from one of the requests.
-
Send a request:
POST /api/v2/list_users Host: www.instacart.com Content-Type: application/json Cookie: ... X-CSRF-Token: ... {"list_user":{"list_id":10,"email":"[email protected]"}} -
Open
https://www.instacart.com/api/v2/lists/10in browser and grab the list's token (7bHoerQin this case). -
Open
http://www.instacart.com/store/giant/lists/7bHoerQ/editin browser and do whatever you want to the list.
Proof of Concept
GET https://www.instacart.com/api/v2/lists/10
{"meta":{"code":200},"data":{"id":10,"name":"Test sameoldstory" ...
Security Implications
This vulnerability can be used to:
- See metadata of a private list.
- See the personal name of a list owner, even if they chose to hide it.
- Change metadata and items or even delete any list.
- Affect product promotion by messing with popular lists.
- Perform website defacement and phishing attacks.
- Enhance stored XSS attacks by embedding them into the popular lists.
Context
Instacart is a grocery delivery service with a web application at www.instacart.com. Among its features are shopping lists, which users can share with other people by adding them as collaborators. A collaborator can edit the list: its metadata and its items. Lists have numeric identifiers, and the API exposes them under /api/v2/lists/<id>. The endpoint responsible for adding a collaborator is POST /api/v2/list_users, which takes a JSON body naming the list and the email address of the person to add.
Setup
The only precondition is an ordinary Instacart account. The researcher logs in as a regular user, picks a target list by its numeric id (the report uses id 10 as an example), and copies two things from an authenticated request: the session cookie and the anti-CSRF header. No special role, tool or version is mentioned.
Finding it
The researcher found that the collaborator endpoint performs no authorisation check on the list being modified. Nothing verifies that the caller owns the list or has any relationship to it. Because the request body simply names a list_id and an email, any authenticated user can add their own address as a collaborator to somebody else's list, and the application then treats them as a legitimate collaborator with full control over it.
Exploitation
Step 1: choose a target list
Pick the list to take over, identified by its numeric id. The report uses 10 throughout.
Step 2: log in
Log in to Instacart with a normal account.
Step 3: collect the session and CSRF values
Copy the cookie and the anti-CSRF header from one of your own authenticated requests. These are the only credentials the attack needs; the CSRF token is a valid one from the attacker's own session, so the anti-CSRF defence does not stand in the way.
Step 4: add yourself as a collaborator
Send the following request, substituting your own cookie, CSRF token and email address:
POST /api/v2/list_users
Host: www.instacart.com
Content-Type: application/json
Cookie: ...
X-CSRF-Token: ...
{"list_user":{"list_id":10,"email":"[redacted]"}}
The body names the victim's list in list_id and the attacker's address in email. The server accepts it and creates the collaborator relationship without checking who owns list 10.
Step 5: retrieve the list token
Open the list's API representation in the browser:
https://www.instacart.com/api/v2/lists/10
and take the list's token from the response. In the report this token is 7bHoerQ.
Step 6: use the edit interface
Open the edit page for the list, using the token from the previous step:
http://www.instacart.com/store/giant/lists/7bHoerQ/edit
From there the attacker can do whatever they want to the list.
Proof of concept
The researcher shows the list API responding successfully for the targeted id:
GET https://www.instacart.com/api/v2/lists/10
{"meta":{"code":200},"data":{"id":10,"name":"Test sameoldstory" ...
The 200 code and the returned list object, including its name, show the list API returning the targeted list's data.
Root cause
The list_users creation endpoint trusts the list_id supplied by the client and creates the collaborator record without verifying that the caller has any right to that list. Authorisation is missing at the object level: the request carries a session cookie and an X-CSRF-Token header, but neither ties the request to the list's owner, but neither ties the request to the list's owner. The CSRF token is a valid one from the attacker's own session, so the anti-CSRF defence does not stand in the way.
Impact
With collaborator access to an arbitrary list, an attacker can:
- see metadata of a private list;
- see the personal name of a list owner, even if the owner chose to hide it;
- change metadata and items, or delete the list entirely;
- affect product promotion by tampering with popular lists;
- perform website defacement and phishing attacks;
- enhance stored XSS attacks by embedding them in popular lists.
The last two depend on how list content is rendered elsewhere, and the report presents them as consequences of controlling a popular list rather than as separately demonstrated issues. The bounty was 150.00 USD and the report was disclosed on 2016-11-18.
Fix
The report does not describe the fix that was applied. The change needed is an authorisation check on POST /api/v2/list_users: the server should confirm that the caller owns the list named in list_id, or otherwise holds a role that permits adding collaborators, before creating the record. The same check should apply to any endpoint that reads or modifies a list by id.
Variants to test
- Other object-creating endpoints. Look for POST endpoints whose body contains an object id plus a user identifier (email, user id, username). A positive result is a
200and a new relationship visible from the attacker's account for an object the attacker does not own. - Numeric id enumeration. Try sequential ids on read endpoints such as
/api/v2/lists/<id>. A positive result is a200with another user's data instead of a403or404. - Token leakage through the API. Check whether read endpoints return share tokens or edit links for objects the caller should not see. A positive result is a token in the response that grants access to the edit interface.
- Hidden profile fields. After gaining access, check whether owner names marked as hidden are still returned. A positive result is a name in the response that the owner had chosen not to display.
Hunting notes
This class of bug hides in endpoints that create relationships between a user and an object, especially where the object id comes straight from the request body. During recon, watch for APIs that expose objects by sequential numeric id and return rich JSON, since the same id space is usually accepted on write endpoints. The signal is a create or update call that succeeds for an id you have no relationship with. To show impact, the researcher demonstrated the full chain: adding themselves, reading the list through the API with a 200, obtaining the list token, and reaching the edit interface. The researcher demonstrated the full chain: adding themselves, reading the list through the API with a 200, obtaining the list token, and reaching the edit interface.
A note on coordination
The researcher credits @cxmcc-instacart for assistance and states that @hitomikt provided no communication and no apology.
What happened, in plain words
Instacart is a grocery delivery service. Its website lets you keep shopping lists, and you can share a list with other people by adding them as collaborators. A collaborator can change the list: its name and details, and the items on it.
A researcher found that the part of the website responsible for adding a collaborator never checked whether the person sending the request had any right to the list in question. Any logged-in user could name somebody else's list and their own email address, and the site would happily add them as a collaborator. From that point the attacker had full control over the list.
The researcher demonstrated adding themselves to a list, reading the list through the site's API, obtaining the list's token, and opening the edit page. The report was disclosed on 2016-11-18 and the bounty was 150.00 USD.
Background you need
What an API is
A website has two faces. One is the pages you see in a browser: buttons, menus, pictures. The other is a set of addresses that the pages quietly talk to in order to fetch and save data. That second face is the API (application programming interface). A useful comparison is a restaurant: the dining room is the website you see, and the kitchen door where orders go in and plates come out is the API. You normally never look at the kitchen door, but you can knock on it directly if you know its address.
API addresses often look like https://www.instacart.com/api/v2/lists/10. The /api/v2/ part marks it as an API address, lists says which kind of thing is being asked about, and 10 is the identifier of one particular list.
What an identifier is
Every list on the site has a number that identifies it, called an id. The report uses the list with id 10 as its example.
What a cookie is
When you log in, the server needs a way to recognise you on your next request. It sends your browser a small piece of text called a cookie, and the browser sends it back with every request to that site. Think of it as a wristband you get at an event: the door staff check the wristband instead of asking for your name every time. Anyone who copies your wristband can walk in as you, which is why the cookie in this report is treated as a secret.
What a CSRF token is
A CSRF token (cross-site request forgery token) is a second, different piece of text that the site also expects on requests that change something. Its purpose is to prove the request came from the site's own pages and not from a malicious page that tricked your browser into sending something. It travels in a header, here X-CSRF-Token. A header is a labelled line of extra information attached to a request, separate from the body.
What authorisation means
Two words sound alike and mean different things. Authentication answers "who are you?" and is handled by the cookie: without logging in, you get nowhere. Authorisation answers "are you allowed to do this?" and is a separate check. A building can check your badge at the door (authentication) and still let you into every room (missing authorisation). This report is about the second check being absent.
What the vulnerability class means
The weakness is listed as privilege escalation, and more precisely it is a missing object-level authorisation check, sometimes called an insecure direct object reference. The site accepts an object id from the request and acts on it without asking whether the caller has any relationship to that object. The everyday comparison: a hotel reception that hands out a room key to anyone who states a room number, without checking that the person is the guest in that room.
What the feature does
Shopping lists can be shared. The endpoint (a single API address that performs one job) for adding a collaborator is POST /api/v2/list_users. POST is the method used when you are creating something. The request carries a JSON body, which is a small structured text block naming the list and the email address of the person to add.
Setting up
The only thing needed is an ordinary Instacart account. No special role, no tool and no particular software version is mentioned in the report.
- Log in as a regular user.
- Pick the list you want to take over, by its numeric id. The report uses
10throughout. - Copy two values from one of your own logged-in requests: the session cookie and the anti-CSRF header.
Step 3 deserves a word. The CSRF token you copy is a perfectly valid one, but it is valid for your session, not the victim's. The CSRF token you copy is a valid one, but it is valid for your own session, not the victim's. It simply was never designed to prove that the session belongs to the list's owner, so it does not stand in the way here.
Finding the hole
The researcher found that the collaborator endpoint performs no authorisation check on the list being modified. Nothing verifies that the caller owns the list or has any relationship to it.
Because the request body simply names a list_id and an email, any logged-in user can put their own address into email and somebody else's list into list_id. The server accepts it and creates the collaborator record. From that moment the application treats the attacker as a legitimate collaborator, with full control over the list.
Carrying out the attack
Step 1: choose a target list
Pick the list to take over, identified by its numeric id. The report uses 10 throughout. The report uses 10 throughout.
Step 2: log in
Log in to Instacart with a normal account. The attack is not about getting in without an account, it is about what an ordinary account is allowed to do once inside.
Step 3: collect the session and CSRF values
Copy the cookie and the anti-CSRF header from one of your own authenticated requests. These two values are the only credentials the attack needs.
Step 4: add yourself as a collaborator
Send the following request, substituting your own cookie, CSRF token and email address:
POST /api/v2/list_users
Host: www.instacart.com
Content-Type: application/json
Cookie: ...
X-CSRF-Token: ...
{"list_user":{"list_id":10,"email":"[redacted]"}}
Line by line:
POST /api/v2/list_usersis the address being called and the method.POSTmeans "create something here", and the something is a link between a list and a user.Host: www.instacart.comsays which website the request is for. One server can host many sites, so the request names the one it wants.Content-Type: application/jsontells the server that the body is written in JSON, so it knows how to read it.Cookie: ...is where your session wristband goes. The dots stand for the real value, which is a secret and is not reproduced here.X-CSRF-Token: ...is the anti-CSRF value from your own session.- The blank line separates the headers from the body.
{"list_user":{"list_id":10,"email":"[redacted]"}}is the body. It says: create alist_user(a collaborator record) for the list with id10, for the person with the address[redacted]. The victim's list is named inlist_id; the attacker's address is inemail.
The server accepts it and creates the collaborator relationship without checking who owns list 10. That single missing check is the whole vulnerability.
Step 5: retrieve the list token
Open the list's API representation in the browser:
https://www.instacart.com/api/v2/lists/10
This is a plain GET request, the kind your browser makes whenever you open an address. It asks the API to describe list 10. The answer includes the list's token. In the report this token is 7bHoerQ. In the report this token is 7bHoerQ. The report calls it the list's token and uses it in the edit page address.
Step 6: use the edit interface
Open the edit page for the list, using the token from the previous step:
http://www.instacart.com/store/giant/lists/7bHoerQ/edit
From there the attacker can do whatever they want to the list: change its details, change its items, or delete it.
Proof of concept
The researcher shows the list API responding successfully for the targeted id:
GET https://www.instacart.com/api/v2/lists/10
{"meta":{"code":200},"data":{"id":10,"name":"Test sameoldstory" ...
Line by line:
GET https://www.instacart.com/api/v2/lists/10is the request: describe list10.{"meta":{"code":200},...}is the start of the answer.200is the standard HTTP status code for "OK, here it is". A refusal would normally look like403(forbidden) or404(not found)."data":{"id":10,"name":"Test sameoldstory" ...is the list itself. The...means the response continues; the report only quotes the beginning. The response shows the list object, including its name, returned for the targeted id.
Why it works
The list_users creation endpoint trusts the list_id supplied by the client and creates the collaborator record without verifying that the caller has any right to that list. Authorisation is missing at the object level.
The request carries a session cookie and an X-CSRF-Token header, but neither ties the request to the list's owner. But neither of them ties the request to the list's owner. The CSRF token only proves the request came from the attacker's own session, which is exactly what the attacker has.
What an attacker could do with it
With collaborator access to an arbitrary list, an attacker can:
- see metadata of a private list;
- see the personal name of a list owner, even if the owner chose to hide it;
- change metadata and items, or delete the list entirely;
- affect product promotion by tampering with popular lists;
- perform website defacement and phishing attacks;
- enhance stored XSS attacks by embedding them in popular lists.
A few of these need unpacking. Metadata is the information about a list rather than its contents: its name, for example. Defacement means changing what visitors see so the site shows the attacker's content. Phishing means planting content that tricks people into handing over information. Stored XSS (cross-site scripting) is when an attacker manages to save code into a site so that it runs in other visitors' browsers later; the report presents it as something that could be made worse by placing it in a popular list.
The last two depend on how list content is rendered elsewhere on the site, and the report presents them as consequences of controlling a popular list rather than as separately demonstrated issues.
The fix
The report does not describe the fix that was applied. The change needed is an authorisation check on POST /api/v2/list_users: the server should confirm that the caller owns the list named in list_id, or otherwise holds a role that permits adding collaborators, before creating the record. The same check should apply to any endpoint that reads or modifies a list by id.
Similar things to look for
- Other object-creating endpoints. Look for
POSTendpoints whose body contains an object id plus a user identifier (email, user id, username). A positive result is a200and a new relationship visible from the attacker's account for an object the attacker does not own. - Numeric id enumeration. Try sequential ids on read endpoints such as
/api/v2/lists/<id>. A positive result is a200with another user's data instead of a403or404. - Token leakage through the API. Check whether read endpoints return share tokens or edit links for objects the caller should not see. A positive result is a token in the response that grants access to the edit interface.
- Hidden profile fields. After gaining access, check whether owner names marked as hidden are still returned. A positive result is a name in the response that the owner had chosen not to display.
How to spot this kind of bug
This class of bug hides in endpoints that create relationships between a user and an object, especially where the object id comes straight from the request body. During recon, watch for APIs that expose objects by sequential numeric id and return rich JSON, since the same id space is usually accepted on write endpoints. The signal is a create or update call that succeeds for an id you have no relationship with.
To show impact, the researcher demonstrated the full chain: adding themselves, reading the list through the API with a 200, obtaining the list token, and reaching the edit interface. The researcher demonstrated the full chain: adding themselves, reading the list through the API with a 200, obtaining the list token, and reaching the edit interface.
A note on coordination
The researcher credits @cxmcc-instacart for assistance and states that @hitomikt provided no communication and no apology.
Glossary
- API: the set of addresses a website's pages use to fetch and save data, separate from the pages you see.
- Authentication: proving who you are, usually by logging in.
- Authorisation: deciding whether the person asking is allowed to do the thing they are asking for.
- Collaborator: a person a list owner has added to a shopping list, with permission to edit it.
- Cookie: a small piece of text a site stores in your browser and receives back on each request, used to recognise your session.
- CSRF token: a value the site expects on requests that change data, to prove the request came from its own pages.
- Defacement: changing what visitors see on a site so it shows the attacker's content.
- Endpoint: one specific API address that performs one job.
- GET: the request method used to ask for something, such as a page or a record.
- Header: a labelled line of extra information attached to a request or response.
- HTTP status code: a number in the response saying how it went, such as
200for OK,403for forbidden,404for not found. - Id: the number that identifies one particular object, such as a list.
- Insecure direct object reference: a bug where the server acts on an object id from the request without checking the caller's right to that object.
- JSON: a simple structured text format for data, built from names and values in curly braces.
- Metadata: information about an object rather than its contents, such as a list's name.
- Phishing: content planted to trick people into handing over information.
- POST: the request method used to create something.
- Privilege escalation: gaining more power over something than you are entitled to.
- Session: the period during which a site recognises you as logged in, carried by the cookie.
- Share token: a short random-looking string that acts as a key to a shared object, here the list's edit page.
- Stored XSS: a bug where an attacker saves code into a site so it runs in other visitors' browsers later.
- XSS: cross-site scripting, running attacker-supplied code in someone else's browser.