Repository navigation
fix: guard SSRF in ExeSQL agent tool DB host - #15609
Conversation
|
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)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR adds SSRF protection to the ExeSQL agent tool by validating the configured database host with ChangesSSRF Hardening for ExeSQL Database Connections
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
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.
Actionable comments posted: 2
🤖 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 `@agent/tools/exesql.py`:
- Around line 127-135: Add ExeSQL-level structured logging in the _invoke flow
around the host validation: before calling assert_host_is_safe() log an
informational trace that validation is starting for self._param.host (without
revealing credentials/SQL), on ValueError catch log a warning/error with the
host and the exception message and then re-raise, and after a successful return
from assert_host_is_safe() log a debug/info message with the resolved safe_host
to indicate validated dial target; use the existing logger used by ExeSQL (refer
to _invoke and assert_host_is_safe) and avoid logging sensitive details.
In `@test/unit_test/agent/tools/test_exesql_ssrf.py`:
- Around line 34-35: The module test_exesql_ssrf.py must follow repo pytest
conventions: remove the inline pytest.main() invocation (pytest.main()) so tests
run via the standard uv run pytest workflow, and add the appropriate priority
markers (e.g., `@pytest.mark.p1` / `@pytest.mark.p2` / `@pytest.mark.p3`) to each test
function in this file so they integrate with the backend test gating; ensure you
place the marker decorators directly above each test_* function and keep import
pytest.
🪄 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: 0dca7bd8-3d33-4be8-bc7e-13e4a9077aaf
📒 Files selected for processing (2)
agent/tools/exesql.pytest/unit_test/agent/tools/test_exesql_ssrf.py
| import pytest | ||
|
|
There was a problem hiding this comment.
Match the repo's pytest conventions in this new module.
These tests are missing a p1/p2/p3 marker, and the inline pytest.main() entry point bypasses the standard uv run pytest workflow the rest of the backend suite uses.
♻️ Proposed cleanup
import pytest
+pytestmark = pytest.mark.p1
+
...
-if __name__ == "__main__":
- pytest.main([__file__, "-v"])As per coding guidelines, "Run backend tests using uv run pytest" and "Use pytest with priority markers (p1/p2/p3) for Python testing".
Also applies to: 113-145
🤖 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/unit_test/agent/tools/test_exesql_ssrf.py` around lines 34 - 35, The
module test_exesql_ssrf.py must follow repo pytest conventions: remove the
inline pytest.main() invocation (pytest.main()) so tests run via the standard uv
run pytest workflow, and add the appropriate priority markers (e.g.,
`@pytest.mark.p1` / `@pytest.mark.p2` / `@pytest.mark.p3`) to each test function in
this file so they integrate with the backend test gating; ensure you place the
marker decorators directly above each test_* function and keep import pytest.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15609 +/- ##
==========================================
- 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:
|
### What problem does this PR solve? Closes #15608. The ExeSQL agent tool (`agent/tools/exesql.py`) opens database connections to a node-author-controlled host/port with no SSRF validation. The sibling `test_db_connection` endpoint already validates the host via `common.ssrf_guard.assert_host_is_safe` (added by PR #14860), but the tool that actually performs the connection at agent run time was left unguarded — so the guard is bypassed simply by running the agent. An agent author can point the host at `127.0.0.1`, `169.254.169.254` (cloud metadata), or any internal RFC1918 host/port, turning ExeSQL into an internal port-scanner / metadata-fetch primitive. ### Fix Mirror the accepted endpoint guard: validate (and resolve) the host once, before the `db_type` dispatch, and connect to the validated public IP so a later DNS change cannot rebind the host to an internal address. - Add `from common.ssrf_guard import assert_host_is_safe`. - `safe_host = assert_host_is_safe(self._param.host)` before the dispatch (rejects loopback, link-local/metadata, RFC1918, and unresolvable hosts). - Substitute the validated IP into all 6 driver branches: mysql/mariadb, oceanbase, postgres, mssql, trino, IBM DB2. Adds `test/unit_test/agent/tools/test_exesql_ssrf.py` covering loopback, link-local/metadata, RFC1918, and empty-host rejection (before any connection), plus an allowed host dialing the validated IP. ### Validation - `python3 -m py_compile agent/tools/exesql.py` - `ruff check agent/tools/exesql.py test/unit_test/agent/tools/test_exesql_ssrf.py` - `pytest test/unit_test/agent/tools/test_exesql_ssrf.py` — 5 passed ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --------- Co-authored-by: Zhichang Yu <[email protected]>
Ports 5 S-effort PRs from .claude/plans/review-and-port-py-agent-changes.md Execution snapshot (all merged upstream) to the Go agent side. Group 1 - tool ports - infiniflow#15609 ExeSQL SSRF guard: add ValidateDBHost to tool/ssrf.go and wire into exesql.InvokableRun. Loopback, link-local, RFC1918, and empty host are rejected before any driver dispatch. Allowed hosts are dialed via the validated/resolved public IP (DNS-pin). - infiniflow#15436 HTTP timeout: Go side already routes github/qweather/tushare through HTTPHelper (client.Timeout: 30s + per-stage timeouts) and jin10 is a stub. Added regression guard tests: default client timeout, stage timeouts, and AST scan for bare http.Get/Post calls outside the helper. Group 2 - component ports - infiniflow#16363 be_output restore + DeepL error: add BeOutput(v) helper returning {"content": v} frame; add DeepL translation-failure regression test using rewriteHostTransport (avoids mutating package globals which raced TestDeepL_BuildRequest). - infiniflow#15644 Switch no longer matches empty condition: evaluateGroup empty-clauses short-circuit now returns false (was true) so an "and" condition with no clauses falls through to the next condition or end_cpn_ids instead of routing to the empty group's "to" target. Mirrors the all([]) is True fix. Group 4 - API ports - infiniflow#15374 session_id bind to path agent_id: Go DAO already enforces WHERE id = ? AND dialog_id = ? (stronger than the Python post-fetch check). Added 3 IDOR regression tests at the service level (Get/Get mismatch/Delete) confirming the binding holds. Total: 32 new tests across 4 new test files. All agent/tool and agent/component tests pass (320 + 331). All new service IDOR tests pass (3/3). The one failing test in agent/component (TestAgent_ReActExhaustsSteps) is a 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#15609 infiniflow#15436 infiniflow#16363 infiniflow#15644 infiniflow#15374
Ports 5 S-effort PRs from .claude/plans/review-and-port-py-agent-changes.md Execution snapshot (all merged upstream) to the Go agent side. Group 1 - tool ports - infiniflow#15609 ExeSQL SSRF guard: add ValidateDBHost to tool/ssrf.go and wire into exesql.InvokableRun. Loopback, link-local, RFC1918, and empty host are rejected before any driver dispatch. Allowed hosts are dialed via the validated/resolved public IP (DNS-pin). - infiniflow#15436 HTTP timeout: Go side already routes github/qweather/tushare through HTTPHelper (client.Timeout: 30s + per-stage timeouts) and jin10 is a stub. Added regression guard tests: default client timeout, stage timeouts, and AST scan for bare http.Get/Post calls outside the helper. Group 2 - component ports - infiniflow#16363 be_output restore + DeepL error: add BeOutput(v) helper returning {"content": v} frame; add DeepL translation-failure regression test using rewriteHostTransport (avoids mutating package globals which raced TestDeepL_BuildRequest). - infiniflow#15644 Switch no longer matches empty condition: evaluateGroup empty-clauses short-circuit now returns false (was true) so an "and" condition with no clauses falls through to the next condition or end_cpn_ids instead of routing to the empty group's "to" target. Mirrors the all([]) is True fix. Group 4 - API ports - infiniflow#15374 session_id bind to path agent_id: Go DAO already enforces WHERE id = ? AND dialog_id = ? (stronger than the Python post-fetch check). Added 3 IDOR regression tests at the service level (Get/Get mismatch/Delete) confirming the binding holds. Total: 32 new tests across 4 new test files. All agent/tool and agent/component tests pass (320 + 331). All new service IDOR tests pass (3/3). The one failing test in agent/component (TestAgent_ReActExhaustsSteps) is a 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#15609 infiniflow#15436 infiniflow#16363 infiniflow#15644 infiniflow#15374
Ports 5 S-effort PRs from .claude/plans/review-and-port-py-agent-changes.md Execution snapshot (all merged upstream) to the Go agent side. Group 1 - tool ports - infiniflow#15609 ExeSQL SSRF guard: add ValidateDBHost to tool/ssrf.go and wire into exesql.InvokableRun. Loopback, link-local, RFC1918, and empty host are rejected before any driver dispatch. Allowed hosts are dialed via the validated/resolved public IP (DNS-pin). - infiniflow#15436 HTTP timeout: Go side already routes github/qweather/tushare through HTTPHelper (client.Timeout: 30s + per-stage timeouts) and jin10 is a stub. Added regression guard tests: default client timeout, stage timeouts, and AST scan for bare http.Get/Post calls outside the helper. Group 2 - component ports - infiniflow#16363 be_output restore + DeepL error: add BeOutput(v) helper returning {"content": v} frame; add DeepL translation-failure regression test using rewriteHostTransport (avoids mutating package globals which raced TestDeepL_BuildRequest). - infiniflow#15644 Switch no longer matches empty condition: evaluateGroup empty-clauses short-circuit now returns false (was true) so an "and" condition with no clauses falls through to the next condition or end_cpn_ids instead of routing to the empty group's "to" target. Mirrors the all([]) is True fix. Group 4 - API ports - infiniflow#15374 session_id bind to path agent_id: Go DAO already enforces WHERE id = ? AND dialog_id = ? (stronger than the Python post-fetch check). Added 3 IDOR regression tests at the service level (Get/Get mismatch/Delete) confirming the binding holds. Total: 32 new tests across 4 new test files. All agent/tool and agent/component tests pass (320 + 331). All new service IDOR tests pass (3/3). The one failing test in agent/component (TestAgent_ReActExhaustsSteps) is a 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#15609 infiniflow#15436 infiniflow#16363 infiniflow#15644 infiniflow#15374
Ports 5 S-effort PRs from .claude/plans/review-and-port-py-agent-changes.md Execution snapshot (all merged upstream) to the Go agent side. Group 1 - tool ports - infiniflow#15609 ExeSQL SSRF guard: add ValidateDBHost to tool/ssrf.go and wire into exesql.InvokableRun. Loopback, link-local, RFC1918, and empty host are rejected before any driver dispatch. Allowed hosts are dialed via the validated/resolved public IP (DNS-pin). - infiniflow#15436 HTTP timeout: Go side already routes github/qweather/tushare through HTTPHelper (client.Timeout: 30s + per-stage timeouts) and jin10 is a stub. Added regression guard tests: default client timeout, stage timeouts, and AST scan for bare http.Get/Post calls outside the helper. Group 2 - component ports - infiniflow#16363 be_output restore + DeepL error: add BeOutput(v) helper returning {"content": v} frame; add DeepL translation-failure regression test using rewriteHostTransport (avoids mutating package globals which raced TestDeepL_BuildRequest). - infiniflow#15644 Switch no longer matches empty condition: evaluateGroup empty-clauses short-circuit now returns false (was true) so an "and" condition with no clauses falls through to the next condition or end_cpn_ids instead of routing to the empty group's "to" target. Mirrors the all([]) is True fix. Group 4 - API ports - infiniflow#15374 session_id bind to path agent_id: Go DAO already enforces WHERE id = ? AND dialog_id = ? (stronger than the Python post-fetch check). Added 3 IDOR regression tests at the service level (Get/Get mismatch/Delete) confirming the binding holds. Total: 32 new tests across 4 new test files. All agent/tool and agent/component tests pass (320 + 331). All new service IDOR tests pass (3/3). The one failing test in agent/component (TestAgent_ReActExhaustsSteps) is a 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#15609 infiniflow#15436 infiniflow#16363 infiniflow#15644 infiniflow#15374
Ports 5 S-effort PRs from .claude/plans/review-and-port-py-agent-changes.md Execution snapshot (all merged upstream) to the Go agent side. Group 1 - tool ports - infiniflow#15609 ExeSQL SSRF guard: add ValidateDBHost to tool/ssrf.go and wire into exesql.InvokableRun. Loopback, link-local, RFC1918, and empty host are rejected before any driver dispatch. Allowed hosts are dialed via the validated/resolved public IP (DNS-pin). - infiniflow#15436 HTTP timeout: Go side already routes github/qweather/tushare through HTTPHelper (client.Timeout: 30s + per-stage timeouts) and jin10 is a stub. Added regression guard tests: default client timeout, stage timeouts, and AST scan for bare http.Get/Post calls outside the helper. Group 2 - component ports - infiniflow#16363 be_output restore + DeepL error: add BeOutput(v) helper returning {"content": v} frame; add DeepL translation-failure regression test using rewriteHostTransport (avoids mutating package globals which raced TestDeepL_BuildRequest). - infiniflow#15644 Switch no longer matches empty condition: evaluateGroup empty-clauses short-circuit now returns false (was true) so an "and" condition with no clauses falls through to the next condition or end_cpn_ids instead of routing to the empty group's "to" target. Mirrors the all([]) is True fix. Group 4 - API ports - infiniflow#15374 session_id bind to path agent_id: Go DAO already enforces WHERE id = ? AND dialog_id = ? (stronger than the Python post-fetch check). Added 3 IDOR regression tests at the service level (Get/Get mismatch/Delete) confirming the binding holds. Total: 32 new tests across 4 new test files. All agent/tool and agent/component tests pass (320 + 331). All new service IDOR tests pass (3/3). The one failing test in agent/component (TestAgent_ReActExhaustsSteps) is a 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#15609 infiniflow#15436 infiniflow#16363 infiniflow#15644 infiniflow#15374
Ports 5 S-effort PRs from .claude/plans/review-and-port-py-agent-changes.md Execution snapshot (all merged upstream) to the Go agent side. Group 1 - tool ports - infiniflow#15609 ExeSQL SSRF guard: add ValidateDBHost to tool/ssrf.go and wire into exesql.InvokableRun. Loopback, link-local, RFC1918, and empty host are rejected before any driver dispatch. Allowed hosts are dialed via the validated/resolved public IP (DNS-pin). - infiniflow#15436 HTTP timeout: Go side already routes github/qweather/tushare through HTTPHelper (client.Timeout: 30s + per-stage timeouts) and jin10 is a stub. Added regression guard tests: default client timeout, stage timeouts, and AST scan for bare http.Get/Post calls outside the helper. Group 2 - component ports - infiniflow#16363 be_output restore + DeepL error: add BeOutput(v) helper returning {"content": v} frame; add DeepL translation-failure regression test using rewriteHostTransport (avoids mutating package globals which raced TestDeepL_BuildRequest). - infiniflow#15644 Switch no longer matches empty condition: evaluateGroup empty-clauses short-circuit now returns false (was true) so an "and" condition with no clauses falls through to the next condition or end_cpn_ids instead of routing to the empty group's "to" target. Mirrors the all([]) is True fix. Group 4 - API ports - infiniflow#15374 session_id bind to path agent_id: Go DAO already enforces WHERE id = ? AND dialog_id = ? (stronger than the Python post-fetch check). Added 3 IDOR regression tests at the service level (Get/Get mismatch/Delete) confirming the binding holds. Total: 32 new tests across 4 new test files. All agent/tool and agent/component tests pass (320 + 331). All new service IDOR tests pass (3/3). The one failing test in agent/component (TestAgent_ReActExhaustsSteps) is a 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#15609 infiniflow#15436 infiniflow#16363 infiniflow#15644 infiniflow#15374 Apply unstaged agent-go-port prep work docker/.env - switch API_PROXY_SCHEME from python to go (Go server is the default) - enable SANDBOX_ENABLED=1 and extend COMPOSE_PROFILES with ragflow-go web/CLAUDE.md - document frontend agent conventions: CSS/flex layout debugging, scope boundaries, i18n language files, query-key factory pattern, request layering (hook -> service -> next-request), shared UI lock, utility libs (dayjs, ahooks, lodash) web/.agents/skills/tanstack-query-best-practices/ - remove the full tanstack-query-best-practices skill set (SKILL.md + 21 rule files, 1,535 lines total) Lefthook pre-commit was satisfied after stripping two pre-existing trailing-whitespace lines from docker/.env comments. chore(hooks): enable auto-fix for staged file checks Convert lefthook pre-commit to B-mode (check + auto-fix in place) for the four fixable jobs: - end-of-file-fixer, trailing-whitespace, mixed-line-ending: these wrap tools/hooks/check_files.py, which gains a --fix mode that rewrites staged files in place. Lefthook re-stages the fixes via stage_fixed: true, so the next commit naturally includes the cleanup. The user no longer has to manually strip whitespace, append newlines, or normalize line endings. - web-eslint: ESLint --fix is enabled; safe auto-fixes are applied, warnings still surface. trailing-whitespace now uses a regex ([ \t]+(?=\r?\n|$)) so it correctly detects/strips whitespace before a line terminator and preserves CRLF when only stripping whitespace. A previous splitlines-based rstrip pass would silently miss whitespace-before-newline. Checks that only validate (json, yaml) or detect states that need human review (case-conflict, merge-conflict, broken symlinks) remain check-only; their --fix flag is accepted but a no-op. ruff check/format, gofmt, and web-prettier already auto-fixed in the previous config and were left unchanged. fix
Ports 5 S-effort PRs from .claude/plans/review-and-port-py-agent-changes.md Execution snapshot (all merged upstream) to the Go agent side. Group 1 - tool ports - infiniflow#15609 ExeSQL SSRF guard: add ValidateDBHost to tool/ssrf.go and wire into exesql.InvokableRun. Loopback, link-local, RFC1918, and empty host are rejected before any driver dispatch. Allowed hosts are dialed via the validated/resolved public IP (DNS-pin). - infiniflow#15436 HTTP timeout: Go side already routes github/qweather/tushare through HTTPHelper (client.Timeout: 30s + per-stage timeouts) and jin10 is a stub. Added regression guard tests: default client timeout, stage timeouts, and AST scan for bare http.Get/Post calls outside the helper. Group 2 - component ports - infiniflow#16363 be_output restore + DeepL error: add BeOutput(v) helper returning {"content": v} frame; add DeepL translation-failure regression test using rewriteHostTransport (avoids mutating package globals which raced TestDeepL_BuildRequest). - infiniflow#15644 Switch no longer matches empty condition: evaluateGroup empty-clauses short-circuit now returns false (was true) so an "and" condition with no clauses falls through to the next condition or end_cpn_ids instead of routing to the empty group's "to" target. Mirrors the all([]) is True fix. Group 4 - API ports - infiniflow#15374 session_id bind to path agent_id: Go DAO already enforces WHERE id = ? AND dialog_id = ? (stronger than the Python post-fetch check). Added 3 IDOR regression tests at the service level (Get/Get mismatch/Delete) confirming the binding holds. Total: 32 new tests across 4 new test files. All agent/tool and agent/component tests pass (320 + 331). All new service IDOR tests pass (3/3). The one failing test in agent/component (TestAgent_ReActExhaustsSteps) is a 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#15609 infiniflow#15436 infiniflow#16363 infiniflow#15644 infiniflow#15374 Apply unstaged agent-go-port prep work docker/.env - switch API_PROXY_SCHEME from python to go (Go server is the default) - enable SANDBOX_ENABLED=1 and extend COMPOSE_PROFILES with ragflow-go web/CLAUDE.md - document frontend agent conventions: CSS/flex layout debugging, scope boundaries, i18n language files, query-key factory pattern, request layering (hook -> service -> next-request), shared UI lock, utility libs (dayjs, ahooks, lodash) web/.agents/skills/tanstack-query-best-practices/ - remove the full tanstack-query-best-practices skill set (SKILL.md + 21 rule files, 1,535 lines total) Lefthook pre-commit was satisfied after stripping two pre-existing trailing-whitespace lines from docker/.env comments. chore(hooks): enable auto-fix for staged file checks Convert lefthook pre-commit to B-mode (check + auto-fix in place) for the four fixable jobs: - end-of-file-fixer, trailing-whitespace, mixed-line-ending: these wrap tools/hooks/check_files.py, which gains a --fix mode that rewrites staged files in place. Lefthook re-stages the fixes via stage_fixed: true, so the next commit naturally includes the cleanup. The user no longer has to manually strip whitespace, append newlines, or normalize line endings. - web-eslint: ESLint --fix is enabled; safe auto-fixes are applied, warnings still surface. trailing-whitespace now uses a regex ([ \t]+(?=\r?\n|$)) so it correctly detects/strips whitespace before a line terminator and preserves CRLF when only stripping whitespace. A previous splitlines-based rstrip pass would silently miss whitespace-before-newline. Checks that only validate (json, yaml) or detect states that need human review (case-conflict, merge-conflict, broken symlinks) remain check-only; their --fix flag is accepted but a no-op. ruff check/format, gofmt, and web-prettier already auto-fixed in the previous config and were left unchanged.
) 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.
What problem does this PR solve?
Closes #15608.
The ExeSQL agent tool (
agent/tools/exesql.py) opens database connections to a node-author-controlled host/port with no SSRF validation. The siblingtest_db_connectionendpoint already validates the host viacommon.ssrf_guard.assert_host_is_safe(added by PR #14860), but the tool that actually performs the connection at agent run time was left unguarded — so the guard is bypassed simply by running the agent. An agent author can point the host at127.0.0.1,169.254.169.254(cloud metadata), or any internal RFC1918 host/port, turning ExeSQL into an internal port-scanner / metadata-fetch primitive.Fix
Mirror the accepted endpoint guard: validate (and resolve) the host once, before the
db_typedispatch, and connect to the validated public IP so a later DNS change cannot rebind the host to an internal address.from common.ssrf_guard import assert_host_is_safe.safe_host = assert_host_is_safe(self._param.host)before the dispatch (rejects loopback, link-local/metadata, RFC1918, and unresolvable hosts).Adds
test/unit_test/agent/tools/test_exesql_ssrf.pycovering loopback, link-local/metadata, RFC1918, and empty-host rejection (before any connection), plus an allowed host dialing the validated IP.Validation
python3 -m py_compile agent/tools/exesql.pyruff check agent/tools/exesql.py test/unit_test/agent/tools/test_exesql_ssrf.pypytest test/unit_test/agent/tools/test_exesql_ssrf.py— 5 passedType of change