Repository navigation
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughUser model now filters sensitive fields (password, access_token, email) via to_safe_dict(for_self=True); login, OAuth-init, logout, profile, registration, and password-reset endpoints now return filtered user dicts and emit additional auth-related logs. ChangesSecure User Data Serialization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
api/apps/restful_apis/user_api.py (1)
64-840:⚠️ Potential issue | 🟠 MajorAdd logging to critical authentication endpoints.
The reviewed code properly uses
to_safe_dict()for all user serialization in API responses, correctly filteringpasswordandaccess_tokenfields. However, three critical authentication endpoints lack logging statements, violating the guideline to "Add logging for new flows":
login()(lines 64–131): No logging for login success or failureoauth_login()(lines 160–177): No logging for OAuth flow initiationlog_out()(lines 280–289): No logging for logout operationsAdd
logging.info()orlogging.warning()calls to these endpoints to track authentication events, especially for failed attempts and user state changes.🤖 Prompt for 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. In `@api/apps/restful_apis/user_api.py` around lines 64 - 840, The three auth endpoints (login, oauth_login, log_out) lack audit logging; add appropriate logging calls: in login() log failed login attempts (invalid JSON, unregistered email, failed decryption, wrong credentials) and successful logins with user id/email using logging.warning or logging.info; in oauth_login(channel) log initiation of OAuth flow including channel and generated state; in log_out() log the user id/email and that their access_token was invalidated (use logging.info). Place logs near the error/return points and after state changes (e.g., after setting access_token, after login_user/logout_user) in the login, oauth_login, and log_out functions respectively.
🧹 Nitpick comments (1)
api/apps/restful_apis/user_api.py (1)
131-131: 💤 Low valueConsider adding logging for security audit trail.
While the security fix is correctly implemented, consider adding logging when user data is serialized for API responses. This would create an audit trail showing when and where user data is accessed, which is valuable for security monitoring and compliance.
Example approach:
def to_safe_dict(self): result = {k: v for k, v in self.to_dict().items() if k not in self.SENSITIVE_FIELDS} logging.debug(f"User {self.id} serialized safely, filtered fields: {self.SENSITIVE_FIELDS}") return resultAs per coding guidelines, new flows should include logging. While this is a data method rather than a flow, security-related operations typically benefit from audit logging.
Also applies to: 385-385, 530-530, 839-839
🤖 Prompt for 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. In `@api/apps/restful_apis/user_api.py` at line 131, Add audit logging when user data is serialized for API responses: update the user.to_safe_dict implementation (and any places that call it such as the response construction in construct_response where user.to_safe_dict() and user.get_id() are used) to emit an appropriate log entry (e.g., logging.info or logging.debug) that records the user id, the API endpoint context (or function name), and a non-sensitive summary of filtered fields; ensure the log message does not include sensitive values, uses the existing logging facility, and is added consistently for other occurrences noted (lines calling user.to_safe_dict at locations referenced).
🤖 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.
Outside diff comments:
In `@api/apps/restful_apis/user_api.py`:
- Around line 64-840: The three auth endpoints (login, oauth_login, log_out)
lack audit logging; add appropriate logging calls: in login() log failed login
attempts (invalid JSON, unregistered email, failed decryption, wrong
credentials) and successful logins with user id/email using logging.warning or
logging.info; in oauth_login(channel) log initiation of OAuth flow including
channel and generated state; in log_out() log the user id/email and that their
access_token was invalidated (use logging.info). Place logs near the
error/return points and after state changes (e.g., after setting access_token,
after login_user/logout_user) in the login, oauth_login, and log_out functions
respectively.
---
Nitpick comments:
In `@api/apps/restful_apis/user_api.py`:
- Line 131: Add audit logging when user data is serialized for API responses:
update the user.to_safe_dict implementation (and any places that call it such as
the response construction in construct_response where user.to_safe_dict() and
user.get_id() are used) to emit an appropriate log entry (e.g., logging.info or
logging.debug) that records the user id, the API endpoint context (or function
name), and a non-sensitive summary of filtered fields; ensure the log message
does not include sensitive values, uses the existing logging facility, and is
added consistently for other occurrences noted (lines calling user.to_safe_dict
at locations referenced).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b42d3db7-3312-4a35-80a8-97a5c3723931
📒 Files selected for processing (2)
api/apps/restful_apis/user_api.pyapi/db/db_models.py
|
Hi, @wangq8 |
|
@dale053 I finished my review, please have a check. |
|
Hi, @wangq8,@KevinHuSh |
|
Hi, @wangq8 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14792 +/- ##
=======================================
Coverage 93.12% 93.12%
=======================================
Files 10 10
Lines 713 713
Branches 116 116
=======================================
Hits 664 664
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
CI failure. |
|
Hi, @JinHai-CN |
|
Hi,@KevinHuSh |
…tive fields The regular login() path and every other user-data response in this file use user.to_safe_dict(for_self=True), per the infiniflow#14792 hardening that keeps sensitive columns out of API responses. ldap_login() still built its response with user.to_json(), so a successful LDAP login leaked those fields. Align it with the rest of the file. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…tive fields The regular login() path and every other user-data response in this file use user.to_safe_dict(for_self=True), per the infiniflow#14792 hardening that keeps sensitive columns out of API responses. ldap_login() still built its response with user.to_json(), so a successful LDAP login leaked those fields. Align it with the rest of the file.
Closes #14789
What problem does this PR solve?
User API endpoints (
login,user_profile,user_add,forget_reset_password) were returning full user objects viato_json()/to_dict(), which included sensitive fields likepasswordandaccess_tokenin the response body. This leaks credentials to the client.This PR adds a
to_safe_dict()method on theUsermodel that strips sensitive fields (password,access_token) and replaces all affected call sites to use it.Type of change