Fix getUserById to omit password and emailHash from response - #926
Open
iamtanuj18 wants to merge 2 commits into
Open
Fix getUserById to omit password and emailHash from response#926iamtanuj18 wants to merge 2 commits into
iamtanuj18 wants to merge 2 commits into
Conversation
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.
Fixes #921.
GET /users/{userId}inapplication/backend/src/controllers/UsersController.tswas returning the raw bcryptpasswordhash andemailHashfields in the response body. Any authenticatedOrganisationAdminorStudyAdmincould retrieve any user's password hash by calling the endpoint with their user id.PR #878 (Constrain User api response) fixed this class of bug for
/users,/users/admin, and/users/admin/deletedby addingomit: { password: true, emailHash: true }to the Prisma queries. On this endpoint it updated the return type fromUsertoUserResponse(=Omit<User, 'password' | 'emailHash'>) but theomitclause itself wasn't added to thefindUniquecall. So the declared response shape didn't match the runtime response.Fix
Add
omit: { password: true, emailHash: true }to thefindUniquecall ingetUserById, matching the pattern the other three endpoints already use.Test repair
The two omit-tests in the
GET /users/:iddescribe block were not hitting the right endpoint. They called/users(list) instead of/users/{userId}, typed the body asGetAllUsersResponse, and assertedbody.data[0]. So they passed regardless of whatgetUserByIddid, which is why #878's own CI didn't catch this leak.Fixed to:
`/users/${userId}`usingTestUsers.PARTICIPANT_UNANSWERED.id, the same fixture the neighbouringshould return a user by IDtest already uses.GetUserByIdResponseand assert onbody.data(single object, not array).Verification
Swagger screenshot attached below.
