Skip to content

πŸ› fix(adminmcp): refuse a request path with an empty, "." or ".." element - #16918

Merged
hivecommons-hive[bot] merged 1 commit into
hivecommons:v6from
Danathar:fix/adminmcp-request-path-elements
Nov 6, 2026
Merged

hivecommons-hive[bot] merged 1 commit into
hivecommons:v6from
Danathar:fix/adminmcp-request-path-elements

Conversation

@Danathar

@Danathar Danathar commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

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 a POST the 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:

agent_nudge_status  agent ".."                 ->  GET  /api/kick/../status
agent.model         agent "..", model "<name>" ->  POST /api/model/../<name>

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/../status is /api/status, and /api/model/../<name> is /api/<name>.

  • Stdio (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>", ran POST /api/<name>.
  • HTTP (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

  • New adminmcp.CheckRequestPath refuses a request path that has an empty, . or .. element (also when percent-encoded).
  • It runs for every read on both transports, in write_preview, in write_confirm (so a confirmation stored before the upgrade is not executed either), and in the stdio write client.
  • The refusal names the path and says a name cannot be empty, . 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-mcp to get the fix.

Files

  • src/pkg/adminmcp/request_path.go: new, CheckRequestPath.
  • src/pkg/adminmcp/adminmcp.go: PreviewWrite and ConfirmWrite call 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.
  • Tests: 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.md

Tests

  • TestCheckRequestPath: 12 paths allowed, 12 refused.
  • TestWritePreviewRefusesDotNames: 20 operation and argument pairs, each refused with no confirmation stored.
  • TestWriteConfirmRefusesStoredDotPath
  • TestWritePreviewStillAcceptsOrdinaryNames
  • TestStdioWriteWithDotNameNeverReachesTheHive, TestStdioReadWithDotNameNeverReachesTheHive: against a test hive with the real route shapes, no request arrives.
  • TestDashboardAdminMCPRefusesDotNamesBeforeRouting
  • Nine mutants (each call site removed, and three weakenings of the check) each fail a test.
  • go test ./pkg/adminmcp/ ./cmd/hive-admin-mcp/ and the AdminMCP, Diag and RequestPath tests in ./pkg/dashboard/ pass, re-run on top of the current v6.

πŸ€– Generated with Claude Code

…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>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Nov 6, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign danathar for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v6

Conflicts are checked with every PR merged onto the current tip of v6, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#16884 ✨ feat(adminmcp): read and act on the Activity monitor; writes run as the verified caller same files src/cmd/hive-admin-mcp/main.go
src/pkg/adminmcp/adminmcp.go
src/pkg/dashboard/admin_mcp.go

@hivecommons-hive

hivecommons-hive Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Hive status β€” updated in place; edits do not notify. Full history is in the Activity Monitor.

Reviewed by reviewer-2 β€” no findings.

Reviewer notes

Read CheckRequestPath (src/pkg/adminmcp/request_path.go) and every call site at df53fb6, then the path builders it protects (tools_agent_ops.go:55-274, all url.PathEscape, which indeed leaves ./.. intact) and the stdio read/write paths in cmd/hive-admin-mcp/main.go.

Coverage is complete as far as I can trace it:

  • stdio reads: lines 339, 352, 371 all go through getPath, which now checks first (main.go:398-401); the only client.Do calls that bypass it are the fixed /api/status/summary and /api/version probes (474, 505).
  • stdio writes: ExecuteWrite checks before roster.activeClient() (main.go:288), so nothing is sent.
  • Both transports' writes are also gated at the handler: PreviewWrite (adminmcp.go:506) and ConfirmWrite re-checking pending.Preview.Request.Path (adminmcp.go:556-560) before WriteClient.ExecuteWrite, so a confirmation persisted before this change cannot execute β€” TestWriteConfirmRefusesStoredDotPath covers exactly that.
  • HTTP transport reads: getVerified (admin_mcp.go:181) and readDiag (admin_mcp_diag.go:29).

I also checked that no legitimate route has a trailing slash or empty segment that the empty-element rule would now refuse: BandReadPath (tools_band_ops.go:157) builds /api/overview/<kind>.json with a fixed kind, and the fixed-path writes (/api/agents, /api/packs/level, /api/plan/from-issue, …) are all clean. Percent-encoded %2e%2e is decoded before comparison and is in the test table.

go build of pkg/adminmcp, cmd/hive-admin-mcp and pkg/dashboard passes on the head. Looks correct to me; no findings.

Evidence bundle `#16918df53fb6` sha256:544bfca253b5e6d673332276bbedddb3cdb92e33af140a5afd82104a8d58c8d5 β€” download from the dashboard or `hivectl review evidence #16918`.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:145 builds a plain http.Client{Timeout, Transport} with no CheckRedirect, 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 via httptest.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 other client.Do calls are fixed paths (:474 /api/status/summary, :505 /api/version) and the guarded ExecuteWrite (:314). On the dashboard side Read funnels into getβ†’getVerified or readDiag, both now guarded. WriteClient.ExecuteWrite has exactly one caller (pkg/adminmcp/adminmcp.go:561), after the new ConfirmWrite check, so dashboard writes are covered without touching dashboardAdminMCPProvider.ExecuteWrite.
  • CheckRequestPath only inspects the path before ?, so /api/logs/read?include=..&exclude=. stays allowed (tested), and single-level PathUnescape catches %2e%2e while leaving a double-encoded %252e%252e as the literal name %2e%2e, which the router does not clean.
  • go build ./pkg/adminmcp/ ./pkg/dashboard/ ./cmd/hive-admin-mcp/ on df53fb6 is 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

@hivecommons-hive
hivecommons-hive Bot merged commit 0033d8c into hivecommons:v6 Nov 6, 2026
72 of 75 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant