Gate /api/admin/stats behind an admin role check
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
- Domain
- authorization, backend
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
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/statsreturns403for non-admin users;200for admins. - Existing tests in
apps/api/src/routes/admin.test.tscontinue 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.tsxhandles403gracefully (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 (
userstable) 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_admincolumn? 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from 0xPolygon/primer
-
triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Feature: @-mention people and agents in documents and comments; a mention notifies and subscribesOpen
Difficulty 5/5 Over a week Newbie friendliness 18/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 Half a day Newbie friendliness 45/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
0xPolygon/primer#185 · 1 comment ·
Maintainers usually reply within 1 day
All issues in 0xPolygon/primer
Similar issues
-
P3
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
bug L3 level 1 needs-review wocs
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
SatyamPandey-07/WorkSphere#10739 · 1 comment ·
Maintainers usually reply within 1 day
-
maintenance
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
assistant-ui/assistant-ui#10946 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:auth-provider issue-rating: 🦞 diamond lobster no-stale P2
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
openclaw/openclaw#206303 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day