Skip to content

fix: sanitize user API responses#402

Open
akshayad2006-cmd wants to merge 2 commits into
MRIARC-08:mainfrom
akshayad2006-cmd:fix/safe-user-dto
Open

fix: sanitize user API responses#402
akshayad2006-cmd wants to merge 2 commits into
MRIARC-08:mainfrom
akshayad2006-cmd:fix/safe-user-dto

Conversation

@akshayad2006-cmd

@akshayad2006-cmd akshayad2006-cmd commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Description

Authentication and profile endpoints were returning complete Prisma User records, which exposed sensitive information such as password hashes and internal account fields to clients.
This change introduces a consistent public user contract and ensures that only fields required by the frontend are returned from register, login, OAuth, and profile endpoints.
Changes Made

  • Added a shared PUBLIC_USER_SELECT for user responses.
  • Updated auth repository methods to avoid exposing complete user records.
  • Sanitized register, login, and Google OAuth responses.
  • Updated profile retrieval to use explicit field selection instead of returning full records.
  • Preserved required frontend fields such as class, image, and stats.
  • Ensured password hashes are used only for server-side verification and never returned in API responses.
  • Maintained existing redirect and profile rendering behavior.
  • Verified the project with a successful production build.

Impact
Before

  • Full Prisma User objects were serialized.
  • Password hashes and unnecessary internal fields could reach the client.

After

  • Password hashes remain server-side.
  • Auth and profile endpoints expose only the fields required by the frontend.
  • A consistent sanitized user contract is used across responses.

Files Modified

  • src/modules/auth/auth.repository.ts
  • src/modules/auth/auth.service.ts
  • src/modules/user/user.repository.ts
  • src/modules/user/user.select.ts
  • src/modules/user/dto/public-user.dto.ts

Related issue
Fixes #323

@vercel

vercel Bot commented Jun 18, 2026

Copy link
Copy Markdown

@akshayad2006-cmd is attempting to deploy a commit to the Adarsh's projects Team on Vercel.

A member of the Team first needs to authorize it.

@MRIARC-08 MRIARC-08 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@akshayad2006-cmd I can’t merge this version. Sanitizing user responses is the right goal, but the PR changes auth behavior while doing it.

Local check:

  • pnpm test fails in src/modules/auth/auth.service.test.ts because access tokens now get hard-coded role: "USER" and isProfileCompleted: false instead of using the real user role/profile state.

  • The response DTO/select layer should remove sensitive fields from API responses, but it should not change token claims or login/register/refresh behavior.

  • Please also remove the unrelated pnpm-lock.yaml churn unless a dependency actually changed.Keep the public user shape, but preserve user.role and user.firstTime/profile-completion values where the auth service builds tokens.

@akshayad2006-cmd

Copy link
Copy Markdown
Contributor Author

Hi @MRIARC-08
Thanks for the review. I updated the PR to preserve existing auth behavior while keeping responses sanitized.

Token claims now use the real user role and firstTime/profile-completion values instead of hardcoded values. I also updated the auth service tests to assert sanitized user responses without password exposure.

Verified with:

  • pnpm test src/modules/auth/auth.service.test.ts
  • npm run build

@MRIARC-08 MRIARC-08 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@akshayad2006-cmd Good progress: the auth service test regression is fixed now.

Local checks from my side:

  • pnpm test src/modules/auth/auth.service.test.ts passes.
  • pnpm exec tsc --noEmit passes.
  • Focused ESLint still fails on Prettier issues in the touched auth/user files, plus one unused password destructure warning in src/modules/user/user.repository.ts.

Main blocker: the PR still changes pnpm-lock.yaml unrelated to this auth sanitization work and removes the security override section from the lockfile. Please restore the lockfile to current main unless this PR intentionally changes dependencies, which it should not.

After that, run the formatter on the touched files and remove the unused destructure warning. No broader rewrite needed.

@MRIARC-08 MRIARC-08 added gssoc gssoc level:intermediate GSSoC difficulty: intermediate type:security Security related contribution labels Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc gssoc level:intermediate GSSoC difficulty: intermediate type:security Security related contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SECURITY] Auth and profile APIs expose password hashes in user responses

2 participants