mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-27 10:52:03 +08:00
fix(agent): enforce document access on POST /api/v1/agents/rerun (#15145)
## Related issues Closes #15144 ### What problem does this PR solve? `POST /api/v1/agents/rerun` loaded a pipeline operation log by UUID via `PipelineOperationLogService.get_documents_info` with no authorization, then wiped chunks, reset document counters, deleted tasks, and re-queued dataflow for the victim document. Any authenticated user who knew a victim's pipeline log id could disrupt parsing on documents they did not own. ### 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): ### Changes | File | Change | |------|--------| | `api/apps/restful_apis/agent_api.py` | Call `DocumentService.accessible(doc["id"], tenant_id)` before destructive rerun operations; deny with generic `"Document not found."` | | `test/unit_test/api/apps/restful_apis/test_rerun_agent_authorization.py` | Unit tests: cross-tenant log rejected, missing/unauthorized same message, authorized rerun proceeds | ### Security notes - **CWE-639:** Closes cross-tenant pipeline rerun / chunk wipe via leaked log UUID. - `tenant_id` from `@add_tenant_id_to_kwargs` is `current_user.id`; `DocumentService.accessible` covers team-shared KBs. ### Test plan - [ ] `pytest test/unit_test/api/apps/restful_apis/test_rerun_agent_authorization.py` - [ ] Manual: attacker cannot rerun victim pipeline log id ```bash cd ragflow uv run pytest test/unit_test/api/apps/restful_apis/test_rerun_agent_authorization.py -q ``` --------- Co-authored-by: Zhichang Yu <yuzhichang@gmail.com>
This commit is contained in:
@@ -14,6 +14,10 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
|
||||
from common.file_utils import get_project_base_directory
|
||||
from common.token_utils import num_tokens_from_string, total_token_count_from_response, truncate, encoder
|
||||
import pytest
|
||||
|
||||
@@ -112,6 +116,12 @@ def test_consistency():
|
||||
assert first_result > 0
|
||||
|
||||
|
||||
def test_bundled_cl100k_cache_file_exists():
|
||||
encoding_url = "https://openaipublic.blob.core.windows.net/encodings/cl100k_base.tiktoken"
|
||||
cache_path = get_project_base_directory(hashlib.sha1(encoding_url.encode()).hexdigest())
|
||||
assert os.path.exists(cache_path)
|
||||
|
||||
|
||||
class TestTotalTokenCountFromResponse:
|
||||
"""Test cases for total_token_count_from_response function"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user