Skip to content
IDOR Write-up Beginner

[Writeup][Bug Bounty][Tokopedia] Manipulate Other User’s Cart and Wishlist on Tokopedia [EN]

The cart and wishlist endpoints trusted user-supplied identifiers (X-User-ID, Tkpd-UserId, user_id) instead of checking the authenticated session, so an attacker could view, add, change, or delete items in another user's cart and add items to their wishlist.

Muhammad Thomas Fadhila Yahya Follow

Published on fadhilthomas.github.io

Bounty$135 View original

Before starting, IDOR is Insecure Direct Object Reference, hereinafter referred to as IDOR, is a condition in which users can access an object without passing the access rights check. (OWASP, 2019)

fadhilthomas, on fadhilthomas.github.io

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

Tokopedia is an e-commerce platform, and the feature under test is the shopping cart and wishlist: the endpoints that list the contents of a cart, add a product to a cart, update the quantity of a product in a cart, remove a product from a cart, and add a product to a wishlist. Normally each of these operations acts only on the cart and wishlist belonging to the authenticated user making the request.

The researcher classifies the bug as an IDOR. In his own definition, IDOR (Insecure Direct Object Reference) is a condition in which users can access an object without passing the access rights check, and with IDOR a user can access, change and delete data. The write-up notes that the bug has been patched by Tokopedia and that screenshots are censored because of PII.

Setup

Two accounts were created:

  • Account A, the attacker, with ID 37822XXX.
  • Account B, the victim, with ID 49468XXX.

The finding is a chain, meaning it involves more than one endpoint, so the write-up is divided into five parts. The attacker works from Account A throughout, and each part ends with a verification step performed by logging in to Account B.

Finding it

The affected endpoints are:

The cart requests carry the user identity in the request body, in the X-User-ID and Tkpd-UserId fields, and the update and remove requests additionally carry a user_id field and a cart_id. Because these identifiers are supplied by the client, changing them to another account's values makes the server act on that account's cart. The cart_id needed for the later steps is obtained from the response of the first request.

Exploitation

Part 1: Viewing products in another user's cart

  1. Log in to the attacker's account.
  2. Open the shopping cart to capture the request shown in Figure 1.

Figure 1. Viewing Shopping Cart Request

  1. In the request body, change X-User-ID and Tkpd-UserId from Account A's ID to Account B's ID, as shown in Figure 2.

Figure 2. Changed Request

  1. Read the response. The request succeeded and returned the product list in the victim's shopping cart, including cart_id and product information such as product_id, product quantity, total price and more, as shown in Figures 3 and 4.

Figure 3. Response From Changed Requests

Figure 4. Response From Changed Requests

  1. Save the cart_id, which is needed later to change and delete the cart and to add wishlist products.

Part 2: Adding products to another user's cart

  1. Log in to the attacker's account.
  2. Add a product to the cart to capture the request shown in Figure 5.

Figure 5. Add Product to Shopping Cart Request

  1. In the request body, change X-User-ID and Tkpd-UserId from Account A's ID to Account B's ID, as shown in Figure 6.

Figure 6. Changed Request

  1. Read the response. The request succeeded and returned values such as cart_id, shop_id and customer_id, as shown in Figure 7.

Figure 7. Response From Requests That Have Been Changed

  1. Verify by logging in to the victim's account and opening the shopping cart. The product has been added to the victim's cart, as shown in Figure 8.

Figure 8. Adding Products Successfully

Part 3: Changing products in another user's cart

  1. Log in to the attacker's account.
  2. Change the number of products in the cart to capture the request shown in Figure 9.

Figure 9. Change Product in Shopping Cart Request

  1. In the request body, change X-User-ID, Tkpd-UserId and user_id from Account A's ID to Account B's ID, replace cart_id with the cart_id obtained in the previous part, and set the desired quantity, as shown in Figure 10.

Figure 10. Changed Request

  1. Read the response. The request succeeded and returned an ok status, as shown in Figure 11.

Figure 11. Response from Changed Requests

  1. The quantity has been changed in the victim's cart, as shown in Figure 12.

Figure 12. Changing Products in the Shopping Cart Successfully

Part 4: Deleting another user's cart

  1. Log in to the attacker's account.
  2. Remove all products from the cart to capture the request shown in Figure 13.

Figure 13. Delete Shopping Cart Request

  1. In the request body, change X-User-ID, Tkpd-UserId and user_id from Account A's ID to Account B's ID, and replace cart_id with the cart_id obtained when adding the product, as shown in Figure 14.

Figure 14. Changed Request

  1. Read the response. The request succeeded and returned an ok status.
  2. All products have been removed from the victim's cart, as shown in Figure 15.

Figure 15. Removing Shopping Cart Successfully

Part 5: Adding products to another user's wishlist

This step continues from the remove request. The remove request carries an add_wishlist parameter set to 0.

  1. Change the add_wishlist parameter from 0 to 1, as shown in Figure 16.

Figure 16. Changed Request

  1. Read the response. The request succeeded and returned an ok status, as shown in Figure 17.

*Figure 17.

  1. Verify by logging in to the victim's account and opening the wishlist. The product has been added to the victim's wishlist, as shown in Figure 18.

Figure 18. Adding Products to Wishlist Successfully

Root cause

The server takes the user identity from client-controlled fields in the request body (X-User-ID, Tkpd-UserId, user_id) and the cart identity from a client-supplied cart_id, and acts on them without checking that they belong to the authenticated session. The write-up does not describe the server-side code, so the exact check that is missing is not stated; the observable behaviour is that changing these values to another account's identifiers is accepted. The remediation section points to the same conclusion: access control needs to be applied, and users need to be authorised for the information requested before the server provides it.

Impact

With these endpoints an attacker can:

  • add a product to another user's wishlist;
  • view the product list in another user's shopping cart;
  • add a product to another user's shopping cart;
  • change the number of products in another user's shopping cart;
  • delete the product list in another user's shopping cart.

Fix

Tokopedia fixed the bug; the write-up does not describe the change that was made. The remediation it recommends is to apply access control and to authorise the user for the information requested before the server provides it.

Variants to test

  • On other cart and wishlist endpoints, replace the user identifier fields in the body (X-User-ID, Tkpd-UserId, user_id) with a second account's ID while keeping the first account's session. A positive result is a response containing the second account's cart contents or an ok status with the change visible when logged in as the second account.
  • Take a cart_id from one account's response and use it in update and remove requests sent from another account. A positive result is the quantity changing or the products being removed in the first account's cart.
  • Look for boolean parameters on remove or delete requests, such as add_wishlist, that trigger a secondary action. A positive result is the item appearing in the other account's wishlist.
  • Repeat the same identifier substitution on other object types that expose an ID in the body or query (orders, addresses, saved payment methods), checking whether the response reflects the other account's data.

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

What happened, in plain words

Tokopedia is a large online shopping site, similar in spirit to any marketplace where you browse products, put them in a basket and pay for them later. Two of its features matter here: the shopping cart (the basket that holds the products you intend to buy) and the wishlist (a list of products you want to remember for later, without buying them yet).

When you use a website like this, your browser does not draw the basket itself. It asks the website's server, over the internet, for the contents of your basket, and the server replies with a list of products. Each of these little request-and-reply conversations is what people call an API (Application Programming Interface). A useful everyday comparison: an API is like a restaurant waiter. You (the browser) tell the waiter what you want, the waiter goes to the kitchen (the server) and brings back a plate (the response). You never walk into the kitchen yourself.

The problem the researcher found is that the waiter did not check whose order he was taking. When the browser asked for a basket, it also sent along a note saying which user the basket belonged to. Normally the server should ignore that note and instead work out who you are from your login session (the proof that you signed in). Here, the server trusted the note. So by editing the note to contain someone else's user number, the researcher could make the server hand over, change or empty that other person's basket.

This kind of bug has a name: IDOR, short for Insecure Direct Object Reference. In the researcher's own words, IDOR is a condition in which users can access an object without passing the access rights check, and with IDOR a user can access, change and delete data. A simple comparison: imagine a hotel where every room key is identical, and the door only opens if you say your room number out loud. Anyone who knows another guest's room number can walk in. The door (the server) is doing its job, but it is trusting a number the guest supplies instead of checking the key (the login session).

The researcher notes that the bug has been patched by Tokopedia, and that screenshots are censored because of PII (personally identifiable information, meaning data that could identify a real person).

Setting up the test

To prove the bug, the researcher needed two separate accounts, so he could play both the attacker and the victim:

  • Account A, the attacker, with ID 37822XXX.
  • Account B, the victim, with ID 49468XXX.

An account ID is simply the number the website uses internally to tell one user apart from another. It is not your username or email; it is a label the system attaches to you.

The researcher calls this finding a chain, meaning it involves more than one endpoint. An endpoint is one specific address on the server that does one specific job, like one particular counter in a large office. The cart feature has several counters: one to list the cart, one to add a product, one to change a quantity, one to remove a product. Because the attack moves through several of them, the write-up is split into five parts. The attacker always works from Account A, and each part ends with a check performed by logging in to Account B, to confirm the change really landed in the victim's account.

The endpoints involved

The affected endpoints are:

Line by line, in plain words:

  • https:// is the secure version of the protocol browsers use to talk to websites. The s means the conversation is encrypted, so nobody sitting between you and the server can read it.
  • [redacted] stands for the site's host name, which has been hidden here.
  • /cart/v2/ is the path: it tells the server you are talking to the cart feature, version 2.
  • shop_group is one of the cart endpoints listed in the report.
  • add_product_cart is the endpoint that puts a product into a cart.
  • update_cart is the endpoint that changes something in a cart, such as the quantity of a product.
  • remove_product_cart is the endpoint that takes a product out of a cart.

Each of these is a separate door into the same room. The bug is that none of the doors checked whether the person knocking owned the room.

How the identity is carried

The cart requests carry the user identity in the request body, in the X-User-ID and Tkpd-UserId fields, and the update and remove requests additionally carry a user_id field and a cart_id.

A few terms unpacked:

  • The request body is the part of the message that carries the actual data being sent, as opposed to the address line. If the request is a letter, the body is the contents of the envelope.
  • A field is one named piece of data inside that body, like one line on a form: a name and a value.
  • X-User-ID, Tkpd-UserId and user_id are three different names the site uses for the same idea: which user this request is about.
  • A cart_id is the internal number of one particular cart. Every user's cart has its own number, just as every hotel room has its own number.

Because these identifiers are supplied by the client (your browser), changing them to another account's values makes the server act on that account's cart. The cart_id needed for the later steps is obtained from the response of the first request. In other words, the attacker first asks for the victim's cart, reads the cart's number out of the reply, and then uses that number in the following steps.

Part 1: Viewing products in another user's cart

  1. Log in to the attacker's account. Logging in gives the browser a session, which is the server's way of remembering that this browser has already proved who it is. The proof usually travels as a cookie or a token, a small piece of data the browser stores and sends back with every request. Think of it as a wristband you get at the entrance to an event: you show it at every door instead of showing your ID again.
  2. Open the shopping cart to capture the request shown in Figure 1.

Figure 1. Viewing Shopping Cart Request

"Capture the request" means watching the conversation between the browser and the server. Browsers have a built-in developer tools panel (usually opened with F12) with a Network tab that lists every request and reply. This is how you see what the browser actually sends, which is normally invisible.

  1. In the request body, change X-User-ID and Tkpd-UserId from Account A's ID to Account B's ID, as shown in Figure 2.

Figure 2. Changed Request

Why this step: the browser was honestly saying "this is user A's cart". By editing that note to say "this is user B's cart" while still holding user A's session wristband, the researcher tests whether the server believes the note or the wristband. If it believes the note, the door is open.

  1. Read the response. The request succeeded and returned the product list in the victim's shopping cart, including cart_id and product information such as product_id, product quantity, total price and more, as shown in Figures 3 and 4.

Figure 3. Response From Changed Requests

Figure 4. Response From Changed Requests

The response is the server's reply. Here it contained the victim's cart contents: cart_id (the cart's number), product_id (the number of each product), the quantity of each product, the total price, and more. The fact that the reply came back at all, with real data, is the proof: the server did not stop to ask whether user A was allowed to see user B's cart.

  1. Save the cart_id, which is needed later to change and delete the cart and to add wishlist products.

Why save it: the later endpoints do not take a user ID alone; they need to know which cart to act on. The cart number is the handle on the victim's basket, and it was just handed over in the reply.

Part 2: Adding products to another user's cart

  1. Log in to the attacker's account.
  2. Add a product to the cart to capture the request shown in Figure 5.

Figure 5. Add Product to Shopping Cart Request

Adding a product to your own cart first is a way of getting a genuine, working example of the request. It is much easier to take a real request and edit two values than to build one from scratch.

  1. In the request body, change X-User-ID and Tkpd-UserId from Account A's ID to Account B's ID, as shown in Figure 6.

Figure 6. Changed Request

Why this step: same idea as Part 1, but now the goal is not to read but to write. The researcher is testing whether the server will accept a change to a cart that does not belong to the logged-in session.

  1. Read the response. The request succeeded and returned values such as cart_id, shop_id and customer_id, as shown in Figure 7.

Figure 7. Response From Requests That Have Been Changed

The reply contained values such as shop_id and customer_id. A successful reply containing these values shows the server treated the request as legitimate.

  1. Verify by logging in to the victim's account and opening the shopping cart. The product has been added to the victim's cart, as shown in Figure 8.

Figure 8. Adding Products Successfully

Why verify: a reply that says "ok" is only the server's claim. Logging in as the victim and seeing the product with your own eyes is the proof that the change really happened in the victim's account, not just in the attacker's copy of the page.

Part 3: Changing products in another user's cart

  1. Log in to the attacker's account.
  2. Change the number of products in the cart to capture the request shown in Figure 9.

Figure 9. Change Product in Shopping Cart Request

Again, the researcher performs the action on his own cart first, to obtain a real request to edit.

  1. In the request body, change X-User-ID, Tkpd-UserId and user_id from Account A's ID to Account B's ID, replace cart_id with the cart_id obtained in the previous part, and set the desired quantity, as shown in Figure 10.

Figure 10. Changed Request

Why three fields and not two: this endpoint carries the user identity in three places, so all three have to be pointed at the victim. The cart_id from Part 2 is used because that is the cart the attacker already knows the number of. The quantity is set to whatever value the attacker wants the victim's cart to show.

  1. Read the response. The request succeeded and returned an ok status, as shown in Figure 11.

Figure 11. Response from Changed Requests

An ok status is a short confirmation, the server's way of saying "done".

  1. The quantity has been changed in the victim's cart, as shown in Figure 12.

Figure 12. Changing Products in the Shopping Cart Successfully

Part 4: Deleting another user's cart

  1. Log in to the attacker's account.
  2. Remove all products from the cart to capture the request shown in Figure 13.

Figure 13. Delete Shopping Cart Request

  1. In the request body, change X-User-ID, Tkpd-UserId and user_id from Account A's ID to Account B's ID, and replace cart_id with the cart_id obtained when adding the product, as shown in Figure 14.

Figure 14. Changed Request

Why this step: this is the most damaging action so far. Reading someone's cart is bad; emptying it is worse, because the victim loses the products they had chosen. The same substitution is used, which shows that one weakness runs through several endpoints rather than being a one-off mistake.

  1. Read the response. The request succeeded and returned an ok status.
  2. All products have been removed from the victim's cart, as shown in Figure 15.

Figure 15. Removing Shopping Cart Successfully

Part 5: Adding products to another user's wishlist

This step continues from the remove request. The remove request carries an add_wishlist parameter set to 0.

A parameter is a named value sent with a request, like a checkbox on a form. Here add_wishlist is a switch: 0 means off, 1 means on. The parameter is named add_wishlist and was set to 0 in the remove request.

  1. Change the add_wishlist parameter from 0 to 1, as shown in Figure 16.

Figure 16. Changed Request

Why this step: the researcher noticed that the remove request had a hidden extra action attached to it. By flipping the switch, he tests whether that extra action also ignores whose account it is acting on. This is a good habit in security testing: look for small optional fields that trigger a second effect.

  1. Read the response. The request succeeded and returned an ok status, as shown in Figure 17.

*Figure 17.

  1. Verify by logging in to the victim's account and opening the wishlist. The product has been added to the victim's wishlist, as shown in Figure 18.

Figure 18. Adding Products to Wishlist Successfully

Why the bug exists

The server takes the user identity from client-controlled fields in the request body (X-User-ID, Tkpd-UserId, user_id) and the cart identity from a client-supplied cart_id, and acts on them without checking that they belong to the authenticated session. The write-up does not describe the server-side code, so the exact check that is missing is not stated; the observable behaviour is that changing these values to another account's identifiers is accepted.

In everyday terms: the server should look at your wristband (the session) and decide what you are allowed to touch. Instead it reads the name tag you wrote yourself (the ID fields in the body) and trusts it. The remediation section points to the same conclusion: access control needs to be applied, and users need to be authorised for the information requested before the server provides it.

Access control is the general name for the rules that decide who may do what. Authorisation is the act of checking those rules for a specific request: not just "are you logged in?" but "are you allowed to see this cart?".

What an attacker could do

With these endpoints an attacker can:

  • add a product to another user's wishlist;
  • view the product list in another user's shopping cart;
  • add a product to another user's shopping cart;
  • change the number of products in another user's shopping cart;
  • delete the product list in another user's shopping cart.

How it was fixed

Tokopedia fixed the bug; the write-up does not describe the change that was made. The remediation it recommends is to apply access control and to authorise the user for the information requested before the server provides it.

Other places to look for the same mistake

Once you know the shape of a bug, you can look for it elsewhere. Other places to look for the same mistake:

  • On other cart and wishlist endpoints, replace the user identifier fields in the body (X-User-ID, Tkpd-UserId, user_id) with a second account's ID while keeping the first account's session. A positive result is a response containing the second account's cart contents or an ok status with the change visible when logged in as the second account.
  • Take a cart_id from one account's response and use it in update and remove requests sent from another account. A positive result is the quantity changing or the products being removed in the first account's cart.
  • Look for boolean parameters on remove or delete requests, such as add_wishlist, that trigger a secondary action. A positive result is the item appearing in the other account's wishlist.
  • Repeat the same identifier substitution on other object types that expose an ID in the body or query (orders, addresses, saved payment methods), checking whether the response reflects the other account's data.

A boolean parameter is one that only takes two values, like a light switch: on or off, 1 or 0, true or false.

Timeline

  • 17 Apr 2019: reported to Tokopedia.
  • 17 Apr 2019: Tokopedia received the report.
  • 18 Apr 2019: Tokopedia declared it valid with Severity Medium.
  • 29 Aug 2019: the bug was fixed.
  • 20 Nov 2019: Tokopedia sent 1.9 million IDR, or $135, as a reward.

A bug bounty is a programme in which a company pays people who report security problems to it, instead of punishing them, so that the problems get fixed before criminals find them.

Glossary

  • API: the set of addresses and rules a website exposes so that a browser (or another program) can ask it to do things and get data back; think of a waiter taking your order to the kitchen.
  • Access control: the rules that decide who is allowed to do what on a system.
  • Account ID: the internal number a site uses to tell one user apart from another.
  • Authorisation: checking, for a specific request, whether the logged-in user is allowed to perform it.
  • Boolean parameter: a parameter that can only be on or off, such as 1 or 0.
  • Bug bounty: a programme that pays people for reporting security bugs responsibly.
  • Cart ID (cart_id): the internal number of one particular shopping cart.
  • Chain: a finding that involves more than one endpoint, where each step builds on the previous one.
  • Cookie / token: a small piece of data the browser stores after you log in and sends back with each request, so the server can recognise your session.
  • Endpoint: one specific address on a server that performs one specific job.
  • Field: one named piece of data inside a request body, like one line on a form.
  • IDOR (Insecure Direct Object Reference): a bug where a user can access, change or delete an object without the server checking that they have the right to it.
  • Parameter: a named value sent with a request, like a checkbox on a form.
  • PII (personally identifiable information): data that could identify a real person, which is why screenshots in the write-up were censored.
  • Request body: the part of a request that carries the actual data being sent.
  • Response: the server's reply to a request.
  • Session: the server's record that your browser has already proved who it is, usually kept alive by a cookie or token.
  • Severity Medium: the rating the company gave the bug, on a scale from low to critical.
  • Shopping cart: the basket of products a user intends to buy.
  • Wishlist: a list of products a user wants to remember for later without buying them yet.

More by Muhammad Thomas Fadhila Yahya

View all

2 more disclosed reports, best first.

More from Tokopedia

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Insecure direct object reference (IDOR)

The lesson behind this report.

One user can read or change another user's data, usually by changing an identifier the server trusts without checking who is asking. One of the most paid bug classes on web programs.