Skip to content
Access control Write-up Beginner

[BAC/IDOR] How my father credit card help me to find this access control issue

The swap default payment method endpoint only checked the API token but not that the token belonged to the user in the URL, so any authenticated user could change another user's default payment method if they knew the user and card IDs. The attacker could swap the default payment options of other users who had added two payment methods.

Xcoder Follow

Published on xcoder074.medium.com

Bounty$350 View original

Hi Everyone, This is xcoder(Joy ahmed) from Bangladesh. Recently I have completed my undergradute.

Xcoder(Joy ahmed), on xcoder074.medium.com

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

Context

This is a write-up of a broken access control (BAC) / IDOR issue found on a private HackerOne program. The program name cannot be disclosed, so the researcher refers to the target as example.com. The main website had limited functionality, but it did include a payments area where a user can add bank account or credit card payment methods and manage them.

The feature that mattered here is the default payment method swap: once a user has added two payment methods, the site lets them choose which one is the default, swapping between the two. The swap is performed through an API endpoint that identifies both the user and the payment method by numeric IDs.

Setup

  • Two user accounts on example.com.
  • User1 adds two payment methods, so that a swap between them is possible.
  • User2's x-api-token is copied and saved for later use.
  • Burp Suite, with Intruder used against the swap request.

The researcher notes that the site validated only the token for actions, so removing cookies did not matter: the x-api-token header was the credential that counted.

Finding it

The researcher started on the main website as a normal user, with two accounts, to understand the workflow, and tried IDOR, XSS and other business logic issues on some endpoints without success; the site was properly secured in those places.

Attention turned to the bank account / credit card adding options. The researcher did not own a credit card, so a father's card was used to add a payment method. The card was added successfully, and the card ID turned out to be a sequential number. The delete endpoint was then examined for IDOR/BAC or disclosure of card information, but nothing was found there.

The same card was added a second time, and it was accepted again, leaving two cards on the account. That unlocked the swap option: with two payment methods present, the default payment method can be swapped between them. Since the swap request carries both a user ID and a card ID, and the site only checks the token, the researcher tried swapping the card of the first user account using the second account's x-api-token, and the swap succeeded.

Exploitation

Step 1: Create two accounts

Two user accounts are created on example.com.

Step 2: Add two payment methods as user1

Logged in as user1, two payment methods are added. Adding the same card twice works, which is what makes the swap possible in the first place.

Step 3: Take user2's token

Logged in as user2, the x-api-token of that account is copied and saved for later use.

Step 4: Capture the swap request

The request that swaps the default payment method looks like this:

HTTP
PUT /api/v1/users/205246/default_payment_method/52684 HTTP/2Host: www.example.comUser-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:96.0) Gecko/20100101 Firefox/96.0Accept: application/jsonAccept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateReferer: https://www.example.com/account/user/paymentsX-Api-Token: [redacted]-Type: application/jsonOrigin: https://www.example.comSec-Fetch-Dest: emptySec-Fetch-Mode: corsSec-Fetch-Site: same-originContent-Length: 0Te: trailers

The request is a PUT to /api/v1/users/{userId}/default_payment_method/{cardId}. The user ID 205246 and the card ID 52684 are both in the path, and the only credential is the X-Api-Token header. The body is empty (Content-Length: 0), so the whole action is driven by the two path parameters.

Step 5: Swap another user's default payment method

With the request in Burp Suite Intruder, user2's x-api-token is placed in the request and the card ID (52684) and user ID (205246) are brute-forced. There is no rate limit on this endpoint, so the IDs can be enumerated. The result is that the default payment options of another user who has added two payment options are successfully swapped.

From the original on xcoder074.medium.com

The screenshot accompanies the end of the reproduction steps.

Root cause

The swap endpoint validates only the x-api-token, and the user ID and card ID are taken from the path, so the researcher could swap another account's card using user2's token. Both identifiers are taken from the URL, and the researcher's swap of another account's card succeeded. The card ID was sequential, and there was no rate limit on the endpoint, so the card ID and user ID could be brute-forced.

The site's other defences did not help: the researcher notes that the site validated only the token for any type of actions, so dropping cookies made no difference to whether the request was accepted.

Impact

An attacker with any valid account can swap the default payment method of another user, provided that user has added two payment methods to their account. The severity was set to low because the impact is minimal, and after retesting the researcher was rewarded a total of 350 USD for the access control issue. The report was submitted on June 23, 2022, and triaged and rewarded on July 5th, 2022.

Fix

The report does not describe a fix.

Variants to test

  1. Path-based object references on state-changing endpoints. Look for PUT, PATCH or DELETE requests where a user ID or object ID sits in the path. Replace it with another account's ID while keeping your own token. A positive result is a successful response and a visible change on the victim account.
  2. Token-only authentication. Send the request without cookies, using only the API token header. If it still succeeds, check whether the token is the only thing being validated, then try another user's token against your own IDs and vice versa.
  3. Sequential identifiers. Add two objects of the same kind and compare their IDs. If they are sequential, try neighbouring IDs with your own token. A positive result is a response that returns or modifies another user's object.
  4. Missing rate limiting on enumeration. Send the same request with an incrementing ID many times and watch for throttling. If responses keep coming, the endpoint can be brute-forced.
  5. Duplicate resource creation. Add the same payment method twice, as the researcher did. If duplicates are accepted, check whether the resulting state (such as a swap between two methods) opens actions that were not reachable with a single method.

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

What happened, in plain words

A security researcher found a way to change another person's default payment method on a website. The website let people save bank accounts or credit cards and choose which one is used by default. The researcher found that the swap request validated only the x-api-token, and using user2's token he swapped the card of the first account. The researcher swapped the default payment method of another account that had added two payment methods.

The bug was found on a private HackerOne program. HackerOne is a platform where companies invite researchers to test their systems and pay for the problems they report. The program's name cannot be disclosed, so the researcher calls the target example.com. The report was submitted on June 23, 2022, and triaged and rewarded on July 5th, 2022. The severity was set to low because the impact was minimal, and the researcher was rewarded a total of 350 USD.

Before going further, a few words on the two ideas at the heart of this bug.

Broken access control (BAC) means a user can do something they are not supposed to be allowed to do. The researcher's own comparison: in a group, the owner can invite new members but a basic member cannot. If a basic member finds a way to invite people anyway, that is an access control problem.

IDOR stands for Insecure Direct Object Reference. It means the website uses a simple identifier, such as a number, to point at something (a user, a card, an order), and does not check that the person asking is allowed to touch that particular thing. If you can change the number in a request and reach someone else's data, that is an IDOR. It is a common kind of broken access control.

The feature that mattered

The main website did not have much functionality, but it did have a payments area. There, a user can add bank account or credit card payment methods and manage them. Once a user has added two payment methods, the site lets them choose which one is the default, swapping between the two. That swap is done through an API endpoint.

An API is the part of a website that the page talks to behind the scenes. When you click a button, your browser sends a small request to the API, and the API does the work and sends back an answer. An endpoint is one specific address in that API, for example the one that handles the swap. The swap endpoint identifies both the user and the payment method by numeric IDs, which are numbers placed directly in the address.

A token is a long string of characters that acts like a temporary key. After you log in, the site gives your browser a token, and your browser sends it with every request so the site knows who you are. A cookie is a small piece of data the browser stores for a site and sends automatically; it is one common way to carry a login. Here, the site used a custom header called x-api-token instead, and the researcher found that this token was the only thing the site checked.

Setting up

To test safely, the researcher needed:

  • Two user accounts on example.com.
  • User1 with two payment methods added, so that a swap between them is possible.
  • User2's x-api-token, copied and saved for later use.
  • Burp Suite, a tool that lets you watch and edit the requests your browser sends. Its Intruder feature sends the same request many times with a changing value, which is how the researcher tried many IDs quickly.

A key observation: the site validated only the token for actions, so removing cookies did not matter. The x-api-token header was the credential that counted.

Finding it

The researcher started on the main website as a normal user, with two accounts, to understand the workflow. They tried IDOR, XSS and other business logic issues on some endpoints without success; the site was properly secured in those places. XSS (cross-site scripting) is a different bug where an attacker gets their own code to run in another user's browser. Business logic issues are flaws in the rules of a feature rather than in its code, such as allowing a step that should be impossible.

Attention turned to the bank account / credit card adding options. The researcher did not own a credit card, so a father's card was used to add a payment method. The card was added successfully, and the card ID turned out to be a sequential number, meaning each new card gets the next number in line (1, 2, 3 and so on). Sequential IDs are a gift to an attacker, because guessing the next one is trivial.

The delete endpoint was then examined for IDOR/BAC or disclosure of card information, but nothing was found there. A delete endpoint is the API address that removes a saved item.

The same card was added a second time, and it was accepted again, leaving two cards on the account. That unlocked the swap option: with two payment methods present, the default payment method can be swapped between them. Since the swap request carries both a user ID and a card ID, and the site only checks the token, the researcher tried swapping the card of the first user account using the second account's x-api-token, and the swap succeeded.

Exploitation, step by step

Step 1: Create two accounts

Two user accounts are created on example.com. Two accounts are needed so that one can play the attacker and the other the victim, without touching a real person's data.

Step 2: Add two payment methods as user1

Logged in as user1, two payment methods are added. Adding the same card twice works, which is what makes the swap possible in the first place: the swap only exists when there are two methods to swap between.

Step 3: Take user2's token

Logged in as user2, the x-api-token of that account is copied and saved for later use. This is the attacker's key. It is a valid key for user2, but the question is whether the site also checks that the target belongs to user2.

Step 4: Capture the swap request

The request that swaps the default payment method looks like this:

HTTP
PUT /api/v1/users/205246/default_payment_method/52684 HTTP/2Host: www.example.comUser-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:96.0) Gecko/20100101 Firefox/96.0Accept: application/jsonAccept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateReferer: https://www.example.com/account/user/paymentsX-Api-Token: [redacted]-Type: application/jsonOrigin: https://www.example.comSec-Fetch-Dest: emptySec-Fetch-Mode: corsSec-Fetch-Site: same-originContent-Length: 0Te: trailers

Line by line, in plain words:

  • PUT /api/v1/users/205246/default_payment_method/52684 HTTP/2 is the first line. PUT is the method, the verb that tells the server what kind of action this is; here it means "change this thing". The path that follows is the address of the endpoint. Inside it, 205246 is the user ID and 52684 is the card ID. HTTP/2 is the version of the language the browser and server use to talk.
  • Host: www.example.com says which website the request is for. One server can host many sites, so it needs to know which one you mean.
  • User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:96.0) Gecko/20100101 Firefox/96.0 tells the server which browser and operating system sent the request. It is normal background information.
  • Accept: application/json says the browser would like the answer in JSON, a common text format for data.
  • Accept-Language: en-US,en;q=0.5 says the preferred language is English (US).
  • Accept-Encoding: gzip, deflate says the browser can accept compressed answers, to save bandwidth.
  • Referer: https://www.example.com/account/user/payments says which page the request came from, here the payments page of the account.
  • X-Api-Token: [redacted] is the credential. This is the token that identifies the account making the request. In the real attack this value was replaced with user2's token.
  • Content-Type: application/json says the body of the request, if any, is in JSON format.
  • Origin: https://www.example.com says which site the request originates from. Browsers add this for security checks.
  • Sec-Fetch-Dest: empty, Sec-Fetch-Mode: cors, Sec-Fetch-Site: same-origin are modern browser hints about the context of the request. same-origin means it comes from the same site.
  • Content-Length: 0 says the body is empty. There is no data being sent; the whole action is driven by the two numbers in the path.
  • Te: trailers is a minor header about how the connection is handled.

The important part is the path: /api/v1/users/{userId}/default_payment_method/{cardId}. The user ID 205246 and the card ID 52684 are both in the path, and the only credential is the X-Api-Token header. The body is empty, so the whole action is driven by the two path parameters.

Step 5: Swap another user's default payment method

With the request in Burp Suite Intruder, user2's x-api-token is placed in the request and the card ID (52684) and user ID (205246) are brute-forced. Brute-forcing here means trying many numbers in a row, one after another, to see which ones the server accepts. There is no rate limit on this endpoint, so the IDs can be enumerated. A rate limit is a cap on how many requests one person can send in a period of time; without one, a script can try thousands of numbers and nothing slows it down. Enumerating means walking through the possible values systematically.

The result is that the default payment options of another user who has added two payment options are successfully swapped.

From the original on xcoder074.medium.com

The screenshot accompanies the end of the reproduction steps.

Why it worked

The swap endpoint validates only the x-api-token, and the user ID and card ID are taken from the path, so the researcher could swap another account's card using user2's token. Both identifiers are taken from the URL, and the researcher's swap of another account's card succeeded. The card ID was sequential, and there was no rate limit on the endpoint, so the card ID and user ID could be brute-forced.

The site's other defences did not help: the researcher notes that the site validated only the token for any type of actions, so dropping cookies made no difference to whether the request was accepted.

Impact

An attacker with any valid account can swap the default payment method of another user, provided that user has added two payment methods to their account. The severity was set to low because the impact is minimal, and after retesting the researcher was rewarded a total of 350 USD for the access control issue.

Fix

The report does not describe a fix.

Variants to test

If you want to look for similar problems yourself, here are the patterns to try. Always test only on systems where you have permission.

  1. Path-based object references on state-changing endpoints. Look for PUT, PATCH or DELETE requests where a user ID or object ID sits in the path. Replace it with another account's ID while keeping your own token. A positive result is a successful response and a visible change on the victim account.
  2. Token-only authentication. Send the request without cookies, using only the API token header. If it still succeeds, check whether the token is the only thing being validated, then try another user's token against your own IDs and vice versa.
  3. Sequential identifiers. Add two objects of the same kind and compare their IDs. If they are sequential, try neighbouring IDs with your own token. A positive result is a response that returns or modifies another user's object.
  4. Missing rate limiting on enumeration. Send the same request with an incrementing ID many times and watch for throttling. If responses keep coming, the endpoint can be brute-forced.
  5. Duplicate resource creation. Add the same payment method twice, as the researcher did. If duplicates are accepted, check whether the resulting state (such as a swap between two methods) opens actions that were not reachable with a single method.

Glossary

  • API: the part of a website that the page talks to behind the scenes to fetch or change data.
  • Endpoint: one specific address in an API that performs one kind of action.
  • Token: a long string of characters that acts like a temporary key, proving who you are on each request.
  • Cookie: a small piece of data a browser stores for a site and sends automatically with requests.
  • Header: an extra line of information attached to a request or response, such as the token or the browser type.
  • Broken access control (BAC): a flaw where a user can do something they are not permitted to do.
  • IDOR (Insecure Direct Object Reference): a flaw where a simple identifier in a request points at someone else's data and the site does not check permission.
  • XSS (cross-site scripting): a flaw where an attacker gets their own code to run in another user's browser.
  • Business logic issue: a flaw in the rules of a feature rather than in its code.
  • Brute-forcing: trying many values in a row, often numbers, until one works.
  • Enumeration: walking through possible values systematically to find valid ones.
  • Rate limit: a cap on how many requests one person can send in a period of time.
  • Sequential ID: an identifier that increases by one each time, making it easy to guess.
  • PUT: an HTTP method meaning "change or replace this thing".
  • JSON: a common text format for data, used by APIs.
  • Burp Suite: a tool that lets you watch, edit and repeat the requests your browser sends.
  • Intruder: the Burp Suite feature that sends the same request many times with a changing value.
  • Severity: a rating of how serious a bug is, often low, medium, high or critical.
  • Triaged: reviewed and confirmed as a valid issue by the program.
  • Retesting: checking the bug again after the company has made changes, to confirm the fix works.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.