# Taskcluster web-server OAuth2 authorization codes are reusable and the exchange handler checks the wrong expiry column

Taskcluster OAuth2 token-exchange handler never consumes authorization codes and checks the wrong expiry column, letting a leaked code be replayed to mint fresh bridge tokens and Taskcluster credentials in the victim's identity.

- Payout: $2,000
- Severity: medium
- Program: Mozilla
- Found by: anshuman_bh
- Disclosed: 2026-06-23
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/3734676
- Library page: https://bugbountylibrary.com/r/h1%3A3734676
- Tags: area:web domain:web impact:ato impact:internal-access kind:bounty platform:hackerone sev:medium tech:oauth technique:incomplete-fix technique:source-review vuln:access-control vuln:auth-bypass

**Target:** Taskcluster web-server OAuth2 endpoints (/login/oauth/token, /login/oauth/credentials)
**Root cause:** The exchange handler at oauth2.js:165-199 mints a bridge token without deleting the authorization_codes row, and its expiry check reads entry.client_details.expires (requested credential lifetime, up to 1 year) instead of the code row's entry.expires (10 minutes). Same column mismatch in /login/oauth/credentials.
**Steps:**
1. Register/use `test-code-whitelisted` client; `GET /login/oauth/authorize` to obtain an authorization code
2. `POST /login/oauth/token` with the code -> 200, token A
3. Replay same code via `POST /login/oauth/token` -> 200, token B (token A != token B)
4. `GET /login/oauth/credentials` with `Authorization: Bearer <token B>` -> 200, Taskcluster credentials in original user's identity
5. Repeat replay until daily cleanup-expire-auth-codes cron removes the row
**How found:** Code review of the OAuth2 handler: noticed the exchange path never deletes the authorization_codes row and that the expiry check referenced client_details.expires rather than the row's own expires, then wrote a Mocha test extending third_party_test.js to confirm replay succeeds.
**Exploitation:** Attacker who captures a leaked authorization code (referer, redirect logs, TLS-inspecting proxy, browser history) replays POST /login/oauth/token to mint fresh bridge access tokens bound to the victim's identity and consented scopes, then converts via GET /login/oauth/credentials to Taskcluster credentials carrying the victim's Firefox-CI scopes.
**Escalation:** Replay window extends from intended 10 minutes to many hours (bounded by client_details.expires up to 1 year and the daily cleanup cron); credentials carry privileged Firefox-CI scopes (e.g. mozilla-employee roles), impacting Firefox build CI integrity.
**Insight:** In OAuth2 implementations, verify the exchange handler both atomically consumes the code (DELETE ... RETURNING) and checks the code row's own expiry field, not a nested client_details field that may represent a different lifetime; grep for `client_details.expires` vs `entry.expires` mismatches across all token handlers.

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

**Mocha command running TC-002 PoC test**

```
TEST_DB_URL=postgresql://postgres@localhost:5432/taskcluster-test NODE_ENV=test \
    yarn mocha --grep "TC-002" test/third_party_test.js
```

**Proposed consume_authorization_code SQL fix**

```
DELETE FROM authorization_codes
 WHERE code = code_in
   AND client_id = client_id_in
   AND redirect_uri = redirect_uri_in
   AND expires > now()
 RETURNING code, client_id, redirect_uri, identity, identity_provider_id, expires, client_details;
```

