fix: prevent non-admin users changing another user's gitAccount #1093
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.
Summary
A recent penetration test identified a security issue in the
/api/v1/auth/gitAccountendpoint:Root Cause
The API only checks that the requester is authenticated; it does not verify whether the user is updating their own account or has admin privileges.
Fix
This PR introduces a guard clause that ensures the requesting user is either:
This change brings the backend access control in line with the intended behaviour already enforced in the UI.
I’ve added a new
auth.test.js. I chose not to expand the existingtestLogin.test.jsbecause I wanted to test at a lower level, where I can directly assert that the database is updated as expected.While the current endpoint lives under /auth, updating a user's Git account may conceptually belong on the /user endpoint. However, this change is out of scope for this fix and has been deferred.