fix: prevent admin PII leak via forged session cookie - #5
Open
zenith600 wants to merge 1 commit into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
zenith600
force-pushed
the
fix/admin-auth-layout-bypass
branch
from
July 10, 2026 16:53
b9f87fe to
201c1a2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vulnerability
app/admin/layout.tsxrendered{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, andmiddleware.tsonly checks that theadmin_sessioncookie is present (not valid — the DB check can't run at the Edge), a request carrying any non-emptyadmin_sessioncookie 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=anythingand GET/admin/teams→ team list rendered unauthenticated.Fix
app/admin/layout.tsx: when there is no valid session, redirect to/admin/loginfor every route except the login page (which must render for logged-out users).middleware.ts: forward the request path as anx-pathnameheader 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
/admin/login/admin/loginAPI routes (
/api/admin/*) already enforcedgetAdminSession()and are unaffected.Testing
tsc --noEmit: no new errors from the two changed files (the only error is a pre-existing missinggoogleapismodule inlib/googleSheets.ts, unrelated).