Skip to content
Race condition Write-up Intermediate

Hacking Starbuck for unlimited money

A race condition in Starbucks' gift card transfer feature allowed an attacker to duplicate transfers, creating money from thin air. By sending multiple simultaneous confirmation requests from different sessions, the attacker could increase the balance on a gift card beyond its actual value.

Egor Homakov Follow

Published on sakurity.com

This is a story about how I found a way to generate unlimited amount of money on Starbucks gift cards to get life-time supply of coffee or steal a couple of $millions.

Egor Homakov, on sakurity.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

Starbucks gift cards can be registered to a personal account on starbucks.com. From that account a user can add gift cards, check their balances, and transfer money between their own gift cards. The transfer feature is the part that matters here: it moves a balance from one card to another, which makes it a stateful, money-like operation and therefore a candidate for a race condition.

The author got the idea to buy three Starbucks cards at $5 each.

From the original on sakurity.com

Setup

  • Three Starbucks gift cards, $5 each, registered to a personal account on starbucks.com.
  • Two different browsers logged into the same account, so that the same account holds two independent session cookies.
  • No special tooling is described beyond the ability to fire the confirmation request repeatedly and in parallel.

Finding it

The transfer is a two-step, stateful flow. The first request stores the transfer parameters in the session:

HTTP
POST /step1?amount=1&from=wallet1&to=wallet2

The second request performs the actual transfer and clears the session:

HTTP
POST /step2?confirm

Because the session is destroyed right after the first confirmation request, a naive attempt to replay step2 fails: the second request has nothing left to confirm. That looks like a protection against double-spending, but it is only a session-level one. Using the same account from two different browsers gives two different session cookies, each holding its own copy of the pending transfer state, so both can confirm.

The author describes the exploit as pseudo code rather than a full script.

Exploitation

Step 1: Prepare the transfer in two sessions

Log the same account into two browsers. In each session, issue the first request with the same parameters, so both sessions hold a pending transfer of the same amount from the same source card to the same destination card:

HTTP
POST /step1?amount=1&from=wallet1&to=wallet2

Step 2: Confirm in parallel

Fire the confirmation request from both sessions at the same time:

HTTP
POST /step2?confirm

The goal is for both confirmations to read the same source balance before either one writes the reduced balance back. If the check and the debit are not atomic, both transfers succeed even though the source card only has enough for one.

Step 3: Retry until it lands

The first five attempts failed. The author notes that with race conditions you never know in advance whether the application is vulnerable, so persistence is part of the method. On the sixth attempt the race hit: two $5 transfers were created from wallet1, which had a $5 balance. The result was two cards holding $15 and $5, $20 in total, after two $5 transfers from wallet1 with a $5 balance.

Step 4: Prove it in the real world

A balance in a web account can always be dismissed as a cache artefact, so the author went to the nearest Starbucks on Market St to spend the money.

  • Can I have anything for $16?
  • O_o
  • What's most expensive thing here?
  • That sandwich, I guess.
From the original on sakurity.com

$15 went in and $16.70 came out. To make sure the US justice system would not put him in jail over $1.70, he then deposited $10 from a credit card.

Root cause

The transfer is split into a stateful prepare step and a confirm step, and the confirm step both checks the balance and performs the debit. The session is cleared after the first confirmation, which stops a simple replay within one session, but it does not serialise concurrent confirmations coming from different sessions of the same account. Two sessions each carry their own pending state, and both confirmations can pass the balance check before either debit is committed.

The author lists the poor protections he has seen developers rely on: limiting the number of requests per IP, per account or per action, adding a random delay, or using database transactions incorrectly. The only correct approach, in his words, is a pessimistic lock, a FOR UPDATE clause, so that the balance row is locked for the duration of the check-and-debit.

Impact

An attacker with an account and at least one funded gift card can create money on their own cards by racing the transfer confirmation. In this test, a $5 balance produced $20 across two cards, and the credit was spendable at a real store. The author frames the ceiling as unlimited: with the same trick repeated, the balance could in principle be inflated without bound.

He also describes what he could have done instead of reporting: buy a batch of fake gift cards from around the world, silently generate credits on them, and sell Starbucks credit online for Bitcoin at, say, a 50% discount. He estimates that would easily make a couple of millions of dollars, unless Starbucks actually tracks gift card balances. He is explicit that this is a wild guess and that he does not know for sure how profitable the bug would be.

Fix

The bug was fixed in like 10 days after the author tried hard to find anyone who cared. The report does not describe the code change. The author says the only right way to prevent this is a pessimistic lock (FOR UPDATE).

Variants to test

  1. Two-session confirmation on any two-step money flow. Prepare the same transfer in two browsers on one account, then confirm both at once. A positive result is two debits from a balance that only covers one, visible as an inflated total across the destination cards.
  2. Repeated parallel confirmation. Send many confirmations of the same pending transfer simultaneously rather than two. A positive result is more than two successful debits, which shows the window is wider than a single pair.
  3. Other limited resources. Apply the same pattern to vouchers, promo codes, withdrawals and refunds, where a check and a write are separate. A positive result is a resource consumed more times than its balance allows.
  4. Defences that only look like defences. Test whether per-IP, per-account or per-action rate limits, random delays or plain transactions actually prevent the double spend. A positive result is a successful race despite those controls being present.

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 make money appear on Starbucks gift cards out of thin air. He bought three cards worth $5 each, registered them to a normal account on starbucks.com, and then abused a flaw in the feature that lets you move money from one of your cards to another. By sending the same transfer confirmation twice at almost exactly the same moment, from two different browsers logged into the same account, he got the site to move the same $5 twice. He then walked into a real Starbucks and spent the money on a sandwich, which proved the balance was real and not a display glitch.

This is a beginner-friendly retelling of his write-up. It assumes you can use a browser and a computer, and nothing else. Every technical idea is explained from zero the first time it appears.

The product and the feature

A Starbucks gift card is a small card with a balance on it, like a prepaid wallet for coffee. On starbucks.com you can create a personal account and register gift cards to it. From that account you can:

  • add gift cards,
  • check how much money is on each one,
  • and transfer money between your own cards.

The transfer feature is the interesting part. It takes money off one card and puts it on another. That makes it a stateful operation: the site has to remember, between one request and the next, what it is in the middle of doing. It also makes it money-like, and money-like features are exactly where a class of bug called a race condition tends to appear.

The author got the idea to buy three Starbucks cards at $5 each.

From the original on sakurity.com

Two ideas you need first

A request. When you click a button on a website, your browser sends a small message to the site's server (the computer that runs the site) asking it to do something. That message is a request. The server sends back a response, usually a page or a piece of data. A request has a method (such as POST, meaning "please create or change something"), a path (which part of the site it is aimed at), and sometimes extra values attached to it.

A session and a cookie. A website needs to know that two requests come from the same logged-in person. It does this with a session: the server keeps a small record for you, and gives your browser a short identifier for that record, stored in a cookie. Your browser sends the cookie back with every request, and the server looks up your session. Think of it like a coat-check ticket: the ticket itself is not your coat, it just tells the attendant which coat is yours. If you log in from a second browser, you get a second ticket and a second session, even though it is the same account.

The vulnerability class: race condition

A race condition happens when two things that should happen one after the other instead happen at the same time, and the program was not built to cope with that. The everyday comparison is two people withdrawing money from the same bank account at the same instant. Each cashier checks the balance, sees $5, and hands over $5. Neither cashier sees the other's withdrawal because both looked before either one wrote the new balance down. The account had $5 but $10 walked out of the door.

Websites with balances, vouchers or other limited resources are common places to find this, because the pattern is always the same: check the balance, then reduce it. If those two actions are not treated as one indivisible step, two requests can both pass the check before either one does the reduction.

How the transfer works

The transfer is a two-step flow, and the site remembers the details between the steps in your session.

The first request stores the transfer parameters in the session:

HTTP
POST /step1?amount=1&from=wallet1&to=wallet2

Line by line:

  • POST is the method: this request is asking the server to change something, not just to show a page.
  • /step1 is the path: the first stage of the transfer.
  • ?amount=1 says how much to move. Here it is 1 unit of currency.
  • &from=wallet1 says which card the money comes from. wallet1 is a placeholder name for one of the author's cards.
  • &to=wallet2 says which card the money goes to. wallet2 is a placeholder for another of his cards.

Nothing has moved yet at this point. The server has simply written down, in your session, "this person wants to move 1 from wallet1 to wallet2".

The second request performs the actual transfer and clears the session:

HTTP
POST /step2?confirm

Line by line:

  • POST again: this is another action request.
  • /step2 is the second stage, the one that actually moves the money.
  • ?confirm is a flag telling the server "yes, do it".

After this second request the server wipes the pending transfer from your session. That is meant to stop you from simply sending the confirmation again and again: the first confirmation uses up the pending transfer, and any repeat finds nothing left to confirm.

Why the obvious attack fails, and the way around it

If you try to send /step2?confirm twice from the same browser, the second one fails. The session was cleared by the first, so there is no pending transfer left. On the surface that looks like a defence against spending the same money twice.

But it is only a defence at the level of a single session. Remember the coat-check ticket: log the same account into two different browsers and you get two different session cookies, so the server keeps two separate session records. Each one can hold its own copy of the pending transfer. Prepare the same transfer in both, then confirm in both, and each confirmation has its own pending state to work from.

The author describes the exploit as pseudo code rather than a full script, so there is no program to copy here; the method is the two browsers and the two requests.

Carrying out the attack

Step 1: Prepare the transfer in two sessions

Log the same account into two browsers. In each session, send the first request with the same parameters, so both sessions hold a pending transfer of the same amount from the same source card to the same destination card:

HTTP
POST /step1?amount=1&from=wallet1&to=wallet2

Why this step: the goal is to have two independent sessions that both believe a transfer is waiting to be confirmed. Neither browser knows about the other.

Step 2: Confirm in parallel

The next step is to fire the confirmation request from both sessions at the same time:

HTTP
POST /step2?confirm

Why this step: the aim is for both confirmations to read the same source balance before either one writes the reduced balance back. If the check and the debit are not atomic (not treated as one indivisible action), both transfers succeed even though the source card only has enough for one.

Step 3: Retry until it lands

The first five attempts failed. The author notes that with race conditions you never know in advance whether the application is vulnerable, so persistence is part of the method. On the sixth attempt the race hit: two $5 transfers were created from wallet1, which had a $5 balance. The result was two cards holding $15 and $5, $20 in total, after two $5 transfers from wallet1 with a $5 balance.

Why this step matters: a race condition is a timing problem, and timing is not guaranteed. Sometimes the two requests arrive far enough apart that the first finishes before the second starts, and nothing goes wrong. You have to keep trying until the timing lines up.

Step 4: Prove it in the real world

A balance shown in a web account can always be dismissed as a cache artefact. A cache is a stored copy of something, kept so it can be shown faster next time; a stale cache can display an old or wrong number. So the author went to the nearest Starbucks on Market St to spend the money, because a sandwich you can actually eat cannot be a caching bug.

  • Can I have anything for $16?
  • O_o
  • What's most expensive thing here?
  • That sandwich, I guess.
From the original on sakurity.com

$15 went in and $16.70 came out. To make sure the US justice system would not put him in jail over $1.70, he then deposited $10 from a credit card.

Root cause

The transfer is split into a stateful prepare step and a confirm step, and the confirm step both checks the balance and performs the debit. The session is cleared after the first confirmation, which stops a simple replay within one session, but it does not serialise concurrent confirmations coming from different sessions of the same account. To serialise means to force actions to happen one at a time, in a queue, rather than side by side. Two sessions each carry their own pending state, and both confirmations can pass the balance check before either debit is committed.

The author lists the poor protections he has seen developers rely on: limiting the number of requests per IP, per account or per action, adding a random delay, or using database transactions incorrectly. An IP is the numeric address your connection comes from; a rate limit is a cap on how many requests you may send in a period. None of these fix the underlying problem, because they slow an attacker down rather than making the check-and-debit indivisible. The only correct approach, in his words, is a pessimistic lock, a FOR UPDATE clause, so that the balance row is locked for the duration of the check-and-debit. A database is where the site stores its data; a row is one record in it, such as one card's balance. A lock means "nobody else may touch this row until I am done", which forces the second confirmation to wait its turn.

Impact

An attacker with an account and at least one funded gift card can create money on their own cards by racing the transfer confirmation. In this test, a $5 balance produced $20 across two cards, and the credit was spendable at a real store. The author frames the ceiling as unlimited: with the same trick repeated, the balance could in principle be inflated without bound.

He also describes what he could have done instead of reporting: buy a batch of fake gift cards from around the world, silently generate credits on them, and sell Starbucks credit online for Bitcoin at, say, a 50% discount. Bitcoin is a digital currency. He estimates that would easily make a couple of millions of dollars, unless Starbucks actually tracks gift card balances. He is explicit that this is a wild guess and that he does not know for sure how profitable the bug would be.

Fix

The bug was fixed in like 10 days after the author tried hard to find anyone who cared. The report does not describe the code change. The author says the only right way to prevent this is a pessimistic lock (FOR UPDATE).

Variants to test

  1. Two-session confirmation on any two-step money flow. Prepare the same transfer in two browsers on one account, then confirm both at once. A positive result is two debits from a balance that only covers one, visible as an inflated total across the destination cards.
  2. Repeated parallel confirmation. Send many confirmations of the same pending transfer simultaneously rather than two. A positive result is more than two successful debits, which shows the window is wider than a single pair.
  3. Other limited resources. Apply the same pattern to vouchers, promo codes, withdrawals and refunds, where a check and a write are separate. A positive result is a resource consumed more times than its balance allows.
  4. Defences that only look like defences. Test whether per-IP, per-account or per-action rate limits, random delays or plain transactions actually prevent the double spend. A positive result is a successful race despite those controls being present.

Glossary

  • Request: a message your browser sends to a website's server asking it to do something or show something.
  • Response: the message the server sends back.
  • Server: the computer that runs a website and holds its data.
  • POST: a request method used when you want the site to create or change something, rather than just display a page.
  • Path: the part of a request that says which feature of the site it is aimed at, such as /step1.
  • Parameter: an extra value attached to a request, such as amount=1 or from=wallet1.
  • Session: the server's record of who you are and what you are in the middle of doing, kept between requests.
  • Cookie: a small piece of data your browser stores and sends back with each request, used here to identify your session.
  • Stateful: remembering information between one request and the next, rather than treating each request as brand new.
  • Race condition: a bug where two actions that should happen one after the other happen at the same time, so a check made by both passes before either one's change is saved.
  • Atomic: treated as one indivisible step, so nothing else can slip in between its parts.
  • Serialise: force actions to happen one at a time in a queue instead of side by side.
  • Pessimistic lock: a rule that one request takes exclusive control of a piece of data until it is finished with it.
  • FOR UPDATE: a database instruction that locks the selected row so other requests must wait.
  • Database: where a website stores its data, such as card balances.
  • Row: one record in a database, for example one card's balance.
  • Cache: a stored copy of data kept for speed, which can sometimes show an old or wrong value.
  • Rate limit: a cap on how many requests you may send in a period, per IP, per account or per action.
  • IP address: the numeric address your internet connection comes from.
  • Bitcoin: a digital currency.
  • Pseudo code: a description of a program's steps in plain language rather than a runnable script.

More by Egor Homakov

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.