Skip to content

fix(api): Remove x-dev-user-id auth bypass from assessment endpoint - #1247

Open
jeromehardaway wants to merge 1 commit into
masterfrom
fix/assessment-auth-bypass
Open

fix(api): Remove x-dev-user-id auth bypass from assessment endpoint#1247
jeromehardaway wants to merge 1 commit into
masterfrom
fix/assessment-auth-bypass

Conversation

@jeromehardaway

Copy link
Copy Markdown
Contributor

Problem

/api/user/assessment honored an x-dev-user-id header with no NODE_ENV gate — any caller could read or write any user's assessment data in production by setting a header.

Fix

  • Removed the header path entirely; the route is wrapped in requireAuth and identity comes from the authenticated session only (req.user.id).
  • Also migrates off the deprecated getSession({ req }) client call as a side effect of using the shared wrapper.

Verification

  • New regression tests (__tests__/pages/api/user/assessment.test.ts, 4 passing): header is ignored for reads and writes; unauthenticated requests are 401 even with the header; input validation intact.
  • npm run typecheck — pass.

Closes #1169

The assessment API honored an x-dev-user-id header with no environment gate, letting any

caller read or write any user's assessment data in production. Identity now comes from the

authenticated session only via requireAuth; regression tests prove the header is ignored.
@vercel

vercel Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
vets-who-code-app Ready Ready Preview, Comment Jul 18, 2026 7:50pm

Request Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes an authentication bypass on /api/user/assessment by eliminating the x-dev-user-id header path and enforcing that user identity always comes from the authenticated session via the shared requireAuth wrapper (closing #1169).

Changes:

  • Replaced getSession({ req }) + x-dev-user-id header logic with requireAuth and req.user.id-based identity.
  • Added Vitest regression coverage to ensure the header is ignored and unauthenticated requests are rejected.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/pages/api/user/assessment.ts Removes header-based user impersonation and wraps the route in requireAuth to derive identity from the session only.
tests/pages/api/user/assessment.test.ts Adds regression tests proving the header no longer affects reads/writes and unauthenticated calls are rejected.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// Identity comes from the authenticated session ONLY. The old x-dev-user-id
// header bypass let any caller read/write any user's assessment in production.
export default requireAuth(async (req: AuthenticatedRequest, res: NextApiResponse) => {
const userId = req.user?.id as string;
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.

accounts: Remove x-dev-user-id auth bypass from assessment API

2 participants