Skip to content

test(admin_test_token): pin ADMIN_TOKEN IDOR-fix (#112) gate behavior - #2373

Merged
HongmingWang-Rabbit merged 1 commit into
stagingfrom
auto/admin-test-token-mock-coverage
Apr 30, 2026
Merged

test(admin_test_token): pin ADMIN_TOKEN IDOR-fix (#112) gate behavior#2373
HongmingWang-Rabbit merged 1 commit into
stagingfrom
auto/admin-test-token-mock-coverage

Conversation

@HongmingWang-Rabbit

Copy link
Copy Markdown
Contributor

Summary

The admin test-token endpoint has a critical security check at `admin_test_token.go:64-72` — the IDOR fix from #112 that requires an explicit `ADMIN_TOKEN` bearer when the env var is set. Pre-fix, the route accepted ANY bearer that matched a live org token, allowing cross-org test-token minting (and therefore cross-org workspace authentication). The current code uses `subtle.ConstantTimeCompare` against `ADMIN_TOKEN`.

Test coverage was zero. Existing tests exercised the `ADMIN_TOKEN`-unset path (local dev / CI) but never set `ADMIN_TOKEN`. A regression that:

  • removed the `os.Getenv("ADMIN_TOKEN")` check
  • inverted the comparison
  • replaced `ConstantTimeCompare` with `bytes.Equal` (timing leak)
  • re-introduced the `AdminAuth` fallback that allowed org tokens

would not fail any test, and the breakage would re-open the IDOR that #112 closed.

Changes

Adds four tests covering the gate's full truth table:

  • `TestAdminTestToken_AdminTokenRequired_NoHeader` — ADMIN_TOKEN set + no Authorization → 401
  • `TestAdminTestToken_AdminTokenRequired_WrongHeader` — ADMIN_TOKEN set + wrong Authorization → 401
  • `TestAdminTestToken_AdminTokenRequired_CorrectHeader` — ADMIN_TOKEN set + correct Authorization → 200
  • `TestAdminTestToken_AdminTokenEmpty_GateBypassedSafely` — ADMIN_TOKEN unset + no Authorization → 200

Any regression in either dimension (gate enabled/disabled × header correct/wrong) trips exactly one test.

Test plan

  • All 4 new tests pass
  • Full module green
  • Verified gate fires correctly: temporarily commenting out the gate makes the no-header / wrong-header tests fail (as expected)

🤖 Generated with Claude Code

The admin test-token endpoint has a critical security check at
admin_test_token.go:64-72 — the IDOR fix from #112 that requires an
explicit ADMIN_TOKEN bearer when the env var is set. Pre-fix, the
route accepted ANY bearer that matched a live org token, allowing
cross-org test-token minting (and therefore cross-org workspace
authentication). The current code uses subtle.ConstantTimeCompare
against ADMIN_TOKEN.

Test coverage was zero. The existing tests exercised the
ADMIN_TOKEN-unset path (local dev / CI) but never set ADMIN_TOKEN.
A regression that:

  - removed the os.Getenv("ADMIN_TOKEN") check
  - inverted the comparison
  - replaced ConstantTimeCompare with bytes.Equal (timing leak)
  - re-introduced the AdminAuth fallback that allows org tokens

would not fail any test, and the breakage would re-open the IDOR
that #112 closed.

Adds four tests covering the gate matrix:

  - ADMIN_TOKEN set + no Authorization header → 401
  - ADMIN_TOKEN set + wrong Authorization → 401
  - ADMIN_TOKEN set + correct Authorization → 200
  - ADMIN_TOKEN unset + no Authorization → 200 (gate bypassed safely)

The 4-row matrix pins the gate's full truth table: any regression in
either dimension (gate enabled/disabled, header correct/wrong) trips
exactly one test.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@HongmingWang-Rabbit
HongmingWang-Rabbit added this pull request to the merge queue Apr 30, 2026
Merged via the queue into staging with commit 17760e1 Apr 30, 2026
18 checks passed
@HongmingWang-Rabbit
HongmingWang-Rabbit deleted the auto/admin-test-token-mock-coverage branch April 30, 2026 10:06
HongmingWang-Rabbit pushed a commit that referenced this pull request Jun 12, 2026
Serialized merge by gitea-merge-queue after current-main, genuine approvals, and required CI checks were green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant