Task #2590: Harden User API Write Permissions - #2581
Open
julhoang wants to merge 2 commits into
Open
Conversation
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
julhoang
marked this pull request as ready for review
August 7, 2026 18:30
jlchilders11
approved these changes
Aug 11, 2026
jlchilders11
left a comment
Collaborator
There was a problem hiding this comment.
Looks good to me, thanks for the catch!
ycanales
self-requested a review
August 12, 2026 17:22
Collaborator
|
Reviewed and tested locally. Thanks for this @julhoang ! |
ycanales
approved these changes
Aug 12, 2026
julhoang
force-pushed
the
julia/harden-user-api-endpoints
branch
from
August 14, 2026 18:51
0edfc24 to
054d563
Compare
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.
Issue: #2590
Summary & Context
CustomUserPermissionsgated writes by listingPOST,PUTandDELETEexplicitly, soPATCHfell through to the authenticated-only branch and any logged-in member passed the permission check on another member's record. This PR keys the check onSAFE_METHODSinstead, and adds the tests that were missing on this endpoint.It was not exploitable — a member's
PATCHreturned 200 and wrote nothing, because non-staff callers getUserSerializerand both its fields (id,display_name) are read-only. What changes here is a status code, not a data outcome. The reason to fix it now rather than log it: making any field on that serializer writable — plausible, e.g. to let users rename themselves — would open cross-member edits with nothing failing to signal it.Changes
CustomUserPermissions, keyed onSAFE_METHODSrather than an enumerated list.PATCHis now rejected for non-staff callers where it previously returned 200, and any method added later is gated by default. Read access is unchanged: still authenticated-only.UserViewSetis the only consumer of this permission class./api/v1/users/: list and detail reject anonymous callers, and the serializer switch is pinned in both directions — a member reading another user's record gets exactly{id, display_name}, a staff reader also getsemail,date_joinedandis_staff. That switch is load-bearing for this endpoint's safety and was untested.PUT/PATCH/DELETEon another member's record for anonymous and member callers, plus create for a member — and a staffPATCHtest asserting the write still applies, so widening the gate can't silently take admin writes with it.users/factories.py, which no longer exists, so it could never be uncommented and run; its cases are covered by the real tests above.PATCH.PATCH /api/v1/users/me/, served byCurrentUserAPIViewunderIsAuthenticated, which never goes throughCustomUserPermissions. Grepping templates and JS, that is the only user API path the frontend calls; nothing calls/api/v1/users/<id>/.PATCHstill applies.Peer-Testing Guidelines
developthe same call returns 200 — with no actual change to the record, which is why this went unnoticed./api/v1/users/me/, the path the frontend actually uses.curl -i http://localhost:8000/api/v1/users/returns 403 anonymously, and the same URL in a signed-in browser tab returns the user list.Self-review Checklist
Frontend
N/A
Summary by CodeRabbit
Bug Fixes
Tests