Gate /api/admin/stats behind an admin role check

Open
#12 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
typescript

Research direction

Start with the stats handler in apps/api/src/routes/admin.ts (lines 11-29) and the global authMiddleware mounted in apps/api/src/app.ts line 48, to see what identity is available on the request. The open question is whether admin status comes from a users.is_admin column or an allowlist, so settle that with maintainers first. Done means GET /api/admin/stats returns 403 for a non-admin and 200 for an admin, with a new test in admin.test.ts for the 403 case and the design spec updated at docs/superpowers/specs/2026-06-19-admin-upgrade-design.md.

Written by the indexing model from the issue text.

Description

P1 triage

Problem

/api/admin/stats is reachable by any logged-in user, not just admins. The design doc calls this out explicitly (docs/superpowers/specs/2026-06-19-admin-upgrade-design.md:11 — "stays open to any logged-in user (no role gating)") and apps/api/src/routes/admin.ts:11-29 has no role check beyond the global authMiddleware mounted in apps/api/src/app.ts:48.

Effect: any compromised or curious end-user account can pull org-wide engagement metrics, the 10 most-viewed document IDs, and the 10 most-active commenter user IDs. Combined with the existing /api/documents/:docId route (also unscoped beyond auth), those IDs are enough to open any document in the top-N list.

Acceptance criteria

  • GET /api/admin/stats returns 403 for non-admin users; 200 for admins.
  • Existing tests in apps/api/src/routes/admin.test.ts continue to pass (test harness uses an admin-by-default identity, or is updated to seed an admin user).
  • New test: non-admin user hitting the endpoint gets 403.
  • Frontend apps/web/src/routes/admin.tsx handles 403 gracefully (no console error spam; ideally hides the Admin nav entry for non-admins, but that can be a follow-up).
  • Update the design spec to reflect the new gating model.

Open questions for triage

  • Is there already a notion of admin in the schema (users table) or do we need to add a column / role table? A quick grep didn't find one — looks like it would be net-new.
  • Allowlist by email domain / explicit list in env, vs. a users.is_admin column? The former is a faster fix; the latter is the right long-term shape.

Surfaced during security review of the admin analytics upgrade (PR series ending at e50a779).

Dominant language
TypeScript
Stars
2
Forks
1
Avg merge
13h 38m
Merged PRs (30d)
24

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from 0xPolygon/primer

All issues in 0xPolygon/primer

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.