Fix user setting API to use allowlist for updatable fields#14863
Fix user setting API to use allowlist for updatable fields#14863dale053 wants to merge 2 commits into
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PATCH /users/me handler now uses an allowlist (nickname, avatar, language, color_schema, timezone) to build the update payload, logs any other non-password fields that were ignored, and tests were updated to capture and assert the warning and excluded fields. ChangesUser Settings Update Security Fix
Sequence DiagramsequenceDiagram
participant Client
participant UserAPI as PATCH_users_me
participant UserService
participant Database
participant Logger
Client->>UserAPI: PATCH /users/me with request body
UserAPI->>UserAPI: filter request fields using ALLOWED_USER_UPDATE_FIELDS
UserAPI->>UserService: update_by_id(user_id, filtered_update_dict)
UserService->>Database: persist allowed fields
UserAPI->>Logger: warning(user_id, ignored_fields)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@api/apps/restful_apis/user_api.py`:
- Around line 336-339: The loop building update_dict drops unexpected keys
silently; modify the code around ALLOWED_USER_UPDATE_FIELDS / request_data /
update_dict to collect any request_data keys that are not in
ALLOWED_USER_UPDATE_FIELDS and emit an audit log (e.g., using the existing
logger or current_app.logger) containing the ignored field names (not values)
and context (user id or request id if available) at info/warning level so client
misuse or abuse is visible; keep the existing behavior of not including values
and still only adding allowlisted keys to update_dict.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e46a6854-b47c-4b82-a087-24093d601e64
📒 Files selected for processing (1)
api/apps/restful_apis/user_api.py
|
Hi, @JinHai-CN |
What problem does this PR solve?
The
PATCH /users/meendpoint uses a denylist to filter out sensitive fields, which means any new or unexpected fields in the request body are accepted and written to the database by default. This allows users to potentially overwrite protected fields that weren't explicitly blocked.This PR replaces the denylist with an allowlist (
nickname,avatar,language,color_schema,timezone), so only explicitly permitted fields can be updated. This is a safer default — new fields are denied unless intentionally added to the allowlist.Fixes #14861
Type of change