Skip to content

fix: prevent admin PII leak via forged session cookie - #5

Open
zenith600 wants to merge 1 commit into
mainfrom
fix/admin-auth-layout-bypass
Open

fix: prevent admin PII leak via forged session cookie#5
zenith600 wants to merge 1 commit into
mainfrom
fix/admin-auth-layout-bypass

Conversation

@zenith600

@zenith600 zenith600 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Vulnerability

app/admin/layout.tsx rendered {children} for unauthenticated requests (it only dropped the sidebar chrome). Because the admin pages (/admin, /admin/teams, /admin/teams/[id]) do no auth check of their own, and middleware.ts only checks that the admin_session cookie is present (not valid — the DB check can't run at the Edge), a request carrying any non-empty admin_session cookie value rendered the full admin pages and leaked all registration PII (names, student IDs, emails, phone/WhatsApp numbers) with no valid session.

Repro: set admin_session=anything and GET /admin/teams → team list rendered unauthenticated.

Fix

  • app/admin/layout.tsx: when there is no valid session, redirect to /admin/login for every route except the login page (which must render for logged-out users).
  • middleware.ts: forward the request path as an x-pathname header so the server layout can tell the login route apart from protected pages without an infinite redirect loop.

Authoritative auth already happens in the layout via getAdminSession() (DB-backed); this change makes a failed check actually block rendering instead of falling through.

Scope

Cookie/auth-bypass issue only. 2 files, additive changes, no file moves — minimal merge-conflict surface. Does not touch the other findings (CSV export injection, Google Sheets formula injection, admin search regex escaping) — those are separate.

Behavior

Case Before After
Authenticated, any admin page renders renders (unchanged)
Unauth, /admin/login renders renders (unchanged)
Unauth/forged cookie, protected page renders (leak) redirects to /admin/login

API routes (/api/admin/*) already enforced getAdminSession() and are unaffected.

Testing

  • tsc --noEmit: no new errors from the two changed files (the only error is a pre-existing missing googleapis module in lib/googleSheets.ts, unrelated).

@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pandora-buildathon-web-vxkj Ready Ready Preview, Comment Jul 10, 2026 4:56pm

The admin layout rendered {children} for unauthenticated requests
(only stripping the sidebar), so a present-but-invalid `admin_session`
cookie passed the middleware presence-check and rendered protected
admin pages — leaking all registration PII without a valid session.

The layout now redirects unauthenticated requests to /admin/login for
every route except the login page itself. Middleware forwards the
request path via an `x-pathname` header so the server layout can make
that distinction without triggering a redirect loop on /admin/login.
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