Repository navigation
fix(security): add host/origin allowlist + validate git refs + quote workflow input - #2185
Conversation
…workflow input
Three defense-in-depth fixes around untrusted input flowing to subprocess execution:
1. **Control-pane HTTP server (scripts/lib/control-pane/server.js)**
The local control-pane API binds to 127.0.0.1 but had no Host or Origin
validation, so a DNS-rebinding attack from a malicious website could pivot
into the loopback endpoints — including POST /api/actions/:id, which spawns
'cargo run -- graph ...' with caller-supplied query strings. Add a hostname
allowlist (loopback variants plus the explicitly configured --host) and
reject mismatched Host (421) or non-loopback Origin (403) before any route
handler runs.
2. **OpenCode git-summary tool (.opencode/tools/git-summary.ts)**
The tool was building 'git diff ${baseBranch}...HEAD --stat' with execSync
and a raw model-supplied baseBranch string. Switch run() to execFileSync
with an args array (no shell), validate baseBranch against a conservative
git-ref allowlist (rejects shell metacharacters, leading -, embedded ..),
and clamp the depth arg to a small positive integer before interpolating
into 'git log --oneline -<N>'.
3. **Reusable test workflow (.github/workflows/reusable-test.yml)**
The 'Install dependencies' step interpolated ${{ inputs.package-manager }}
directly into a bash 'case' and into an echo, so a downstream caller that
forwarded attacker-controllable input could inject into the runner. Move
the input into a PACKAGE_MANAGER env var and reference $PACKAGE_MANAGER
inside the script per the GitHub script-injection guidance.
Detected by Aeon + semgrep p/security-audit (host check via threat-model
manual-review axis; git-summary via detect-child-process; workflow via
run-shell-injection).
Verification: node tests/run-all.js — 2686/2687 pre-existing tests pass; the
one failure (observe.sh legacy output fallback) reproduces on main without
this branch applied. Added 2 new control-pane tests covering the allowlist
classifier and the DNS-rebinding-gate behavior end-to-end.
---
Filed by [Aeon](https://github.com/aaronjmars/aeon-aaron).
|
ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR. |
📝 WalkthroughWalkthroughThis PR adds three independent security and robustness improvements: a package-manager variable refactoring in the CI workflow, input validation and safer command execution in the git-summary tool, and HTTP request allowlisting for the control-pane server with matching test coverage. ChangesPackage Manager Variable Refactoring
Git Tool Input Validation and Safer Execution
Control-Pane HTTP Request Allowlisting
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. 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 (2)
.opencode/tools/git-summary.ts (1)
70-76: 💤 Low valueConsider optional debug logging for failed git commands.
The empty-string fallback is a reasonable graceful-degradation strategy for tooling, and calling code handles it well. For debugging difficult environments (missing git, permission issues), you could optionally log to stderr at debug level, though this is not blocking.
💡 Optional: Add debug visibility
function runArgs(args: string[], cwd: string): string { try { return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim() - } catch { + } catch (err) { + // Uncomment for debugging: console.error(`git ${args[0]} failed:`, err) return "" } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.opencode/tools/git-summary.ts around lines 70 - 76, The runArgs function swallows all errors and returns an empty string; add optional debug logging in the catch to surface the underlying error when debug mode is enabled. Modify runArgs to accept or read a debug flag (or use an existing logger) and in the catch block log a debug-level message containing the args, cwd and the caught error before returning ""; reference the runArgs function and the execFileSync call so the change is limited to that function's catch handling.scripts/lib/control-pane/server.js (1)
12-12: Add IPv4-mapped IPv6 loopback hostnames toLOOPBACK_HOSTNAMES
scripts/lib/control-pane/server.jscurrently allows only127.0.0.1,localhost,[::1], and::1. On dual-stack systems, local connections may present::ffff:127.0.0.1;parseHostHeader()expects the bracketed form forHost([::ffff:127.0.0.1]), whileisAllowedOrigin()expects the unbracketed form forOrigin(::ffff:127.0.0.1). Adding both to the allowlist (or normalizing::ffff:127.0.0.1→127.0.0.1) avoids incorrectly rejecting local requests with 421/403.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@scripts/lib/control-pane/server.js` at line 12, LOOPBACK_HOSTNAMES currently lacks IPv4-mapped IPv6 entries, causing local dual-stack requests like ::ffff:127.0.0.1 to be rejected; update the allowlist used by parseHostHeader() and isAllowedOrigin() by adding both the bracketed and unbracketed IPv4-mapped forms (e.g. '[::ffff:127.0.0.1]' and '::ffff:127.0.0.1') or normalize mapped addresses to '127.0.0.1' before checks; modify the Set named LOOPBACK_HOSTNAMES to include these entries (or add a small normalization helper called from parseHostHeader() and isAllowedOrigin()) so local dual-stack requests are accepted.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In @.opencode/tools/git-summary.ts:
- Around line 70-76: The runArgs function swallows all errors and returns an
empty string; add optional debug logging in the catch to surface the underlying
error when debug mode is enabled. Modify runArgs to accept or read a debug flag
(or use an existing logger) and in the catch block log a debug-level message
containing the args, cwd and the caught error before returning ""; reference the
runArgs function and the execFileSync call so the change is limited to that
function's catch handling.
In `@scripts/lib/control-pane/server.js`:
- Line 12: LOOPBACK_HOSTNAMES currently lacks IPv4-mapped IPv6 entries, causing
local dual-stack requests like ::ffff:127.0.0.1 to be rejected; update the
allowlist used by parseHostHeader() and isAllowedOrigin() by adding both the
bracketed and unbracketed IPv4-mapped forms (e.g. '[::ffff:127.0.0.1]' and
'::ffff:127.0.0.1') or normalize mapped addresses to '127.0.0.1' before checks;
modify the Set named LOOPBACK_HOSTNAMES to include these entries (or add a small
normalization helper called from parseHostHeader() and isAllowedOrigin()) so
local dual-stack requests are accepted.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 009ed015-18bf-418c-a16c-451199d18003
📒 Files selected for processing (4)
.github/workflows/reusable-test.yml.opencode/tools/git-summary.tsscripts/lib/control-pane/server.jstests/scripts/control-pane.test.js
|
🤖 Bezalel Engine — Automated Code Review PR #2185 Code Review1. SummaryThree defense-in-depth security fixes:
These are legitimate, well |
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.jsbinds to127.0.0.1:8765by default and exposesPOST /api/actions/:id, which spawnscargo run -- graph <subcommand>with a request-body-suppliedqueryandlimit. The handler did not validate theHostorOriginheader, so a victim visitingattacker.example(DNS-rebound to127.0.0.1) would trigger same-origin POSTs to the loopback API, ultimately invokingrecall-knowledge/sync-knowledge/graph-syncwith attacker-shaped strings./api/snapshotis similarly reachable for read-side exfiltration of the graph DB summary.2. OpenCode
gitSummarytool — model-supplied shell input..opencode/tools/git-summary.tswas buildinggit diff ${baseBranch}...HEAD --statwithexecSync, wherebaseBranchis astringtool argument the LLM picks. An attacker who can prompt-inject the agent (untrusted file content, README, PR body, etc.) can drive the model to passbaseBranch = 'main"; <payload>; echo "x'and reach RCE on the developer's machine.3. Reusable test workflow — script-injection seam.
.github/workflows/reusable-test.ymlinterpolated${{ inputs.package-manager }}directly into a bashcaseand into an unsupported-PMecho. The repo's own caller (ci.yml) constrainsmatrix.pmto a fixed set, but downstream callers of the reusable workflow that forward attacker-controllable input (e.g. anissue_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-81Fix
allowedHostnamesset at server start containing the configured--hostplus loopback variants (127.0.0.1,localhost,[::1],::1). Reject mismatchedHostheaders with421 Misdirected Requestand non-loopbackOriginheaders (when present) with403 Forbidden originbefore any route handler runs.Hostis mandatory;Originis optional so non-browser clients (fetchfromnode,curl) still work.execSyncforexecFileSyncwith an args-array form so no spawnedgitcall passes through a shell. ValidatebaseBranchagainst^[A-Za-z0-9._/-]+$plus the usual git-ref guardrails (no leading-/.//, no embedded..or//, max 200 chars). Clampdepthto a positive integer ≤ 1000 before interpolating into-N.${{ inputs.package-manager }}into aPACKAGE_MANAGERstep env var and reference$PACKAGE_MANAGERinside 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).
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, intests/hooks/hooks.test.js) reproduces onmainwithout this branch applied and is unrelated.npx eslint scripts/**/*.js tests/**/*.jsclean.node scripts/ci/validate-workflow-security.jsclean.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--hostLAN binding.rejects requests forged with a non-loopback Host header (DNS rebinding gate)— end-to-end test against a live server usinghttp.requestto send forgedHostandOriginheaders, asserts421/403and that the legitimate baseline still returns200.Filed by Aeon.
Summary by cubic
Strengthens input handling to block DNS rebinding and command/script injection across the control-pane server, the
git-summarytool, and the reusable CI workflow. Removes shell entry points and restricts loopback access to prevent untrusted input from reaching a shell.Host/Originto loopback and the configured--host; reject others with 421/403 before routing.Originremains optional for non-browser clients. (scripts/lib/control-pane/server.js)git-summarytool: ReplaceexecSyncwithexecFileSync(args array), validatebaseBranchas a safe git ref, and clampdepthto a small positive int. Protectslog, staged diff, and branch diff calls. (.opencode/tools/git-summary.ts)${{ inputs.package-manager }}intoPACKAGE_MANAGERenv and reference$PACKAGE_MANAGERin the script to prevent shell injection. (.github/workflows/reusable-test.yml)Written for commit 56bd1bd. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
Chores
Tests