Repository navigation
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe ChangesFile-to-Dataset Link Authorization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
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.
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/file2document_api.py (1)
95-121:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAdd audit logs for the new authorization branches.
The new file/KB permission flow returns on multiple auth/validation branches but doesn’t log outcomes. Please add structured logs (at least on authorization failures and successful scheduling) to make this path traceable in production.
As per coding guidelines,
**/*.py: Add logging for new flows.🤖 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/file2document_api.py` around lines 95 - 121, The authorization and validation branches in the file-to-document flow lack audit logging; update the block that calls KnowledgebaseService.get_by_id, FileService.get_all_innermost_file_ids, FileService.get_by_id, check_file_team_permission and check_kb_team_permission to emit structured logs (using the project logger) for: a) lookup failures (e.g., when KnowledgebaseService.get_by_id or FileService.get_by_id returns error) including kb_id/file_id and error context, b) authorization failures from check_file_team_permission and check_kb_team_permission including user_id, resource id and reason, and c) a success/info entry when scheduling/succeeding for each file/kb (include user_id, file_id(s), kb_ids); keep messages concise and use a consistent structured key set (user_id, resource_type, resource_id, action, result).
🧹 Nitpick comments (1)
test/testcases/test_web_api/test_file_app/test_file2document_routes_unit.py (1)
259-269: ⚡ Quick winAssert that executor scheduling does not happen on authorization failures.
These cases validate the response message, but not the critical side effect boundary. Please stub
asyncio.get_running_loop().run_in_executor(or_convert_files) and assert it is not called for unauthorized file/KB paths.🤖 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 `@test/testcases/test_web_api/test_file_app/test_file2document_routes_unit.py` around lines 259 - 269, The tests currently assert the "No authorization." responses but do not verify that background scheduling is suppressed; update the two unauthorized test cases to stub and spy on asyncio.get_running_loop().run_in_executor (or the internal _convert_files) and assert the stub was NOT called when calling module.convert(); specifically patch module._convert_files or monkeypatch asyncio.get_running_loop().run_in_executor before invoking module.convert(), then after each unauthorized-path assertion add an assert that the stubbed run_in_executor/_convert_files call_count (or call) is zero to ensure no executor scheduling occurred in check_file_team_permission/check_kb_team_permission failure scenarios.
🤖 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/file2document_api.py`:
- Around line 95-121: The authorization and validation branches in the
file-to-document flow lack audit logging; update the block that calls
KnowledgebaseService.get_by_id, FileService.get_all_innermost_file_ids,
FileService.get_by_id, check_file_team_permission and check_kb_team_permission
to emit structured logs (using the project logger) for: a) lookup failures
(e.g., when KnowledgebaseService.get_by_id or FileService.get_by_id returns
error) including kb_id/file_id and error context, b) authorization failures from
check_file_team_permission and check_kb_team_permission including user_id,
resource id and reason, and c) a success/info entry when scheduling/succeeding
for each file/kb (include user_id, file_id(s), kb_ids); keep messages concise
and use a consistent structured key set (user_id, resource_type, resource_id,
action, result).
---
Nitpick comments:
In `@test/testcases/test_web_api/test_file_app/test_file2document_routes_unit.py`:
- Around line 259-269: The tests currently assert the "No authorization."
responses but do not verify that background scheduling is suppressed; update the
two unauthorized test cases to stub and spy on
asyncio.get_running_loop().run_in_executor (or the internal _convert_files) and
assert the stub was NOT called when calling module.convert(); specifically patch
module._convert_files or monkeypatch asyncio.get_running_loop().run_in_executor
before invoking module.convert(), then after each unauthorized-path assertion
add an assert that the stubbed run_in_executor/_convert_files call_count (or
call) is zero to ensure no executor scheduling occurred in
check_file_team_permission/check_kb_team_permission failure scenarios.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a1ac7019-00e8-45b4-af8d-6a573f1007fe
📒 Files selected for processing (2)
api/apps/restful_apis/file2document_api.pytest/testcases/test_web_api/test_file_app/test_file2document_routes_unit.py
|
@coderabbitai |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 8993
✅ What looks good
🔍 Minor observations (non-blocking)
These are all minor polish items. The core implementation — authorization checks with structured audit logs — is solid. The test suite also correctly stubs |
|
LGTM. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #14649 +/- ##
==========================================
- Coverage 95.59% 94.16% -1.43%
==========================================
Files 10 10
Lines 703 703
Branches 112 112
==========================================
- Hits 672 662 -10
- Misses 21 25 +4
- Partials 10 16 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…iflow#14649) ### Related issues Closes infiniflow#14648 ### What problem does this PR solve? This PR fixes an authorization flaw in `POST /files/link-to-datasets`. Before this change, the endpoint only checked whether the supplied `file_ids` and `kb_ids` existed. It did not verify whether the authenticated user was actually allowed to access those files or target datasets. As a result, an authenticated user who knew valid IDs could relink another user's files to arbitrary datasets. This was especially risky because the relinking flow is state-changing: the background worker removes existing file-document mappings and then recreates documents under the attacker-supplied dataset IDs. This change makes the route enforce the same permission model already used by nearby file and document operations: - each resolved file must pass `check_file_team_permission(...)` - each target dataset must pass `check_kb_team_permission(...)` - authorization is enforced before scheduling background relinking work ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [ ] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe): ### Testing - Added regression coverage in `test/testcases/test_web_api/test_file_app/test_file2document_routes_unit.py` - Covered: - unauthorized file access is rejected - unauthorized dataset access is rejected - existing success path still returns immediately after scheduling background work - Attempted to run: - `python -m pytest test\\testcases\\test_web_api\\test_file_app\\test_file2document_routes_unit.py -q` - Local execution in this workspace is currently blocked by missing test dependencies during bootstrap, including `ragflow_sdk` --------- Co-authored-by: jony376 <[email protected]>
…iflow#14649) ### Related issues Closes infiniflow#14648 ### What problem does this PR solve? This PR fixes an authorization flaw in `POST /files/link-to-datasets`. Before this change, the endpoint only checked whether the supplied `file_ids` and `kb_ids` existed. It did not verify whether the authenticated user was actually allowed to access those files or target datasets. As a result, an authenticated user who knew valid IDs could relink another user's files to arbitrary datasets. This was especially risky because the relinking flow is state-changing: the background worker removes existing file-document mappings and then recreates documents under the attacker-supplied dataset IDs. This change makes the route enforce the same permission model already used by nearby file and document operations: - each resolved file must pass `check_file_team_permission(...)` - each target dataset must pass `check_kb_team_permission(...)` - authorization is enforced before scheduling background relinking work ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [ ] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe): ### Testing - Added regression coverage in `test/testcases/test_web_api/test_file_app/test_file2document_routes_unit.py` - Covered: - unauthorized file access is rejected - unauthorized dataset access is rejected - existing success path still returns immediately after scheduling background work - Attempted to run: - `python -m pytest test\\testcases\\test_web_api\\test_file_app\\test_file2document_routes_unit.py -q` - Local execution in this workspace is currently blocked by missing test dependencies during bootstrap, including `ragflow_sdk` --------- Co-authored-by: jony376 <[email protected]>
Related issues
Closes #14648
What problem does this PR solve?
This PR fixes an authorization flaw in
POST /files/link-to-datasets.Before this change, the endpoint only checked whether the supplied
file_idsandkb_idsexisted. It did not verify whether the authenticated user was actually allowed to access those files or target datasets. As a result, an authenticated user who knew valid IDs could relink another user's files to arbitrary datasets.This was especially risky because the relinking flow is state-changing: the background worker removes existing file-document mappings and then recreates documents under the attacker-supplied dataset IDs.
This change makes the route enforce the same permission model already used by nearby file and document operations:
check_file_team_permission(...)check_kb_team_permission(...)Type of change
Testing
test/testcases/test_web_api/test_file_app/test_file2document_routes_unit.pypython -m pytest test\\testcases\\test_web_api\\test_file_app\\test_file2document_routes_unit.py -qragflow_sdk