Skip to content

Add protected admin diagnostics endpoint#28

Open
Spbd1 wants to merge 1 commit into
codex/harden-admin-and-api-securityfrom
codex/add-protected-diagnostics-endpoint
Open

Add protected admin diagnostics endpoint#28
Spbd1 wants to merge 1 commit into
codex/harden-admin-and-api-securityfrom
codex/add-protected-diagnostics-endpoint

Conversation

@Spbd1

@Spbd1 Spbd1 commented May 11, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Provide a small, safe diagnostics endpoint for final VPS debugging without exposing secrets.
  • Reuse existing admin bearer auth so only authorized operators can call diagnostics in production.
  • Surface a quick diagnostics view in the admin UI so operators can validate environment and DB connectivity after entering the admin token.

Description

  • Added GET /api/admin/diagnostics at app/api/admin/diagnostics/route.ts that requires the same ADMIN_EXPORT_TOKEN bearer auth and returns only safe JSON fields (environment, app version, times, booleans, numeric limits, latest/total submission metrics) and never reveals secret values or URLs.
  • Diagnostics performs a lightweight DB reachability check via prisma.$queryRaw\SELECT 1`and gatherscount()and latestsubmittedAtwithfindFirst(); when the DB is configured but unreachable the route returns a safe payload with { ok: false, error: "Database is configured but unreachable." }and status503`.
  • Reused adminJsonResponse (which applies Cache-Control: no-store) and validateAdminRequest from lib/adminAuth.server.ts to enforce the same token rules and safe headers.
  • Exported the admin token sentinel as DEFAULT_ADMIN_EXPORT_TOKEN from lib/adminAuth.server.ts so diagnostics can report whether the configured token still uses the placeholder without exposing token values.
  • Added a client-side diagnostics panel to the admin dashboard in components/admin/AdminDashboard.tsx that fetches /api/admin/diagnostics after token entry, shows status badges and safe details, and includes a copyable curl example.

Testing

  • Changed files: app/api/admin/diagnostics/route.ts, lib/adminAuth.server.ts, components/admin/AdminDashboard.tsx.
  • Commands run: npm run typecheck (succeeded), npm run lint (succeeded; project already shows an unrelated React Hook warning in components/ParticipantBackgroundForm.tsx), npm run build (Next.js build succeeded).
  • curl example: curl -H "Authorization: Bearer TOKEN" https://domain.com/api/admin/diagnostics.
  • Behavior verified: endpoint requires valid bearer token (returns 401 for missing/invalid token), returns 503 with a safe message when DB is configured but unreachable, and sets Cache-Control: no-store on responses.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant