Repository navigation
fix(serve): require API key on connector confirm endpoints - #3264
Conversation
The v2 connector routes `/pending-confirms` and `/confirm` were mounted without the bearer check every other serve module applies, so anyone who could reach the server could list pending tool confirmations (including the argument summaries) and approve or reject them, even when `api_keys` was configured. `ConnectorServe` is already registered with the global `api_keys`, and `ConnectorService.config` exposes them; nothing read them. Add the same `check_api_key` dependency used by the flow and file endpoints and attach it to the two confirmation routes. With `api_keys` unset the behaviour is unchanged (allow all). Fixes eosphoros-ai#3242
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 SummaryPurpose and implementationThe change protects ScopeThe change affects the connector API in Risks and compatibilityWhen API keys are configured, clients that call either route must provide a configured key. The authentication bypass for Tests and verificationThe added tests cover successful and rejected authentication for Run the targeted tests with WalkthroughThe ChangesConnector endpoint authentication
Priority: ⬆️ High Estimated code review effort: 2 (Simple) | ~10 minutes Severity of issue fixed: High Merge Risk: 🔵 Low · up to The authentication change is mergeable with bounded risk, but an authorized confirmation POST should be tested to protect the intended approval flow. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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)
packages/dbgpt-serve/src/dbgpt_serve/connector/tests/test_endpoints.py (1)
101-108: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTest an authorized confirmation POST.
The POST test covers only rejection. Add a configured-key case with a registered
confirm-1confirmation. Assert the200response,{"status": "ok"}, and removal of the pending confirmation. The existing fixture seeds_PENDING_CONFIRMATIONS, but the route resolves through the separateConfirmationRegistry, so adding only the Bearer header would not exercise a successful confirmation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 7be2c469-0059-46cb-a8da-b88d64daf480
📒 Files selected for processing (2)
packages/dbgpt-serve/src/dbgpt_serve/connector/api/endpoints.pypackages/dbgpt-serve/src/dbgpt_serve/connector/tests/test_endpoints.py
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📜 Review details
🧰 Additional context used
📓 Path-based instructions (3)
保持 API -> service -> DAO/model 的职责边界,不得引入对 dbgpt_app 的反向依赖。 修改 API 时,检查 route、HTTP method、response_model、Pydantic schema、 error code、v1/v2 兼容性以及 dbgpt-client contract。 启用身份认证或多用户模式时,create、update、delete、download、install 和 execution endpoint...
⚙️ CodeRabbit configuration file
Files:
packages/dbgpt-serve/src/dbgpt_serve/connector/api/endpoints.pypackages/dbgpt-serve/src/dbgpt_serve/connector/tests/test_endpoints.py
检查 Python 测试、fixture 和测试辅助代码是否提供了有意义的回归覆盖。 应断言可观察行为和对外相关契约,而不是只断言 mock 调用次数或实现细节。将 mock 保持在真实 I/O 或进程边界,使被测行为本身仍会执行。 对于 bug 修复,聚焦的回归测试应在旧行为上失败。对于安全修复,在能够安全测试时, 应包含一个具体的绕过方式或恶意输入场景。 当这些场景与变更的生产路径相关时,覆盖错误、空输入、边界、清理,以及异步取消 或 timeout 行为;不要要求与变更...
⚙️ CodeRabbit configuration file
Files:
packages/dbgpt-serve/src/dbgpt_serve/connector/tests/test_endpoints.py
Use Python 3.10 or newer for project development.
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Files:
packages/dbgpt-serve/src/dbgpt_serve/connector/api/endpoints.pypackages/dbgpt-serve/src/dbgpt_serve/connector/tests/test_endpoints.py
🔇 Additional comments (1)
packages/dbgpt-serve/src/dbgpt_serve/connector/api/endpoints.py (1)
4-8: LGTM!Also applies to: 37-99, 234-241
Description
Fixes #3242.
GET /api/v2/serve/connectors/pending-confirmsandPOST /api/v2/serve/connectors/confirmhad no auth dependency, so withapi_keysconfigured anyone who could reach the server could still list pending tool confirmations (argument summaries included) and approve them.ConnectorServealready receives the globalapi_keysandConnectorService.configexposes them, but nothing in the connector router ever read them.I added the same
check_api_keydependency the flow, prompt and conversation serve modules define and attached it to those two routes. Withapi_keysunset nothing changes, which matches how every other serve module behaves. I thought about liftingcheck_api_keyintodbgpt_serve.coresince it is now copied in several places, but that would be a refactor across modules and I wanted this to be the small change that closes the hole. Happy to do that as a follow-up if you'd prefer it shared.I only guarded the two confirmation routes. The rest of the connector CRUD routes are also unguarded, and I went back and forth on covering the whole router here. I held off because those are a separate question from the approval bypass this issue is about, and putting auth on them changes what the web UI gets back for every connector call. The issue also raises binding a confirmation to the session that created it, and the
except Exception: passfail-open inexecute_tool.py. Both are real, but they touch the agent execution path rather than this router, so I've left them out of this PR.How Has This Been Tested?
I added
packages/dbgpt-serve/src/dbgpt_serve/connector/tests/test_endpoints.py, using the sharedclient/asystem_appfixtures fromdbgpt_serve.core.tests.conftestlike the other serve tests do. It checks that withapi_keysset,/pending-confirmsreturns 401 with no token and with a wrong token and 200 with the right one. It also checks that/confirmreturns 401 without a token and leaves the pending entry in the queue, and that withapi_keysunset/pending-confirmsstill answers without a token.pytest packages/dbgpt-serve/src/dbgpt_serve/connector/testsgives 30 passed on main and 35 passed with this branch. With the twodependencies=[...]lines reverted, the three new cases that expect a 401 fail and the other 32 still pass.Snapshots:
N/A, backend only.
Checklist: