Skip to content

Reconcile dashboard /api/stats auth parameter#81

Merged
TeoSlayer merged 1 commit into
mainfrom
fix/dashboard-stats-auth-param
Jun 22, 2026
Merged

Reconcile dashboard /api/stats auth parameter#81
TeoSlayer merged 1 commit into
mainfrom
fix/dashboard-stats-auth-param

Conversation

@TeoSlayer

Copy link
Copy Markdown
Contributor

Summary

The dashboard frontend authenticated to /api/stats by sending ?token=<t>, but /api/stats is wrapped in requireAdminToken (PR #50), which only accepts an admin token via the X-Admin-Token header or admin_token= query param. The ?token= param was ignored by the gate, so the operator's stats request silently returned 401 — and the inner dashboard-token elevation check inside the handler had become dead code (the admin gate rejects anything without the admin token first).

Fix (consistent + secure)

The token the frontend stores is the operator admin token — it is already sent as admin_token= to /api/pulse. Reconcile on that:

  • Frontend: /api/stats is now fetched with admin_token=<t> (was token=), matching every other operator call.
  • Backend: once requireAdminToken has confirmed a valid admin token reached the handler, the elevated per-network payload is returned. Removed the dead inner dashboard-token branch.

Auth strength is unchanged: a missing token, a wrong token, the legacy ?token=, and the unconfigured-token case all still return 401.

Route registration was factored into buildMux() so the real /api/stats auth path is exercised end-to-end in tests rather than via a re-implemented shim.

Tests

  • TestStatsAuth_AdminTokenQueryParamadmin_token= query and X-Admin-Token header both accepted (200).
  • TestStatsAuth_RejectsBadAndMissingToken — missing / wrong / legacy ?token= all 401.
  • TestStatsAuth_UnconfiguredLocksShut — no admin token configured => 401.

Validation

GOWORK=off go build/vet ./... clean; GOWORK=off go test -race -parallel 4 ./... green (all packages); gofmt clean.

The dashboard frontend authenticated to /api/stats with ?token=<t>,
but the endpoint is wrapped in requireAdminToken (PR #50) which only
accepts an admin token via X-Admin-Token header or admin_token= query.
?token= was ignored by the gate, so operator stats requests silently
401'd, and the inner dashboard-token elevation check had become dead
code behind the admin gate.

Reconcile on the admin gate (the secure, consistent option — the
stored token is the same admin token /api/pulse already uses):
the frontend now sends admin_token=, and the handler returns the
elevated payload once requireAdminToken has confirmed a valid admin
token reached it. Auth strength is unchanged; a missing/wrong token
and the legacy ?token= still 401.

Factor route registration into buildMux() so the real /api/stats auth
path is testable, and add coverage for the accepted and rejected
auth cases.
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@TeoSlayer TeoSlayer merged commit 1a7a362 into main Jun 22, 2026
9 checks passed
@matthew-pilot matthew-pilot deleted the fix/dashboard-stats-auth-param branch June 22, 2026 15:48
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.

2 participants