Repository navigation
π fix(adminmcp): refuse a request path with an empty, "." or ".." element - #16918
Conversation
β¦ment Names from the caller (agent, run, repository, contributor, plan) go into the request path through url.PathEscape, which leaves "." and ".." as they are. The hive's router answers a path holding one with a redirect to the cleaned path, which is another route: /api/kick/../status is /api/status and /api/model/../<name> is /api/<name>. The stdio client followed the redirect with the same method, body and token, so a registered write could be confirmed into an endpoint the admin MCP does not offer, and a read could return another endpoint's data. Over HTTP the redirect was not followed and the caller saw only "HTTP 307". CheckRequestPath refuses such a path. It is called for every read on both transports, in PreviewWrite and ConfirmWrite, and in the stdio write client. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Danathar <Danathar@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
|
Hive status β updated in place; edits do not notify. Full history is in the Activity Monitor. Reviewed by Reviewer notesRead Coverage is complete as far as I can trace it:
I also checked that no legitimate route has a trailing slash or empty segment that the empty-element rule would now refuse:
|
There was a problem hiding this comment.
Read the diff against the v6 tree and the callers; the change does what the body says and I found no defect.
Verified
- The stdio redirect claim holds:
pkg/hivectl/client.go:145builds a plainhttp.Client{Timeout, Transport}with noCheckRedirect, so a 307 from the hub is followed with the same method/body and the token re-sent (same host). The dashboard provider dispatches in-process viahttptest.NewRequest(pkg/dashboard/admin_mcp.go:182,:264), which does not follow redirects β matching the "caller only saw HTTP 307" description. - Coverage of entry points: every stdio read goes through
getPath(cmd/hive-admin-mcp/main.go:339,:352,:371), and the only otherclient.Docalls are fixed paths (:474/api/status/summary,:505/api/version) and the guardedExecuteWrite(:314). On the dashboard sideReadfunnels intogetβgetVerifiedorreadDiag, both now guarded.WriteClient.ExecuteWritehas exactly one caller (pkg/adminmcp/adminmcp.go:561), after the newConfirmWritecheck, so dashboard writes are covered without touchingdashboardAdminMCPProvider.ExecuteWrite. CheckRequestPathonly inspects the path before?, so/api/logs/read?include=..&exclude=.stays allowed (tested), and single-levelPathUnescapecatches%2e%2ewhile leaving a double-encoded%252e%252eas the literal name%2e%2e, which the router does not clean.go build ./pkg/adminmcp/ ./pkg/dashboard/ ./cmd/hive-admin-mcp/ondf53fb6is clean; CI is green apart from pending tide.
Non-blocking observation: the stdio ExecuteWrite re-checks the path itself (main.go:288) but the dashboard ExecuteWrite relies on ConfirmWrite. Both are safe today since ConfirmWrite is the sole caller; a one-line mirror in admin_mcp.go:248 would keep the two providers symmetric if anyone later adds a second caller.
Looks correct to me.
β hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
Summary
The admin MCP puts names from the caller (an agent, a run, a repository, a contributor, a plan) into the path of the request it sends to the hive. A name of
.or..changed which endpoint the request reached. Over stdio, with writes enabled, a registered write operation could be previewed and confirmed into aPOSTthe admin MCP does not offer, including operations its exclusion catalogue refuses. This PR refuses such a path on both transports before anything is sent.What went wrong
Names are escaped with
url.PathEscape, and.and..are valid path characters, so they pass through unchanged:The hive's router does not serve a path with a
.or..element. It answers with a redirect (307) to the cleaned path, and the cleaned path is another route:/api/kick/../statusis/api/status, and/api/model/../<name>is/api/<name>.hive-admin-mcp). The client follows that redirect with the same method, body and token. A read tool then returned another endpoint's data under the wrong name. A write operation, shown to the operator as "Set model for agent .. to<name>", ranPOST /api/<name>.POST /api/admin/mcp). The redirect is not followed inside the hive, so nothing else was reached. The caller only saw "Hive API returned HTTP 307" with a link to the other route.Writes are off by default, and the stdio caller already holds the dashboard token. What this broke is the admin MCP's own promise that the assistant can run only the listed operations.
What changes
adminmcp.CheckRequestPathrefuses a request path that has an empty,.or..element (also when percent-encoded).write_preview, inwrite_confirm(so a confirmation stored before the upgrade is not executed either), and in the stdio write client..or... No request is sent.Names that merely contain dots (
.github,epic..1) and names that need escaping (team/scanner) are not affected.Operators using stdio need to re-extract or rebuild
hive-admin-mcpto get the fix.Files
src/pkg/adminmcp/request_path.go: new,CheckRequestPath.src/pkg/adminmcp/adminmcp.go:PreviewWriteandConfirmWritecall it.src/pkg/dashboard/admin_mcp.go,src/pkg/dashboard/admin_mcp_diag.go: the HTTP provider's reads call it.src/cmd/hive-admin-mcp/main.go: the stdio reads and the stdio write client call it.src/pkg/adminmcp/request_path_test.go,src/cmd/hive-admin-mcp/request_path_test.go,src/pkg/dashboard/admin_mcp_request_path_test.go.changelog.d/security-admin-mcp-request-path-elements.mdTests
TestCheckRequestPath: 12 paths allowed, 12 refused.TestWritePreviewRefusesDotNames: 20 operation and argument pairs, each refused with no confirmation stored.TestWriteConfirmRefusesStoredDotPathTestWritePreviewStillAcceptsOrdinaryNamesTestStdioWriteWithDotNameNeverReachesTheHive,TestStdioReadWithDotNameNeverReachesTheHive: against a test hive with the real route shapes, no request arrives.TestDashboardAdminMCPRefusesDotNamesBeforeRoutinggo test ./pkg/adminmcp/ ./cmd/hive-admin-mcp/and theAdminMCP,DiagandRequestPathtests in./pkg/dashboard/pass, re-run on top of the currentv6.π€ Generated with Claude Code