Skip to content

Fix user setting API to use allowlist for updatable fields - #14863

Merged
KevinHuSh merged 8 commits into
infiniflow:mainfrom
dale053:fix/14861-patch-users-me-allowlist
May 21, 2026
Merged

KevinHuSh merged 8 commits into
infiniflow:mainfrom
dale053:fix/14861-patch-users-me-allowlist

Conversation

@dale053

@dale053 dale053 commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

The PATCH /users/me endpoint 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

  • Bug Fix (non-breaking change which fixes an issue)

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 12, 2026
@coderabbitai

coderabbitai Bot commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Failed to post review comments

📝 Walkthrough

Walkthrough

PATCH /users/me now uses an explicit allowlist (nickname, avatar, language, color_schema, timezone) to build the update payload; unsupported non-password fields are collected and logged as a warning. Tests were updated to capture and assert the emitted warning and excluded fields; docs add a sandbox settings screenshot and a Provider options subsection.

Changes

User Settings Update Security Fix

Layer / File(s) Summary
Allowlist-based user field update
api/apps/restful_apis/user_api.py
setting_user constructs update_dict from an explicit allowlist of safe fields, collects unsupported non-password keys into ignored_fields, logs a warning containing the current user id and sorted ignored fields, then calls UserService.update_by_id with the filtered payload.
Tests capture audit warnings and assert excluded fields
test/testcases/test_web_api/test_user_app/test_user_app_unit.py, test/testcases/restful_api/test_user_tenant_routes_unit.py
Unit tests monkeypatch logging.warning to collect calls, assert update_by_id is called without theme, email, and status, and verify the logged warning includes the current user id and the omitted-field list.

Docs: Sandbox Quickstart

Layer / File(s) Summary
Sandbox quickstart screenshot and Provider options subsection
docs/guides/agent/agent_quickstarts/sandbox_quickstart.md
Inserted Admin > Sandbox Settings screenshot and added an earlier “Provider options” subsection with a lead-in sentence telling users to configure the active provider after sandbox services are running.
sequenceDiagram
  participant Client
  participant PATCH_users_me as UserAPI
  participant UserService
  participant Database
  participant Logger

  Client->>PATCH_users_me: PATCH /users/me with request body
  PATCH_users_me->>PATCH_users_me: filter request fields using allowlist
  PATCH_users_me->>UserService: update_by_id(user_id, filtered_update_dict)
  UserService->>Database: persist allowed fields
  PATCH_users_me->>Logger: warning(user_id, ignored_fields)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

📖 documentation, 🌈 python, size:L

Poem

🐰 I hop through code with tidy paws,

Only safe keys get through my laws.
Warnings logged for fields unkind,
Tests now catch what I designed.
Safe updates bloom — secure and fine.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Out of Scope Changes check ❓ Inconclusive The documentation changes to sandbox_quickstart.md appear unrelated to the allowlist security fix for the user settings API and may be out of scope. Verify whether the documentation update is necessary for this PR or should be separated into a distinct pull request focused on documentation changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: switching from a blocklist to an allowlist approach for the user settings API.
Description check ✅ Passed The description comprehensively addresses the problem, explains the solution, and correctly indicates the type of change as a bug fix.
Linked Issues check ✅ Passed The changes directly address all coding requirements from #14861: implementing an allowlist approach with permitted fields (nickname, avatar, language, color_schema, timezone) and logging ignored fields.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5e46457 and 51f69d2.

📒 Files selected for processing (1)
  • api/apps/restful_apis/user_api.py

Comment thread api/apps/restful_apis/user_api.py Resolved
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels May 13, 2026
@dale053

dale053 commented May 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi, @JinHai-CN
When you have a moment, could you please review this PR?

@KevinHuSh KevinHuSh added the ci Continue Integration label May 19, 2026
@KevinHuSh
KevinHuSh marked this pull request as draft May 19, 2026 08:04
@KevinHuSh
KevinHuSh marked this pull request as ready for review May 19, 2026 08:04
@codecov

codecov Bot commented May 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.12%. Comparing base (b28e134) to head (158ec94).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14863   +/-   ##
=======================================
  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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KevinHuSh

Copy link
Copy Markdown
Contributor

Appreciations!

CI failure.

=================================== FAILURES ===================================
___________________ test_logout_setting_profile_matrix_unit ____________________
test/testcases/restful_api/test_user_tenant_routes_unit.py:1005: in test_logout_setting_profile_matrix_unit
    assert update_calls["payload"]["theme"] == "dark"
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E   KeyError: 'theme'
------------------------------ Captured log call -------------------------------
WARNING  root:user_api.py:346 Ignoring unsupported fields in PATCH /users/me. user_id=current-user fields=['email', 'status', 'theme']

Magicbook1108 and others added 4 commits May 19, 2026 17:36
### What problem does this PR solve?

This PR improves the connector dashboard task management experience and
adds better visibility into connector execution logs.

### Overview:

<img width="700" alt="image"
src="https://github.com/user-attachments/assets/0e643433-878e-44f7-9b98-5b8217be5e19"
/>

### 1. Support hot switching during agent runs and complete log updates

Supports switching providers during an agent run, for example:

local provider -> self-managed provider -> local provider

<img width="700" alt="image"
src="https://github.com/user-attachments/assets/bc52fc77-e44b-415d-b5c9-0e035f9a2cee"
/>

### 2. Support SSH provider

<img width="700" alt="image"
src="https://github.com/user-attachments/assets/d3039f7a-df71-4e07-9120-5748f36ece64"
/>

### 3. Support local provider

<img width="700" alt="image"
src="https://github.com/user-attachments/assets/d5d1b170-8d45-4da4-afa3-957bb69557b8"
/>

### 4. Expose self-managed deployment defaults

Self-managed deployment defaults are now visible to users and can be
customized in `docker/.env`.

These values are kept as deployment defaults because changes require a
hard restart to take effect.

<img width="700" alt="image"
src="https://github.com/user-attachments/assets/05923610-e083-4f1c-bef9-4db90ad131b8"
/>

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
…reak RAPTOR (infiniflow#14998)

### What problem does this PR solve?

Fixes infiniflow#14997.

RAPTOR builds on the Infinity backend have been broken since v0.25.2
introduced the `extra` field in code (`rag/svr/task_executor.py:1011`)
without declaring it in `conf/infinity_mapping.json`. Every RAPTOR job
fails with:

```
infinity.common.InfinityException: (3013, 'Fail to bind the expression: extra@src/planner/expression_binder_impl.cpp:99')
```

The auto-migration in
`common/doc_store/infinity_conn_base.py:_migrate_db()` adds any columns
it finds in the mapping JSON to existing tables — so the only thing
standing between users and a working RAPTOR build is that one missing
declaration. OceanBase, ES, and OpenSearch were unaffected because they
store `extra` as a native JSON type; only Infinity (which has a strict
`varchar`/`integer`/`float` schema) needed the addition.

### The fix

Two-part change:

1. **`conf/infinity_mapping.json`**: declare `"extra": {"type":
"varchar", "default": ""}`. On next startup, `_migrate_db()` adds the
column to all existing chunk tables — no manual DDL needed for upgrading
installations.
2. **`rag/utils/infinity_conn.py` `insert()`**: serialize the `extra`
dict to a JSON string at write time, since Infinity's `varchar` can't
store a Python dict directly. Modelled on the existing `chunk_data`
handling a few lines above.

The read path (`rag/utils/raptor_utils.py:_as_extra_dict`) already
normalises both dict and JSON-string inputs, so no read-side change is
needed. Other backends are untouched — `task_executor.py` still writes
the dict, and the OceanBase/ES/OpenSearch insert paths handle dicts
natively.

### Verification

Tested on a v0.25.4 deployment with the Infinity backend by applying the
same two changes via mounted-volume override:

- Confirmed `_migrate_db()` adds the `extra` column to all pre-existing
chunk tables on startup (column visible via Infinity's
`show_columns()`).
- Triggered RAPTOR builds on four datasets (~21k chunks total) via `POST
/api/v1/datasets/<id>/index?type=raptor`.
- All four progressed past the previously-failing
`get_raptor_chunk_methods()` call into actual entity-extraction and
clustering work without the (3013) error.
- GraphRAG builds (which can trigger the same path indirectly via
`task_executor.py:857`) also progressed cleanly.

### Type of change

- [X] Bug Fix (non-breaking change which fixes an issue)
@dale053

dale053 commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

Hi, @KevinHuSh
All checks have passed! could you please review this PR?

@KevinHuSh
KevinHuSh merged commit 39c1b3a into infiniflow:main May 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: PATCH /users/me blocklist bypass allows arbitrary User model field overwrites (privilege escalation)

4 participants