You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: prevent user ID spoofing by stripping client-supplied 'g' header in withMobileAuth - #1927
The withMobileAuth middleware in /src/middleware.ts had two vulnerabilities:
Vulnerability 1 — Auth-Key not validated:
The original code only checked if Auth-Key header existed, not its value:
if(req.headers.get('Auth-Key')){// ← any value passed!returnNextResponse.next();}
Vulnerability 2 — Client-supplied g header not stripped:
When Auth-Key matched, the middleware called NextResponse.next()
without stripping the incoming headers. This meant an attacker could:
Send a valid Auth-Key
Attach their own g: {"id": "admin-user-id"} header
The endpoint blindly trusted it:
// route.ts — trusted client-supplied g as if server set itconstuser: {id: string}=JSON.parse(request.headers.get('g')||'');
Problem
The
withMobileAuthmiddleware in/src/middleware.tshad two vulnerabilities:Vulnerability 1 — Auth-Key not validated:
The original code only checked if
Auth-Keyheader existed, not its value:Vulnerability 2 — Client-supplied
gheader not stripped:When
Auth-Keymatched, the middleware calledNextResponse.next()without stripping the incoming headers. This meant an attacker could:
Auth-Keyg: {"id": "admin-user-id"}headerAttack looked like this:
Fix