# Race condition in faucet when using starport

Concurrent faucet requests bypass the coins_max credit limit because balance check and token send are non-atomic, letting a user drain more tokens than allowed.

- Payout: $5,000
- Severity: critical
- Program: Cosmos
- Found by: cyberboy
- Disclosed: 2022-07-26
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/1438052
- Library page: https://bugbountylibrary.com/r/h1%3A1438052
- Tags: area:web domain:api impact:funds-loss kind:bounty platform:hackerone sev:critical tech:go technique:race-window vuln:business-logic vuln:race-condition

**Target:** Starport cosmosfaucet HTTP endpoint (POST /)
**Root cause:** Transfer() reads the account balance and then sends tokens as separate non-atomic steps; concurrent requests all pass the balance check before any send finalizes, and the shared Go map is not concurrency-safe.
**Steps:**
1. Configure faucet with `coins_max: ["11token", ...]` and per-request `5token`.
2. Send `POST /` with `{"address":"ALICE_ADDRESS"}` twice to confirm the 11-token cap blocks further requests.
3. Fire ~50 concurrent identical POST requests to the faucet for the same address.
4. Check Alice balance: it is 30 tokens, exceeding the 11-token cap.
**How found:** While testing a Starport app, noticed the faucet enforced a coins_max cap; hypothesized the check-then-send flow in transfer.go was non-atomic and confirmed by replaying requests concurrently.
**Exploitation:** Attacker sends a burst of parallel faucet requests for one address; each request's balance query races before prior sends settle, so all pass the max-credit check and tokens are disbursed beyond the limit.
**Insight:** Faucet/credit-limit logic that does a read-then-write on shared state is a race target: test any per-address cap by firing parallel requests and comparing final balance to the configured max.

## Proof of concept (copied exactly from the original report)

**Concurrent faucet requests to exceed coins_max**

```
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.
```

**Faucet config with coins_max limit**

```
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"]
```

**Manual faucet POST request**

```
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"}
```

