Skip to content

Harden admin/backend route gating (defense-in-depth)#146

Merged
mvalancy merged 1 commit into
devfrom
harden/admin-route-guards
Jun 20, 2026
Merged

Harden admin/backend route gating (defense-in-depth)#146
mvalancy merged 1 commit into
devfrom
harden/admin-route-guards

Conversation

@mvalancy

Copy link
Copy Markdown
Member

Follow-up to the 6-agent live audit, which found admin access is already correctly enforced server-side (Worker → "Admins only."/UNAUTHENTICATED for non-admins; forged tokens rejected). This is UI defense-in-depth so the client matches that boundary and stops looking like a leak.

  • lib/roleAccess.ts — single source of truth (canAccessAdmin/canAccessBackend) used by both the router guard and the nav.
  • RequireRole/admin (ADMIN) and /backend (not GUEST/VIEWER) redirect home for disallowed roles instead of mounting + showing an "Access Denied" shell.
  • Layout + MobileBottomNav — role-gated Admin/System links hidden entirely for non-admins (was greyed-but-visible).

Verified: unit + component tests (redirect-vs-allow per role); typecheck; web unit suite 227/227; THE GATE 5/5; dev non-admin → /admin redirects to /, no nav link, no shell, no data.

Note: this lands on dev; the live Cloudflare site keeps the (already-safe) current behavior until a deploy.

🤖 Generated with Claude Code

…-in-depth)

The 6-agent live audit found admin access is correctly enforced server-side (the
Worker returns "Admins only."/UNAUTHENTICATED to non-admins, rejects forged
tokens), so this is NOT a fix for a breach — it's UI defense-in-depth so the
client matches that boundary:

- lib/roleAccess.ts: single source of truth — canAccessAdmin / canAccessBackend
  (mirrors the prior inline nav logic), used by the router guard AND the nav so
  they can't drift.
- components/RequireRole.tsx: router guard — /admin (ADMIN) and /backend
  (not GUEST/VIEWER) now redirect home for disallowed roles instead of mounting
  the page and showing an in-component "Access Denied" shell (which is what made
  it look like non-admins could "see" the admin page).
- Layout + MobileBottomNav: role-gated Admin/System links are now hidden entirely
  for users who can't reach them (was greyed-but-visible).

Verified: roleAccess + RequireRole unit/component tests (redirect-vs-allow per
role, incl. unauthenticated); web typecheck; full web unit suite 227/227; THE
GATE 5/5 (admin still reaches /admin); dev non-admin → /admin redirects to /,
no nav link, no shell, no data.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mvalancy mvalancy merged commit de8a3fc into dev Jun 20, 2026
@mvalancy mvalancy deleted the harden/admin-route-guards branch June 20, 2026 07:01
@github-actions

Copy link
Copy Markdown

🧪 Comprehensive Test Suite

  • Unit suites (Node 18.x & 20.x) — core, web, server, mcp-server: ✅ passed
  • Installer & deploy config: ✅ passed

Full-stack smoke gate runs in the CI workflow.

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