Skip to content
IDOR Write-up Intermediate

The Million Dollar IDOR

The GraphQL API allowed any authenticated user to fetch another user's gift card details by changing an incremental ID parameter, exposing card numbers, CVVs, and expiry dates. A race condition in the redemption process also allowed the same gift card to be redeemed multiple times, crediting the attacker's bank account repeatedly.

Monish Basaniwal Follow

Published on monish-basaniwal.medium.com

Read on to find out how I was able to leverage a simple IDOR + Authorization vulnerability to expose thousands of Visa gift cards on a leading gift card company’s website + Bonus: Found a way to redeem them more than once.

Monish, on monish-basaniwal.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. 7 min read.

Context

A leading gift card company's website let users hold and redeem gift cards. After logging in, a user could see the cards issued to them, including Visa card numbers, CVVs and expiry dates, and could cash out cards issued in another currency into a currency of their choice. In this case the platform offered direct conversion between USD and INR, paid out instantly to a UPI id.

The site exposed a GraphQL-based API, where requests are "queries" asking for exactly the amount of data needed. The researcher found the site randomly and set out to understand the technology and the data passed in the background.

From the original on monish-basaniwal.medium.com

Setup

The report describes no special accounts, roles, tools or versions. The researcher browsed the site as a normal logged-in user, observed the GraphQL traffic, and later intercepted the redemption request. The only precondition for the first issue was a valid session on the platform; the second required the ability to initiate a redemption of a card into a local currency.

Finding it

In a GraphQL API the endpoint for all API communication usually stays the same, typically /graphql, and the queries and methods in the body define the operation, backed by a Schema. The researcher notes that there are a few ways to fetch all available queries and mutations, and to return the entire schema, popularly known as the Retrospection Query. These are sensitive and are usually disabled on serious production GraphQL servers and by default on the Apollo GraphQL server, but very often they are still available.

Fetch all available queries:

Text
{  __schema {    queryType {      fields {        name      }    }  }}

Fetch all available mutations:

Text
{  __schema {    mutationType {      fields {        name      }    }  }}

The platform used very simple queries to retrieve and show all the gift cards owned by a user. Right after login a query for getUserStipends was made, which fetched all the cards belonging to a specific user, listing the Visa card number, the CVV and the expiry for each card. Each card had an id that was guessable and incremental, like 45, 46, 47.

Text
query getUserStipends {  myStipends {    id    status    stipend {      amount      canAccrue      colorHex      colorHex2      currency      currentIntervalStart      emoji      endDate      id      interval      logoUrl      name      nextIntervalStart      recurrenceStart      startDate      createdAt    }  }}

After clicking on a specific card there was yet another request, this time for getUserStipend with the id of the card that had been clicked:

Text
query getUserStipend($id: Int!) {  stipendUser(id: $id) {    activeUserAddressId    id    personalCardEnabled    status    isTestCard    redemptionType    endDate    endDateExtension    stipend {      amount      canAccrue      colorHex      colorHex2      company {        id        allowParticipantBillingAddress        allowParticipantPersonalCC      }      currency      currentIntervalStart      emoji      endDate      id      interval      logoUrl      name      nextIntervalStart      recurrenceStart      startDate      createdAt      address {        city        country        id        line1        line2        phone_number        postal_code        state      }      merchantCategory {        categoryId        categoryName        merchantId        merchantName        url        logoUrl        networkId      }    }    userAddresses {      city      country      id      line1      line2      phone_number      postal_code      state    }    card {      stripeCardId      currentBalance      accruedBalance      number      cvc      expiry      status      donated      categories {        displayTitle        title      }      cardholder {        name        address {          city          country          line1          line2          postal_code          state        }      }    }    reimbursement {      history {        status        occurredAt      }      amount      targetCurrency      totalFee      wiseQuoteId      wiseRecipientId      wiseTransferId    }  }}{    "id": 100000}

This query returned more in-depth data about the specific card: the amount available, the currency and so on. The first thing that came to mind was to change the id parameter to something else, since it was very easily guessable.

Exploitation

Step 1: change the id in getUserStipend

Changing the id parameter caused the query to execute successfully and returned the entire card details of some other user. Trying the same request with another id returned a new Visa gift card that did not belong to the researcher, every time. The response returned the entire card details of another user, as defined by the query above.

With this, the researcher had access to thousands of valid Visa gift cards with varying values, and unhinged access to all of them, from a simple IDOR that exposed extremely confidential details valued in millions.

Step 2: report the IDOR

The researcher took to the platform's helpline and reported the vulnerability. Within hours it was fixed and acknowledged by the company's co-founder.

From the original on monish-basaniwal.medium.com

Step 3: look at the redemption flow

The platform offered another feature: if you had been issued a gift card in some other currency, you could get it cashed out in the currency of your choice. Here they offered direct conversions between USD and INR, where the money would be paid directly to a UPI id instantly.

When a redemption process was initiated, the platform generated a quotationID with the converted amount of the card in the requested currency, and then asked for more details such as the UPI id to be paid. Once redeem was clicked, a request was sent using the quotationID to mark it paid, after which the card would no longer be useful.

Step 4: race the redemption request

The researcher intercepted the redemption request, duplicated it a couple of times and sent them all at once. The converted amount was credited multiple times to the bank account.

The researcher's analogy: a group of slingshots tied to a single lever; when the lever is pulled all the requests are sent simultaneously to the server, and before the server can mark the quotation id as "used" the server has placed multiple redemption requests, which in turn send multiple reimbursements to the user.

From the original on monish-basaniwal.medium.com

So the researcher now had not only unlimited Visa gift cards but also a way to redeem them into a local currency multiple times per card.

Root cause

The stipendUser query accepts an id from the client and returned the card for that id, including cards belonging to other users. The report does not describe the server-side code, so the exact cause is not shown. Because ids are incremental integers rather than unguessable values such as UUIDs, enumerating them is trivial. The report does not describe the server-side code, so the exact check that was missing is not shown.

The race condition arises because several requests can reach the server before it marks the quotation id as used, so each one triggers a redemption. The report frames the fix in terms of doing the status change and the payout in one query, and of database ACID properties, where most scalable databases place a temporary lock on the part of the data being accessed through one request so that until one operation is completely done that part of the data is not accessible by other queries. Whether the platform already had such locking in place is not stated.

Impact

On the IDOR, an authenticated user could read the full details of other users' gift cards, including the Visa card number, CVC and expiry, the cardholder name and address, and reimbursement information, by changing a guessable id. The researcher describes access to thousands of valid Visa gift cards with varying values, with confidential details valued in millions.

On the race condition, a user who initiates a redemption could have the converted amount credited multiple times to their bank account for a single card.

The report led to another bounty plus a security contract with the company.

Fix

For the race condition, the report gives two recommendations:

  1. Queries leading to actions: on modules where critical systems are involved, do not talk to the database on a multi-query basis. Instead of asking about the gift card in one query and then issuing a second query to change its status, perform both in one query: 'If not paid set to paid and payout'.
  2. DB ACID properties: depending on the database, use the temporary lock that most scalable databases place on the part of the data being accessed through one request, so that until one operation is completely done that part of the data is not accessible by other queries.

Variants to test

  1. Incremental ids in GraphQL queries. Take any query that takes an object id and substitute neighbouring values. A positive result is a successful response containing another user's object, as happened here with stipendUser(id: $id).
  2. Retrospection queries. Send the two schema queries above to /graphql. A positive result is a response listing query or mutation field names, which maps the attack surface even when the server is not meant to expose it.
  3. Single-use assets under concurrency. Intercept the request that consumes a quotation, voucher or coupon and replay it several times in parallel. A positive result is more than one credit, redemption or payout for one asset.
  4. Check-then-act flows generally. Look for any flow where a status is read and then changed in a separate request, such as marking something paid or used. A positive result is the action succeeding more than once before the status change takes effect.

Closing notes

  1. Do not hesitate to change id parameters to various values, especially if they are not unique like a UUID and are incremental, as in this case.
  2. Always check for race conditions; any action which may lead to a critical action must be double-checked to be race-condition safe. These are more common in single-use assets like vouchers and coupons.

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

What happened, in plain words

A researcher found a website run by a gift card company. Gift cards are small prepaid cards, like a voucher you can spend online. This company let people receive gift cards, look at them on the website, and cash them out into real money in a currency of their choice.

The researcher found one problem, and later a second one:

  1. By changing a single number in a request that the website sends in the background, they could see the full details of other people's gift cards, including the card number, the security code on the back and the expiry date. The card ids were guessable and incremental, like 45, 46, 47, so guessing them was easy.
  2. When cashing a card out, they could send the same request several times at once and get paid more than once for the same card.

They reported the first problem through the company's helpline and it was fixed within hours. The report led to another bounty plus a security contract with the company.

From the original on monish-basaniwal.medium.com

Some background before we start

Before walking through the steps, here are a few ideas that come up again and again. If you have never done any security work, read this section first; everything later depends on it.

What is an API? A website is what you see in the browser. Behind it, the browser talks to a server, a computer somewhere else that holds the data. The language they use to talk is called an API (Application Programming Interface). Think of a restaurant: the menu is the API, the kitchen is the server, and the waiter carries your order back and forth. You never walk into the kitchen yourself; you ask for things through the menu.

What is GraphQL? Most APIs have many addresses, one for each thing you can do (one for listing cards, one for viewing a card, one for redeeming). GraphQL is a different style: there is usually a single address, typically /graphql, and every request is a short piece of text called a query that says exactly which fields you want back. The server has a description of everything it can do, called a Schema, like a catalogue of all the questions you are allowed to ask.

What is an IDOR? IDOR stands for Insecure Direct Object Reference. In plain words: the server hands out an object (a card, an order, a message) based only on an identifier you supply, without checking that the object actually belongs to you. Imagine a hotel where room keys are numbered 1, 2, 3 and the front desk gives you a key to any number you ask for, without checking which room you booked. That is an IDOR.

What is a race condition? A race condition happens when a system does two things at the same time and the order matters. Imagine a shop with one last concert ticket. Two cashiers both check the stock at the same moment, both see one ticket left, and both sell it. The check and the sale were separate steps, so both passed the check before either updated the stock. In software, the same thing happens when a server checks whether a voucher is unused and then marks it used in two separate steps.

What is a UPI id? UPI is an instant payment system used in India. A UPI id is a short address, like a username, that money can be sent to instantly. The company in this report paid out converted gift card money directly to a UPI id.

What does intercepting a request mean? When you click a button, your browser sends a request to the server. A tool that sits between your browser and the server can pause that request, let you look at it, change it, copy it, and then send it on. The report does not name the tool used; it only says the request was intercepted and duplicated.

The recon

The researcher found the site randomly and wanted to understand the technology it used and the kind of data being passed in the background. Very quickly it was clear the website used a GraphQL-based API, where requests are queries asking for exactly the amount of data needed.

Why does this matter to someone testing a site? Because in a GraphQL API the address for all communication usually stays the same, typically /graphql, and the queries and methods in the body define what operation runs, backed by a Schema. If you can list everything the Schema contains, you have a map of the whole site's capabilities.

There are a few ways to fetch all the available queries and mutations, and to return the entire schema. This is popularly known as the Retrospection Query. The researcher notes that these are sensitive and are usually disabled on serious production GraphQL servers, and by default on the Apollo GraphQL server, but very often they are still available.

Fetch all available queries:

Text
{  __schema {    queryType {      fields {        name      }    }  }}

Line by line, in plain words:

  • The outer { ... } is the query itself: everything inside is what you are asking for.
  • __schema asks for the schema, the catalogue of everything the server can do. The double underscore is a special name that GraphQL reserves for this kind of built-in information.
  • queryType narrows it to the part of the catalogue that describes queries, meaning read operations, things that fetch data.
  • fields asks for the list of fields inside that part.
  • name asks for just the name of each field, not its details.

So the whole thing means: give me the names of every read operation this server supports.

Fetch all available mutations:

Text
{  __schema {    mutationType {      fields {        name      }    }  }}

This is the same idea, with one change:

  • mutationType instead of queryType asks for the part of the catalogue that describes mutations, meaning write operations, things that change data (create, update, delete, pay out).
  • The rest is identical: list the fields and give their names.

Together, these two queries tell you what the server can read and what it can change. That is why they are considered sensitive: they hand an outsider a map of the whole application.

The hack

The platform used very simple queries to retrieve and show all the gift cards owned by a user. Right after login, a query for getUserStipends was made, which fetched all the cards belonging to a specific user, listing the Visa card number, the CVV and the expiry for each card. Each card had an id that was guessable and incremental, like 45, 46, 47.

Text
query getUserStipends {  myStipends {    id    status    stipend {      amount      canAccrue      colorHex      colorHex2      currency      currentIntervalStart      emoji      endDate      id      interval      logoUrl      name      nextIntervalStart      recurrenceStart      startDate      createdAt    }  }}

What this query is asking for:

  • query getUserStipends is the name of the operation, a label so both sides can refer to it.
  • myStipends is the field being requested: the list of gift cards that belong to the logged-in user. The word "my" is the important part; the server is supposed to work out who "my" is from your session.
  • id and status are basic details of each card.
  • stipend { ... } asks for the details of the gift card itself: amount, currency, startDate, endDate, interval, logoUrl, name and so on. These are display details: how much the card is worth, in what currency, when it starts and ends, what logo and colour to show.

This query listed the Visa card number, the CVV and the expiry for each card.

After clicking on a specific card there was yet another request, this time for getUserStipend, with the id of the card that had been clicked:

Text
query getUserStipend($id: Int!) {  stipendUser(id: $id) {    activeUserAddressId    id    personalCardEnabled    status    isTestCard    redemptionType    endDate    endDateExtension    stipend {      amount      canAccrue      colorHex      colorHex2      company {        id        allowParticipantBillingAddress        allowParticipantPersonalCC      }      currency      currentIntervalStart      emoji      endDate      id      interval      logoUrl      name      nextIntervalStart      recurrenceStart      startDate      createdAt      address {        city        country        id        line1        line2        phone_number        postal_code        state      }      merchantCategory {        categoryId        categoryName        merchantId        merchantName        url        logoUrl        networkId      }    }    userAddresses {      city      country      id      line1      line2      phone_number      postal_code      state    }    card {      stripeCardId      currentBalance      accruedBalance      number      cvc      expiry      status      donated      categories {        displayTitle        title      }      cardholder {        name        address {          city          country          line1          line2          postal_code          state        }      }    }    reimbursement {      history {        status        occurredAt      }      amount      targetCurrency      totalFee      wiseQuoteId      wiseRecipientId      wiseTransferId    }  }}{    "id": 100000}

This is a bigger query, so take it in pieces:

  • query getUserStipend($id: Int!) declares an operation that takes one input, $id, and the Int! means it must be a whole number and it is required (the exclamation mark means "cannot be empty").
  • stipendUser(id: $id) is the field being requested: give me the gift card whose id is the number I passed in. This is the crucial line. The server is being told which card to look up, purely by number.
  • activeUserAddressId, personalCardEnabled, status, isTestCard, redemptionType, endDate, endDateExtension are settings and status flags for that card.
  • stipend { ... } again holds the display details: amount, currency, dates, colours, logo, name. Inside it, company { ... } asks for the company's id and two settings about billing addresses and personal credit cards, and address { ... } asks for the company's address, including line1, line2, city, country, postal_code, state and phone_number. merchantCategory { ... } asks for the category the card can be spent in, with a name, a merchant id, a URL and a logo.
  • userAddresses { ... } asks for the addresses on file for the user: city, country, line1, line2, phone_number, postal_code, state.
  • card { ... } is the sensitive part: stripeCardId, currentBalance, accruedBalance, number, cvc, expiry, status, donated. number is the Visa card number, cvc is the three-digit security code on the back, and expiry is the date the card stops working. categories { ... } lists what the card can be spent on. cardholder { ... } gives the name on the card and that person's address.
  • reimbursement { ... } asks for the payout history: history { status occurredAt } (what happened and when), plus amount, targetCurrency, totalFee and three identifiers from a payment provider (wiseQuoteId, wiseRecipientId, wiseTransferId).
  • The block at the end, { "id": 100000 }, is the value for the variable. In GraphQL, the query text and the values are sent separately; this is the value that fills in $id.

So the request means: give me everything about the gift card with id 100000, including its card number, security code, expiry, the cardholder's name and address, and its payout history.

The first thing that came to the researcher's mind was to change the id parameter to something else, since it was very easily guessable.

Why that idea? Because the id is a plain whole number and the cards were numbered 45, 46, 47 and so on. If the server trusts whatever number you send, then sending 46 instead of 45 asks for someone else's card. There is nothing secret about the number, so there is nothing stopping you from trying the neighbours.

Exploitation

Step 1: change the id in getUserStipend

Changing the id parameter caused the query to execute successfully and returned the entire card details of some other user. Trying the same request with another id returned a new Visa gift card that did not belong to the researcher, every time. The response included the card number, CVC and expiry, along with the cardholder name and address, the stipend details and the reimbursement history shown in the query above.

With this, the researcher had access to thousands of valid Visa gift cards with varying values, and unhinged access to all of them, from a simple IDOR that exposed extremely confidential details valued in millions.

In everyday terms: the website asked "which card do you want to see?" and accepted any answer, without checking whether the card was yours. The researcher simply answered with other people's numbers.

Step 2: report the IDOR

The researcher took to the platform's helpline and reported the vulnerability. Within hours it was fixed and acknowledged by the company's co-founder.

From the original on monish-basaniwal.medium.com

Step 3: look at the redemption flow

The platform offered another feature: if you had been issued a gift card in some other currency, you could get it cashed out in the currency of your choice. Here they offered direct conversions between USD and INR, where the money would be paid directly to a UPI id instantly.

When a redemption process was initiated, the platform generated a quotationID with the converted amount of the card in the requested currency, and then asked for more details such as the UPI id to be paid. Once redeem was clicked, a request was sent using the quotationID to mark it paid, after which the card would no longer be useful.

Think of the quotationID as a numbered receipt: the shop writes down "this card is worth X in your currency, here is receipt number 123", and later, when you come back to collect, the shop looks up receipt 123 and stamps it "paid". A receipt should only be stamped once.

Step 4: race the redemption request

The researcher intercepted the redemption request, duplicated it a couple of times and sent them all at once. The converted amount was credited multiple times to the bank account.

The researcher's analogy: a group of slingshots tied to a single lever; when the lever is pulled all the requests are sent simultaneously to the server, and before the server can mark the quotation id as "used" the server has placed multiple redemption requests, which in turn send multiple reimbursements to the user.

From the original on monish-basaniwal.medium.com

So the researcher now had not only unlimited Visa gift cards but also a way to redeem them into a local currency multiple times per card.

Why does this work? Because several requests can reach the server before it marks the quotation id as used, so each one triggers its own payout. If several copies of the request arrive at almost the same moment, they can all pass the check before any of them has marked the quotation used. Each copy then triggers its own payout.

Root cause

The stipendUser query accepts an id from the client and returned the card for that id, including cards belonging to other users. The report does not describe the server-side code, so the exact cause is not shown. Because ids are incremental integers rather than unguessable values such as UUIDs, enumerating them is trivial.

A UUID is a long random-looking identifier, something like a very long serial number. Guessing one is impractical, whereas guessing 46 after 45 takes no effort at all.

The race condition arises because several requests can reach the server before it marks the quotation id as used, so each one triggers a redemption. The report frames the fix in terms of doing the status change and the payout in one query, and of database ACID properties, where most scalable databases place a temporary lock on the part of the data being accessed through one request so that until one operation is completely done that part of the data is not accessible by other queries. Whether the platform already had such locking in place is not stated.

ACID is a set of promises databases make about handling data safely. The relevant letter here is isolation: while one operation is working on a piece of data, other operations wait their turn. The lock is like a changing-room door: while someone is inside, the door is locked, and the next person waits until it opens.

Impact

On the IDOR, an authenticated user could read the full details of other users' gift cards, including the Visa card number, CVC and expiry, the cardholder name and address, and reimbursement information, by changing a guessable id. The researcher describes access to thousands of valid Visa gift cards with varying values, with confidential details valued in millions.

On the race condition, a user who initiates a redemption could have the converted amount credited multiple times to their bank account for a single card.

Fix

For the race condition, the report gives two recommendations:

  1. Queries leading to actions: on modules where critical systems are involved, do not talk to the database on a multi-query basis. Instead of asking about the gift card in one query and then issuing a second query to change its status, perform both in one query: 'If not paid set to paid and payout'.
  2. DB ACID properties: depending on the database, use the temporary lock that most scalable databases place on the part of the data being accessed through one request, so that until one operation is completely done that part of the data is not accessible by other queries.

In plain words, the first recommendation says: do the check and the change in one indivisible step, so there is no gap for a second request to slip through. The second says: let the database itself hold a lock on the record while it is being worked on.

Variants to test

  1. Incremental ids in GraphQL queries. Take any query that takes an object id and substitute neighbouring values. A positive result is a successful response containing another user's object, as happened here with stipendUser(id: $id).
  2. Retrospection queries. Send the two schema queries above to /graphql. A positive result is a response listing query or mutation field names, which maps the attack surface even when the server is not meant to expose it.
  3. Single-use assets under concurrency. Intercept the request that consumes a quotation, voucher or coupon and replay it several times in parallel. A positive result is more than one credit, redemption or payout for one asset.
  4. Check-then-act flows generally. Look for any flow where a status is read and then changed in a separate request, such as marking something paid or used. A positive result is the action succeeding more than once before the status change takes effect.

Closing notes

  1. Do not hesitate to change id parameters to various values, especially if they are not unique like a UUID and are incremental, as in this case.
  2. Always check for race conditions; any action which may lead to a critical action must be double-checked to be race-condition safe. These are more common in single-use assets like vouchers and coupons.

Glossary

  • API: the way a browser and a server talk to each other; a menu of requests the server accepts.
  • GraphQL: an API style with usually one address, where each request is a query naming exactly the fields wanted.
  • Query: a GraphQL request that reads data.
  • Mutation: a GraphQL request that changes data, such as creating, updating or paying out.
  • Schema: the server's catalogue of everything it can do and every field it can return.
  • Retrospection Query: a special query that asks the server to describe its own schema, listing all queries and mutations.
  • Endpoint: the address a request is sent to; for GraphQL it is usually /graphql.
  • IDOR (Insecure Direct Object Reference): a flaw where the server returns an object based on an identifier you supply without checking that the object belongs to you.
  • Authorisation check: the server's check that you are allowed to do or see the thing you asked for.
  • Incremental id: an identifier that goes up by one each time, like 45, 46, 47, making it easy to guess.
  • UUID: a long random-looking identifier that is impractical to guess.
  • Enumeration: trying a series of values, such as neighbouring ids, one after another.
  • CVV / CVC: the short security code printed on a payment card.
  • Expiry: the date after which a payment card stops working.
  • Race condition: a flaw where two operations happening at the same time produce an unintended result because the order matters.
  • Check-then-act: a flow that first checks a condition and then acts on it in a separate step, leaving a gap between the two.
  • Concurrency: several operations happening at the same time.
  • quotationID: an identifier the platform generates for a redemption, holding the converted amount, which is later marked as paid.
  • Single-use asset: something meant to be used only once, such as a voucher, coupon or quotation.
  • Reimbursement: a payout of money back to the user.
  • UPI id: a short address in India's instant payment system that money can be sent to.
  • USD / INR: United States dollar and Indian rupee.
  • ACID properties: promises databases make about handling data safely, including isolation, where one operation's data is locked until that operation finishes.
  • Lock: a temporary hold a database places on a piece of data so other operations wait.
  • Intercept: to pause a request between browser and server so it can be inspected, changed, copied or replayed.
  • Session: the state that tells the server who is logged in.
  • Bounty: a reward paid by a company for a responsibly reported security flaw.

More by Monish Basaniwal

View all

2 more disclosed reports, best first.

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.