Repository navigation
fix(agent): enforce document access on POST /api/v1/agents/rerun - #15145
Conversation
…estructive document rerun operations
|
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:
📝 WalkthroughWalkthroughThis PR adds a tenant accessibility check to ChangesRerun Agent Authorization Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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.
🧹 Nitpick comments (1)
api/apps/restful_apis/agent_api.py (1)
949-950: ⚡ Quick winAdd audit logging for the new authorization deny branch.
The generic error response is correct, but this new security path should log denied rerun attempts (tenant + doc/log context) for incident triage.
Proposed change
doc = doc[0] if not DocumentService.accessible(doc["id"], tenant_id): + logging.warning( + "rerun_agent denied: tenant_id=%s log_id=%s doc_id=%s", + tenant_id, + req.get("id"), + doc.get("id"), + ) return get_data_error_result(message="Document not found.")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/agent_api.py` around lines 949 - 950, The new authorization-deny branch that returns get_data_error_result needs audit logging: inside the if block that checks DocumentService.accessible(doc["id"], tenant_id) add a structured audit log (using the module logger) recording the denied action (e.g., "document rerun denied"), the tenant_id and doc["id"], and any available request/context identifier (user id or request id) so incident triage can correlate events; ensure the log level is appropriate for audits (info/warn) and keep the existing return behavior.
🤖 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.
Nitpick comments:
In `@api/apps/restful_apis/agent_api.py`:
- Around line 949-950: The new authorization-deny branch that returns
get_data_error_result needs audit logging: inside the if block that checks
DocumentService.accessible(doc["id"], tenant_id) add a structured audit log
(using the module logger) recording the denied action (e.g., "document rerun
denied"), the tenant_id and doc["id"], and any available request/context
identifier (user id or request id) so incident triage can correlate events;
ensure the log level is appropriate for audits (info/warn) and keep the existing
return behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 16acee75-756f-4c95-81f0-03a3e8b6bd5b
📒 Files selected for processing (2)
api/apps/restful_apis/agent_api.pytest/unit_test/api/apps/restful_apis/test_rerun_agent_authorization.py
|
Hi @wangq8 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
api/apps/restful_apis/agent_api.py (1)
1048-1049: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick winLog denied rerun attempts on this new auth branch.
This adds a new authorization failure path on a destructive endpoint, but the denial is silent server-side. Please keep the generic
"Document not found."response, but log the tenant/document context before returning so cross-tenant probes are observable. 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/agent_api.py` around lines 1048 - 1049, The new authorization failure path in the destructive document flow is returning a generic response without any server-side trace. In the branch that checks DocumentService.accessible inside the agent API handler, keep the existing "Document not found." result but add a log entry before returning, including the tenant_id and document id so denied cross-tenant rerun attempts are observable. Use the surrounding handler logic and the DocumentService.accessible check to place the log in the new auth branch.Source: Coding guidelines
🤖 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/agent_api.py`:
- Line 377: The direct calls to validate_rest_api_page_size in the agent API
request handlers are letting ValueError escape and turn bad page_size query
params into 500s. Update the affected request flows in agent_api (including the
code paths that use items_per_page/page_size) to catch validation failures and
convert them into a structured client error response, using the existing
request-handling error pattern in this module so malformed or oversized
page_size values return a 4xx instead of bubbling up.
---
Nitpick comments:
In `@api/apps/restful_apis/agent_api.py`:
- Around line 1048-1049: The new authorization failure path in the destructive
document flow is returning a generic response without any server-side trace. In
the branch that checks DocumentService.accessible inside the agent API handler,
keep the existing "Document not found." result but add a log entry before
returning, including the tenant_id and document id so denied cross-tenant rerun
attempts are observable. Use the surrounding handler logic and the
DocumentService.accessible check to place the log in the new auth branch.
🪄 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: d23a369e-ea6e-454b-8425-db96fdd1b1b4
📒 Files selected for processing (1)
api/apps/restful_apis/agent_api.py
There was a problem hiding this comment.
Caution
Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.
Actionable comments posted: 1
🧹 Nitpick comments (1)
api/apps/restful_apis/agent_api.py (1)
1048-1049: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick winLog denied rerun attempts on this new auth branch.
This adds a new authorization failure path on a destructive endpoint, but the denial is silent server-side. Please keep the generic
"Document not found."response, but log the tenant/document context before returning so cross-tenant probes are observable. 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/agent_api.py` around lines 1048 - 1049, The new authorization failure path in the destructive document flow is returning a generic response without any server-side trace. In the branch that checks DocumentService.accessible inside the agent API handler, keep the existing "Document not found." result but add a log entry before returning, including the tenant_id and document id so denied cross-tenant rerun attempts are observable. Use the surrounding handler logic and the DocumentService.accessible check to place the log in the new auth branch.Source: Coding guidelines
🤖 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/agent_api.py`:
- Line 377: The direct calls to validate_rest_api_page_size in the agent API
request handlers are letting ValueError escape and turn bad page_size query
params into 500s. Update the affected request flows in agent_api (including the
code paths that use items_per_page/page_size) to catch validation failures and
convert them into a structured client error response, using the existing
request-handling error pattern in this module so malformed or oversized
page_size values return a 4xx instead of bubbling up.
---
Nitpick comments:
In `@api/apps/restful_apis/agent_api.py`:
- Around line 1048-1049: The new authorization failure path in the destructive
document flow is returning a generic response without any server-side trace. In
the branch that checks DocumentService.accessible inside the agent API handler,
keep the existing "Document not found." result but add a log entry before
returning, including the tenant_id and document id so denied cross-tenant rerun
attempts are observable. Use the surrounding handler logic and the
DocumentService.accessible check to place the log in the new auth branch.
🪄 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: d23a369e-ea6e-454b-8425-db96fdd1b1b4
📒 Files selected for processing (1)
api/apps/restful_apis/agent_api.py
🛑 Comments failed to post (1)
api/apps/restful_apis/agent_api.py (1)
377-377: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Handle
page_sizevalidation failures as request errors.Line 377 and Line 600 call
validate_rest_api_page_size(...)directly. That helper raisesValueError, so an oversized or malformedpage_sizenow turns a bad query string into an HTTP 500 instead of a structured 4xx response.Also applies to: 600-600
🤖 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/agent_api.py` at line 377, The direct calls to validate_rest_api_page_size in the agent API request handlers are letting ValueError escape and turn bad page_size query params into 500s. Update the affected request flows in agent_api (including the code paths that use items_per_page/page_size) to catch validation failures and convert them into a structured client error response, using the existing request-handling error pattern in this module so malformed or oversized page_size values return a 4xx instead of bubbling up.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15145 +/- ##
==========================================
- Coverage 94.56% 93.16% -1.40%
==========================================
Files 10 10
Lines 717 717
Branches 118 118
==========================================
- Hits 678 668 -10
- Misses 25 29 +4
- Partials 14 20 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
) ## 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 <[email protected]>
Ports 4 M-effort PRs from .claude/plans/review-and-port-py-agent-changes.md Execution snapshot (all merged upstream) to the Go agent side. Group 4 - API auth ports - infiniflow#16169 Sandbox artifact ownership: add UserCanvasDAO.Accessible (owner-or-team predicate) and DocumentService.sandboxArtifactAccessible to gate GET /api/v1/documents/artifact/<filename>. Query API4Conversation for sessions owned by userID whose message blob references the filename (or its documents/artifact/<name> URL form); require at least one accessible canvas. Handler now fetches the current user and passes userID into the service; denial returns ErrArtifactNotFound to avoid cross-user enumeration. - infiniflow#15457 Tenant ownership on agentbots: Go side already had the loadCanvas IDOR guard at the entry of both AgentbotInputs and AgentbotCompletion. Added a cross-tenant regression test (tenant-B asks for tenant-A's canvas -> ErrUserCanvasNotFound). - infiniflow#15145 Rerun agent document access: add DocumentService.Accessible (loads doc, checks kbDAO.Accessible). Wire documentService into AgentHandler via WithDocumentService (nil-tolerant, preserves the existing NewAgentHandler signature for tests). RerunAgent returns "Document not found." when accessible check fails; cmd/server_main.go wires documentService after construction. Group 2 - thinking switch - infiniflow#15446 component portion: add Thinking field to LLMParam, LLMInput, and ChatInvokeRequest. mergeLLMParam reads inputs["thinking"] with a whitelist of {"enabled","disabled"} (matching python llm.py:78-79); arbitrary strings are rejected. The provider policy portion (Qwen/Kimi/GLM in rag/llm/chat_model.py) belongs to internal/llm/ and is a separate porting stream. Total: 4 new tests across 3 modified test files. All touched package tests pass (1697 + 4 skipped). The 1 failing test (TestAgent_ReActExhaustsSteps) is the pre-existing flaky test that also fails on the baseline without my changes. Refs: .claude/plans/review-and-port-py-agent-changes.md Refs: infiniflow#16169 infiniflow#15457 infiniflow#15145 infiniflow#15446
Ports 4 M-effort PRs from .claude/plans/review-and-port-py-agent-changes.md Execution snapshot (all merged upstream) to the Go agent side. Group 4 - API auth ports - infiniflow#16169 Sandbox artifact ownership: add UserCanvasDAO.Accessible (owner-or-team predicate) and DocumentService.sandboxArtifactAccessible to gate GET /api/v1/documents/artifact/<filename>. Query API4Conversation for sessions owned by userID whose message blob references the filename (or its documents/artifact/<name> URL form); require at least one accessible canvas. Handler now fetches the current user and passes userID into the service; denial returns ErrArtifactNotFound to avoid cross-user enumeration. - infiniflow#15457 Tenant ownership on agentbots: Go side already had the loadCanvas IDOR guard at the entry of both AgentbotInputs and AgentbotCompletion. Added a cross-tenant regression test (tenant-B asks for tenant-A's canvas -> ErrUserCanvasNotFound). - infiniflow#15145 Rerun agent document access: add DocumentService.Accessible (loads doc, checks kbDAO.Accessible). Wire documentService into AgentHandler via WithDocumentService (nil-tolerant, preserves the existing NewAgentHandler signature for tests). RerunAgent returns "Document not found." when accessible check fails; cmd/server_main.go wires documentService after construction. Group 2 - thinking switch - infiniflow#15446 component portion: add Thinking field to LLMParam, LLMInput, and ChatInvokeRequest. mergeLLMParam reads inputs["thinking"] with a whitelist of {"enabled","disabled"} (matching python llm.py:78-79); arbitrary strings are rejected. The provider policy portion (Qwen/Kimi/GLM in rag/llm/chat_model.py) belongs to internal/llm/ and is a separate porting stream. Total: 4 new tests across 3 modified test files. All touched package tests pass (1697 + 4 skipped). The 1 failing test (TestAgent_ReActExhaustsSteps) is the pre-existing flaky test that also fails on the baseline without my changes. Refs: .claude/plans/review-and-port-py-agent-changes.md Refs: infiniflow#16169 infiniflow#15457 infiniflow#15145 infiniflow#15446
Ports 4 M-effort PRs from .claude/plans/review-and-port-py-agent-changes.md Execution snapshot (all merged upstream) to the Go agent side. Group 4 - API auth ports - infiniflow#16169 Sandbox artifact ownership: add UserCanvasDAO.Accessible (owner-or-team predicate) and DocumentService.sandboxArtifactAccessible to gate GET /api/v1/documents/artifact/<filename>. Query API4Conversation for sessions owned by userID whose message blob references the filename (or its documents/artifact/<name> URL form); require at least one accessible canvas. Handler now fetches the current user and passes userID into the service; denial returns ErrArtifactNotFound to avoid cross-user enumeration. - infiniflow#15457 Tenant ownership on agentbots: Go side already had the loadCanvas IDOR guard at the entry of both AgentbotInputs and AgentbotCompletion. Added a cross-tenant regression test (tenant-B asks for tenant-A's canvas -> ErrUserCanvasNotFound). - infiniflow#15145 Rerun agent document access: add DocumentService.Accessible (loads doc, checks kbDAO.Accessible). Wire documentService into AgentHandler via WithDocumentService (nil-tolerant, preserves the existing NewAgentHandler signature for tests). RerunAgent returns "Document not found." when accessible check fails; cmd/server_main.go wires documentService after construction. Group 2 - thinking switch - infiniflow#15446 component portion: add Thinking field to LLMParam, LLMInput, and ChatInvokeRequest. mergeLLMParam reads inputs["thinking"] with a whitelist of {"enabled","disabled"} (matching python llm.py:78-79); arbitrary strings are rejected. The provider policy portion (Qwen/Kimi/GLM in rag/llm/chat_model.py) belongs to internal/llm/ and is a separate porting stream. Total: 4 new tests across 3 modified test files. All touched package tests pass (1697 + 4 skipped). The 1 failing test (TestAgent_ReActExhaustsSteps) is the pre-existing flaky test that also fails on the baseline without my changes. Refs: .claude/plans/review-and-port-py-agent-changes.md Refs: infiniflow#16169 infiniflow#15457 infiniflow#15145 infiniflow#15446
Ports 4 M-effort PRs from .claude/plans/review-and-port-py-agent-changes.md Execution snapshot (all merged upstream) to the Go agent side. Group 4 - API auth ports - infiniflow#16169 Sandbox artifact ownership: add UserCanvasDAO.Accessible (owner-or-team predicate) and DocumentService.sandboxArtifactAccessible to gate GET /api/v1/documents/artifact/<filename>. Query API4Conversation for sessions owned by userID whose message blob references the filename (or its documents/artifact/<name> URL form); require at least one accessible canvas. Handler now fetches the current user and passes userID into the service; denial returns ErrArtifactNotFound to avoid cross-user enumeration. - infiniflow#15457 Tenant ownership on agentbots: Go side already had the loadCanvas IDOR guard at the entry of both AgentbotInputs and AgentbotCompletion. Added a cross-tenant regression test (tenant-B asks for tenant-A's canvas -> ErrUserCanvasNotFound). - infiniflow#15145 Rerun agent document access: add DocumentService.Accessible (loads doc, checks kbDAO.Accessible). Wire documentService into AgentHandler via WithDocumentService (nil-tolerant, preserves the existing NewAgentHandler signature for tests). RerunAgent returns "Document not found." when accessible check fails; cmd/server_main.go wires documentService after construction. Group 2 - thinking switch - infiniflow#15446 component portion: add Thinking field to LLMParam, LLMInput, and ChatInvokeRequest. mergeLLMParam reads inputs["thinking"] with a whitelist of {"enabled","disabled"} (matching python llm.py:78-79); arbitrary strings are rejected. The provider policy portion (Qwen/Kimi/GLM in rag/llm/chat_model.py) belongs to internal/llm/ and is a separate porting stream. Total: 4 new tests across 3 modified test files. All touched package tests pass (1697 + 4 skipped). The 1 failing test (TestAgent_ReActExhaustsSteps) is the pre-existing flaky test that also fails on the baseline without my changes. Refs: .claude/plans/review-and-port-py-agent-changes.md Refs: infiniflow#16169 infiniflow#15457 infiniflow#15145 infiniflow#15446
) Mirrors 14 merged upstream PRs into the Go agent port. PRs ported: - #15609 ExeSQL SSRF guard + DNS pin - #15436 HTTP timeout on external API tools - #16363 be_output restore + DeepL error path - #15644 switch no longer matches empty condition - #15374 session_id bind to path agent_id (DAO idor guard) - #16169 sandbox artifact ownership gate - #15457 tenant ownership on agentbots - #15145 rerun agent document access check - #15446 thinking switch (component portion; provider policy lives in internal/llm) - #15426 Invoke URL/proxy SSRF + DNS pin + no-redirects - #15238 agentbot thinking-logs beta endpoint - #14589 UserFillUp SSE event propagation - #14890 anonymous webhook opt-in - #15068 PipelineChunker new component (text/file_ref/parser_id dispatch; file-format extraction is a follow-up) 40 files, +2355 / -58 lines. 33 new tests, all targeted package suites pass (1721 + 4 skipped); 1 pre-existing flaky test unrelated.
…sion/user + input/output to Langfuse for agent runs Rebuilt on current upstream/main after force-push; cherry-pick of the 7 PR-original commits collapsed into a single net diff to avoid conflicts with intervening commits pulled in by repeated merges of upstream/main. Original PR work (commits dropped during rebuild because their content already lives on upstream/main or was a merge of upstream/main): c7339ae Enhance LLMService with token usage reporting 0266cf0 Implement token usage tracking and Langfuse integration ab2b267 Include session_id in run_kwargs 8bf937c Implement token usage tracking in chat model c955988 Enhance token tracking with context variables and functions 3e88ed5 fix(agent): address CodeRabbit review on token usage tracking 74b8c8c fix(agent): address CodeRabbit follow-up review Forced-upstream duplicates dropped (already merged to main): 70546ea (infiniflow#16396), 5b09910 (infiniflow#16403), 5d7f0fd (infiniflow#16405), 730f33b (infiniflow#16407), a06343e (infiniflow#16408), f90be41 (infiniflow#16410), c4fe68e (infiniflow#16409), d4a0e71 (infiniflow#14773), ef42fd7 (infiniflow#15436), ab1015d (infiniflow#16363), db188cc (infiniflow#15446), 56ece68 (infiniflow#15609), 2589b6e (infiniflow#15644), 74c2944 (infiniflow#15374), 78832ff (infiniflow#14985), bf18b59 (infiniflow#15457), 6c87225 (infiniflow#14890), e16d1a0 (infiniflow#15426), 4712fcb (infiniflow#16169), 0536233 (infiniflow#14589), 08c807a (infiniflow#15145) Plus 18 'Merge branch main into main' commits dropped (polluted topology).
…sion/user + input/output to Langfuse for agent runs Rebuilt on current upstream/main after force-push; cherry-pick of the 7 PR-original commits collapsed into a single net diff to avoid conflicts with intervening commits pulled in by repeated merges of upstream/main. Original PR work (commits dropped during rebuild because their content already lives on upstream/main or was a merge of upstream/main): c7339ae Enhance LLMService with token usage reporting 0266cf0 Implement token usage tracking and Langfuse integration ab2b267 Include session_id in run_kwargs 8bf937c Implement token usage tracking in chat model c955988 Enhance token tracking with context variables and functions 3e88ed5 fix(agent): address CodeRabbit review on token usage tracking 74b8c8c fix(agent): address CodeRabbit follow-up review Forced-upstream duplicates dropped (already merged to main): 70546ea (infiniflow#16396), 5b09910 (infiniflow#16403), 5d7f0fd (infiniflow#16405), 730f33b (infiniflow#16407), a06343e (infiniflow#16408), f90be41 (infiniflow#16410), c4fe68e (infiniflow#16409), d4a0e71 (infiniflow#14773), ef42fd7 (infiniflow#15436), ab1015d (infiniflow#16363), db188cc (infiniflow#15446), 56ece68 (infiniflow#15609), 2589b6e (infiniflow#15644), 74c2944 (infiniflow#15374), 78832ff (infiniflow#14985), bf18b59 (infiniflow#15457), 6c87225 (infiniflow#14890), e16d1a0 (infiniflow#15426), 4712fcb (infiniflow#16169), 0536233 (infiniflow#14589), 08c807a (infiniflow#15145) Plus 18 'Merge branch main into main' commits dropped (polluted topology). Co-authored-by: yzc <[email protected]>
…iniflow#16455) Mirrors 14 merged upstream PRs into the Go agent port. PRs ported: - infiniflow#15609 ExeSQL SSRF guard + DNS pin - infiniflow#15436 HTTP timeout on external API tools - infiniflow#16363 be_output restore + DeepL error path - infiniflow#15644 switch no longer matches empty condition - infiniflow#15374 session_id bind to path agent_id (DAO idor guard) - infiniflow#16169 sandbox artifact ownership gate - infiniflow#15457 tenant ownership on agentbots - infiniflow#15145 rerun agent document access check - infiniflow#15446 thinking switch (component portion; provider policy lives in internal/llm) - infiniflow#15426 Invoke URL/proxy SSRF + DNS pin + no-redirects - infiniflow#15238 agentbot thinking-logs beta endpoint - infiniflow#14589 UserFillUp SSE event propagation - infiniflow#14890 anonymous webhook opt-in - infiniflow#15068 PipelineChunker new component (text/file_ref/parser_id dispatch; file-format extraction is a follow-up) 40 files, +2355 / -58 lines. 33 new tests, all targeted package suites pass (1721 + 4 skipped); 1 pre-existing flaky test unrelated.
The Go port of POST /api/v1/agents/rerun failed every request with "500 server misconfiguration: document service not wired". Two defects stacked: 1. The fail-closed gate from infiniflow#15145 required a documentService, but cmd/ragflow_server.go never chained WithDocumentService onto NewAgentHandler. 2. It could never have compiled if it had: the injected documentAccessChecker interface declared Accessible(docID, userID) while the concrete DocumentService.Accessible takes a context, so the production service did not satisfy the interface. A compile-time assertion now pins the contract. Beyond the 500, the handler treated body.id as a document id, but the front-end (web useRerunDataflow) sends the pipeline operation LOG id — Python resolves log -> document via get_documents_info before gating. Even with the service wired the rerun would have been rejected with "Document not found." and, if it ever passed, silently did nothing. Implement the rerun properly on DocumentService.RerunDataflow: resolve the log to its document, enforce accessibility, refuse while the document is mid-run (0 < progress < 1), persist the edited DSL with dsl.path = [component_id] on the log row (Python update_by_id parity), then clear prior parse results and enqueue a fresh ingestion run via the existing StartParseDocuments(RerunWithDelete) machinery. The Go pipeline has no partial-resume entry point, so the rerun re-executes the full pipeline instead of resuming from component_id.
The Go port of POST /api/v1/agents/rerun failed every request with "500 server misconfiguration: document service not wired". Two defects stacked: 1. The fail-closed gate from infiniflow#15145 required a documentService, but cmd/ragflow_server.go never chained WithDocumentService onto NewAgentHandler. 2. It could never have compiled if it had: the injected documentAccessChecker interface declared Accessible(docID, userID) while the concrete DocumentService.Accessible takes a context, so the production service did not satisfy the interface. A compile-time assertion now pins the contract. Beyond the 500, the handler treated body.id as a document id, but the front-end (web useRerunDataflow) sends the pipeline operation LOG id — Python resolves log -> document via get_documents_info before gating. Even with the service wired the rerun would have been rejected with "Document not found." and, if it ever passed, silently did nothing. Implement the rerun properly on DocumentService.RerunDataflow: resolve the log to its document, enforce accessibility, refuse while the document is mid-run (0 < progress < 1), persist the edited DSL with dsl.path = [component_id] on the log row (Python update_by_id parity), then clear prior parse results and enqueue a fresh ingestion run via the existing StartParseDocuments(RerunWithDelete) machinery. The Go pipeline has no partial-resume entry point, so the rerun re-executes the full pipeline instead of resuming from component_id.
Related issues
Closes #15144
What problem does this PR solve?
POST /api/v1/agents/rerunloaded a pipeline operation log by UUID viaPipelineOperationLogService.get_documents_infowith 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
Changes
api/apps/restful_apis/agent_api.pyDocumentService.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.pySecurity notes
tenant_idfrom@add_tenant_id_to_kwargsiscurrent_user.id;DocumentService.accessiblecovers team-shared KBs.Test plan
pytest test/unit_test/api/apps/restful_apis/test_rerun_agent_authorization.pycd ragflow uv run pytest test/unit_test/api/apps/restful_apis/test_rerun_agent_authorization.py -q