Skip to content
Race condition Disclosed report Intermediate

Race condition in faucet when using starport

The faucet's transfer function checked the account balance and then sent tokens as two separate steps, so concurrent requests could all pass the balance check before any transfer was finalised. An attacker could therefore obtain more tokens than the configured maximum credit limit.

cyberboy Follow with z0mb13

Originally disclosed on HackerOne

Bounty$5,000 Critical 9.3 View original
  • Triaged in 7 months
  • Fixed in 7 months
  • Paid in 7 months
  • Disclosed after 7 months

Summary by the researcher

The proper writeup of the bug can be found here at our blogpost https://blog.credshields.com/race-condition-in-tendermints-starport-7cebe176d935

The root cause of the bug was in function “Transfer” at https://github.com/tendermint/starport/blob/7812125/starport/pkg/cosmosfaucet/transfer.go#L50-L74 We can notice in the code that each request to the faucet causes two actions to be made; one for querying the account’s balance and the other for sending tokens. When sending concurrent requests to the faucet, in the time of querying the balance, for some requests, this check happens at the same time and ends up seeing less balance in the account because sending the tokens action has not been finalized for the previous requests.

The report

Hi team, I and Aditya sent this bug over email on Wed, 29 Dec, 17:45 IST. Later we noticed that security reports are accepted via the HackerOne program. So, I am sending a copy of the bug report here.

Summary:

We were testing an application and we found a race condition bug in the faucet Implementation of Starport. https://github.com/tendermint/starport

Steps To Reproduce:

  1. Start a starport with the below configuration. Note the "coins_max" has been set to 11 tokens and hence a user cannot fetch more after the 11 token limits.
accounts:
  - name: alice
    coins: ["0token", "200000000stake"]
  - name: bob
    coins: ["500token", "100000000stake"]
validator:
  name: alice
  staked: "100000000stake"
client:
  openapi:
    path: "docs/static/openapi.yml"
  vuex:
    path: "vue/src/store"
faucet:
  name: bob
  coins: ["5token", "100000stake"]  
  coins_max: ["11token", "100000stake"]
  1. Now call the request manually with 5 tokens per request as in our configuration after 2 requests and 10 tokens in total Alice won't be able to fetch more tokens from the faucet
POST / HTTP/1.1
Host: 172.105.41.242:4500
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:95.0) Gecko/20100101 Firefox/95.0
Accept: application/json
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://172.105.41.242:4500/
Content-Type: application/json
Origin: http://172.105.41.242:4500
Content-Length: 63
Connection: close
{
  "address": "ALICE_ADDRESS"}

Now we can confirm Alice cannot have more than 11 tokens.

  1. Now regenerate the server and instead of sending a single request send a concurrent request to fetch tokens in Alice address. We used 50 requests concurrently.
Screenshot_2021-12-29_at_5.41.56_PM.png
Screenshot_2021-12-29_at_5.41.56_PM.png From the original on HackerOne
  1. Now when we check Alice balance it is 30 which should have not been more than 11
Screenshot_2021-12-29_at_5.43.09_PM.png
Screenshot_2021-12-29_at_5.43.09_PM.png From the original on HackerOne

We believe the root cause of the issues is the go mapping which is not advised for concurrency https://github.com/tendermint/starport/blob/develop/starport/pkg/cosmosfaucet/transfer.go#L59

Supporting Material/References:

https://cwe.mitre.org/data/definitions/362.html

Impact

A malicious user can send concurrent requests to fetch more tokes from faucets than the "max-credit limit" which allows.

The original report as published on HackerOne, by cyberboy. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely a check-then-act race: the balance is queried and the transfer sent as separate, non-atomic steps, so concurrent requests read the same pre-transfer balance.

Impact

A malicious user could send concurrent requests to obtain more tokens from the faucet than the maximum credit limit allows.

What the attacker needed

Access to a running starport faucet; ability to send concurrent requests

How it was found

  1. Start starport with a faucet configuration where coins_max is set to 11 tokens.
  2. Send a single request for 5 tokens twice and confirm the user cannot exceed 11 tokens.
  3. Restart the server and send 50 concurrent requests for tokens to the same address.
  4. Check the balance and observe it is 30, above the 11 token limit.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A faucet is a service that hands out small amounts of a cryptocurrency token, usually with a cap per user. This faucet first looked at how much the user already had and then sent tokens, but it did those two things separately, so many requests arriving at once could all see the old balance and all be approved. The result is that a user gets far more tokens than the cap allows.

What is Race condition?

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

More by cyberboy

View all

2 more disclosed reports, best first.

More from Cosmos

View all

The newest disclosed reports for this program.

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.