Skip to content

fix(serve): require API key on connector confirm endpoints - #3264

Merged
chenliang15405 merged 1 commit into
eosphoros-ai:mainfrom
drakeo338:claude/3242-fix
Sep 26, 2026
Merged

chenliang15405 merged 1 commit into
eosphoros-ai:mainfrom
drakeo338:claude/3242-fix

Conversation

@drakeo338

Copy link
Copy Markdown
Contributor

Description

Fixes #3242.

GET /api/v2/serve/connectors/pending-confirms and POST /api/v2/serve/connectors/confirm had no auth dependency, so with api_keys configured anyone who could reach the server could still list pending tool confirmations (argument summaries included) and approve them. ConnectorServe already receives the global api_keys and ConnectorService.config exposes them, but nothing in the connector router ever read them.

I added the same check_api_key dependency the flow, prompt and conversation serve modules define and attached it to those two routes. With api_keys unset nothing changes, which matches how every other serve module behaves. I thought about lifting check_api_key into dbgpt_serve.core since 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: pass fail-open in execute_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 shared client/asystem_app fixtures from dbgpt_serve.core.tests.conftest like the other serve tests do. It checks that with api_keys set, /pending-confirms returns 401 with no token and with a wrong token and 200 with the right one. It also checks that /confirm returns 401 without a token and leaves the pending entry in the queue, and that with api_keys unset /pending-confirms still answers without a token.

pytest packages/dbgpt-serve/src/dbgpt_serve/connector/tests gives 30 passed on main and 35 passed with this branch. With the two dependencies=[...] lines reverted, the three new cases that expect a 401 fail and the other 32 still pass.

Snapshots:

N/A, backend only.

Checklist:

  • My code follows the style guidelines of this project
  • I have already rebased the commits and make the commit message conform to the project standard.
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • Any dependent changes have been merged and published in downstream modules

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
@github-actions github-actions Bot added the fix Bug fixes label Sep 24, 2026
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Summary

Purpose and implementation

The change protects GET /pending-confirms and POST /confirm with API-key authentication. When service.config.api_keys is configured, the request must include a matching Bearer token. When no keys are configured, the routes remain accessible without a token.

Scope

The change affects the connector API in dbgpt-serve. It adds a cached parser for comma-separated API keys and applies check_api_key to both confirmation routes. The dependency also bypasses authentication for paths beginning with /api/v1. Other connector routes, confirmation-to-session binding, and fail-closed confirmation handling are outside the change.

Risks and compatibility

When API keys are configured, clients that call either route must provide a configured key. The authentication bypass for /api/v1 paths means requests using such paths are not checked by this dependency. The change does not address the linked issue’s session-binding or fail-closed concerns. No performance measurements were supplied.

Tests and verification

The added tests cover successful and rejected authentication for GET /pending-confirms, rejection of unauthenticated POST /confirm, and unauthenticated access to the listing route when no API keys are configured. They do not cover successful confirmation with a valid key or the unset-key behavior for POST /confirm. Test execution results were not supplied.

Run the targeted tests with pytest packages/dbgpt-serve/src/dbgpt_serve/connector/tests/test_endpoints.py.

Walkthrough

The /pending-confirms and /confirm routes now use a Bearer-token dependency. When API keys are configured, it checks the supplied token against the configured keys and returns 401 for missing or unmatched tokens. Requests are allowed when no keys are configured, and /api/v1 paths bypass the check.

Changes

Connector endpoint authentication

Layer / File(s) Summary
Bearer-token validation and route coverage
packages/dbgpt-serve/src/dbgpt_serve/connector/api/endpoints.py, packages/dbgpt-serve/src/dbgpt_serve/connector/tests/test_endpoints.py
The two confirmation routes use the API-key dependency. Tests cover missing, incorrect, and correct tokens, access with no configured keys, and rejection before confirmation processing.

Priority: ⬆️ High

Estimated code review effort: 2 (Simple) | ~10 minutes

Severity of issue fixed: High

Merge Risk: 🔵 Low · up to 64b78

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commit format with the valid type fix, the serve scope, and a concise description that accurately identifies the secured connector confirmation endpoints.
Description check ✅ Passed The description clearly explains the security issue, scope, implementation, testing, out-of-scope items, and checklist status. The documentation and downstream dependency checklist items remain unchec…
Linked Issues check ✅ Passed Issue [#3242] requires authentication for the pending-confirmation listing and resolution routes. endpoints.py applies Depends(check_api_key) to both /pending-confirms and /confirm. `check_api…
Out of Scope Changes check ✅ Passed The reported changes add conditional API-key enforcement to the two routes identified by [#3242] and add endpoint tests for that behavior. The reviewed files do not show an unrelated functional change…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/dbgpt-serve/src/dbgpt_serve/connector/tests/test_endpoints.py (1)

101-108: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test an authorized confirmation POST.

The POST test covers only rejection. Add a configured-key case with a registered confirm-1 confirmation. Assert the 200 response, {"status": "ok"}, and removal of the pending confirmation. The existing fixture seeds _PENDING_CONFIRMATIONS, but the route resolves through the separate ConfirmationRegistry, 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

📥 Commits

Reviewing files that changed from the base of the PR and between ca9f014 and 64b78f1.

📒 Files selected for processing (2)
  • packages/dbgpt-serve/src/dbgpt_serve/connector/api/endpoints.py
  • packages/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.py
  • packages/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.py
  • packages/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

@chenliang15405
chenliang15405 merged commit fbea7ba into eosphoros-ai:main Sep 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fixes

Projects

None yet

3 participants