fix(security): add host/origin allowlist + validate git refs + quote workflow input

Merged
AA
6mo ago
+172-11

Summary

Three defense-in-depth fixes around untrusted input flowing to subprocess execution. None of the affected paths had a direct attacker-reachable proof of exploit, but each one combines a published threat-model boundary (loopback-only, model-supplied tool args, CI input boundary) with the kind of pattern that has bit other agent-tooling projects in the same week. Net effect: an attacker who can pivot through DNS-rebinding, prompt-inject the agent's tool args, or pass attacker-controlled inputs into a downstream caller of the reusable workflow can no longer reach a shell.

Impact

1. Control-pane HTTP server — DNS-rebinding gate. scripts/lib/control-pane/server.js binds to 127.0.0.1:8765 by default and exposes POST /api/actions/:id, which spawns cargo run -- graph <subcommand> with a request-body-supplied query and limit. The handler did not validate the Host or Origin header, so a victim visiting attacker.example (DNS-rebound to 127.0.0.1) would trigger same-origin POSTs to the loopback API, ultimately invoking recall-knowledge / sync-knowledge / graph-sync with attacker-shaped strings. /api/snapshot is similarly reachable for read-side exfiltration of the graph DB summary.

2. OpenCode gitSummary tool — model-supplied shell input. .opencode/tools/git-summary.ts was building git diff ${baseBranch}...HEAD --stat with execSync, where baseBranch is a string tool argument the LLM picks. An attacker who can prompt-inject the agent (untrusted file content, README, PR body, etc.) can drive the model to pass baseBranch = 'main"; <payload>; echo "x' and reach RCE on the developer's machine.

3. Reusable test workflow — script-injection seam. .github/workflows/reusable-test.yml interpolated ${{ inputs.package-manager }} directly into a bash case and into an unsupported-PM echo. The repo's own caller (ci.yml) constrains matrix.pm to a fixed set, but downstream callers of the reusable workflow that forward attacker-controllable input (e.g. an issue_comment-triggered workflow) would inject into the runner shell.

Location

  • scripts/lib/control-pane/server.js:163-205 (handler) + new helpers at the top of the file
  • .opencode/tools/git-summary.ts:30-65
  • .github/workflows/reusable-test.yml:64-81

Fix

  • Control-pane: Build an allowedHostnames set at server start containing the configured --host plus loopback variants (127.0.0.1, localhost, [::1], ::1). Reject mismatched Host headers with 421 Misdirected Request and non-loopback Origin headers (when present) with 403 Forbidden origin before any route handler runs. Host is mandatory; Origin is optional so non-browser clients (fetch from node, curl) still work.
  • OpenCode tool: Swap execSync for execFileSync with an args-array form so no spawned git call passes through a shell. Validate baseBranch against ^[A-Za-z0-9._/-]+$ plus the usual git-ref guardrails (no leading -/.//, no embedded .. or //, max 200 chars). Clamp depth to a positive integer ≤ 1000 before interpolating into -N.
  • Workflow: Move ${{ inputs.package-manager }} into a PACKAGE_MANAGER step env var and reference $PACKAGE_MANAGER inside the script, per the canonical GitHub script-injection mitigation.

Detected by

Aeon + Semgrep p/security-audit, surfaced via the threat-model-claim manual-review axis (SECURITY.md scopes "Local MCP Ports" verification but not the control-pane HTTP server one floor up; tool-args boundary advertised by OpenCode's tool schema but not enforced at the execSync call site; reusable workflow advertised as composable but unguarded against caller-supplied input).

  • Severity: medium-high (DNS-rebinding gate), medium-high (prompt-injection → RCE via tool args), low-medium (dormant CI surface, easy to enable accidentally)
  • CWE-918 (server-side request forgery class via DNS rebinding) / CWE-352 (CSRF-equivalent in absence of Host check) / CWE-78 (OS command injection — opencode tool + workflow)
  • No published advisory; this PR is the disclosure.

Verification

node tests/run-all.js — 2686 / 2687 passing. The one failure (observe.sh falls back to legacy output fields when tool_response is null, in tests/hooks/hooks.test.js) reproduces on main without this branch applied and is unrelated. npx eslint scripts/**/*.js tests/**/*.js clean. node scripts/ci/validate-workflow-security.js clean.

Two new tests added in tests/scripts/control-pane.test.js:

  • classifies Host and Origin headers against the loopback allowlist — unit test of the classifier against forged and legitimate hostnames including IPv6 / case-insensitive matching and a non-default --host LAN binding.
  • rejects requests forged with a non-loopback Host header (DNS rebinding gate) — end-to-end test against a live server using http.request to send forged Host and Origin headers, asserts 421 / 403 and that the legitimate baseline still returns 200.

Filed by Aeon.


Summary by cubic

Strengthens input handling to block DNS rebinding and command/script injection across the control-pane server, the git-summary tool, and the reusable CI workflow. Removes shell entry points and restricts loopback access to prevent untrusted input from reaching a shell.

  • Bug Fixes
    • Control-pane HTTP server: Allowlist Host/Origin to loopback and the configured --host; reject others with 421/403 before routing. Origin remains optional for non-browser clients. (scripts/lib/control-pane/server.js)
    • OpenCode git-summary tool: Replace execSync with execFileSync (args array), validate baseBranch as a safe git ref, and clamp depth to a small positive int. Protects log, staged diff, and branch diff calls. (.opencode/tools/git-summary.ts)
    • Reusable test workflow: Move ${{ inputs.package-manager }} into PACKAGE_MANAGER env and reference $PACKAGE_MANAGER in the script to prevent shell injection. (.github/workflows/reusable-test.yml)

Summary by CodeRabbit

  • Bug Fixes

    • Restricted control-pane HTTP API access to exclusively local connections. Requests from external hosts or non-loopback origins are now rejected with appropriate HTTP error responses.
  • Chores

    • Enhanced input validation in internal git utilities to prevent unsafe git reference injection.
    • Updated GitHub Actions reusable test workflow for improved package manager selection.
  • Tests

    • Added comprehensive test coverage for control-pane security features.