Skip to content

Security: block exec host overrides when tools.exec.host is auto#58897

Merged
steipete merged 4 commits into
mainfrom
codex/fix-exec-host-override-vulnerability
Apr 2, 2026
Merged

Security: block exec host overrides when tools.exec.host is auto#58897
steipete merged 4 commits into
mainfrom
codex/fix-exec-host-override-vulnerability

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Motivation

  • Fix a sandbox-bypass regression where configuredTarget = "auto" acted like a wildcard allowlist and model-supplied host=gateway|node could force execution on the gateway/node host, escaping sandbox isolation.

Description

  • Tighten exec target authorization by changing isRequestedExecTargetAllowed to only permit a requested target when it exactly matches the configured target (remove the previous special-case that allowed auto).
  • Keep elevated requests (elevatedRequested) behavior unchanged (still select gateway).
  • Update the runtime unit test in src/agents/bash-tools.exec-runtime.test.ts to assert that host overrides are rejected when configuredTarget is auto.
  • Add an internal investigation note at docs/internal/codex/2026-03-29-exec-target-override-fix.md documenting the issue and the remediation.

Testing

  • Ran the targeted unit test: pnpm test -- src/agents/bash-tools.exec-runtime.test.ts, which passed (1 test file, 12 tests).
  • Ran the project pre-commit verification via the committer flow (which triggers pnpm check), and the checks completed with no errors.

Codex Task

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: XS maintainer Maintainer-authored PR labels Apr 1, 2026
@greptile-apps

greptile-apps Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a sandbox-bypass regression by tightening isRequestedExecTargetAllowed: the previous auto-wildcard shortcut allowed any model-supplied host value to be accepted when the operator had configured tools.exec.host=auto, effectively making auto an open allowlist. The fix reduces the function to a strict equality check, so a requested target must exactly match the configured target; anything else throws \"exec host not allowed\". The implementation change is correct and the unit test is updated to assert the new throw behaviour.

  • Security logic is sound \u2014 removing the auto wildcard is the right fail-closed default; auto resolution now falls back to sandbox/gateway automatically without trusting model-supplied overrides.
  • Misleading error message hint \u2014 the resolveExecTarget throw references configuredTarget in the "configure to allow" hint, so when configuredTarget === \"auto\" the message says configure tools.exec.host=auto to allow \u2014 which is already the current setting. Using requestedTarget in the hint would give actionable guidance.
  • Thin test coverage \u2014 the new test covers requestedTarget: \"node\" but not the symmetrical gateway override or the still-valid auto\u2192auto pass-through case.
  • elevatedRequested path not addressed \u2014 the elevatedRequested: true branch still bypasses the target check and hard-selects gateway; this is out of scope and intentional, but operators should be aware a model-supplied elevated=true can still route to the gateway host."

Confidence Score: 5/5

Safe to merge — the security fix is correct and no regressions are introduced; remaining findings are P2 quality/UX suggestions.

The core logic change is simple, correct, and well-targeted. Both findings are P2: the error message hint is cosmetic/informational and the test gaps are minor coverage improvements rather than evidence of broken behaviour. No P0/P1 issues found.

No files require special attention for merge safety, but src/agents/bash-tools.exec-runtime.ts lines 248–251 contain the misleading error message worth fixing in a follow-up.

Comments Outside Diff (1)

  1. src/agents/bash-tools.exec-runtime.ts, line 248-251 (link)

    P2 Misleading "configure to allow" hint in error message

    The error message tells users configure tools.exec.host=auto to allow when configuredTarget is "auto" — but auto is already the configured value and explicitly does not allow host overrides after this fix. The hint should name the requestedTarget so the user knows which concrete value to set:

    Before this PR, auto would never reach this throw; the change makes this code path reachable for the first time, exposing the pre-existing misleading hint.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/agents/bash-tools.exec-runtime.ts
    Line: 248-251
    
    Comment:
    **Misleading "configure to allow" hint in error message**
    
    The error message tells users `configure tools.exec.host=auto to allow` when `configuredTarget` is `"auto"` — but `auto` is _already_ the configured value and explicitly does **not** allow host overrides after this fix. The hint should name the `requestedTarget` so the user knows which concrete value to set:
    
    
    
    Before this PR, `auto` would never reach this throw; the change makes this code path reachable for the first time, exposing the pre-existing misleading hint.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/bash-tools.exec-runtime.ts
Line: 248-251

Comment:
**Misleading "configure to allow" hint in error message**

The error message tells users `configure tools.exec.host=auto to allow` when `configuredTarget` is `"auto"` — but `auto` is _already_ the configured value and explicitly does **not** allow host overrides after this fix. The hint should name the `requestedTarget` so the user knows which concrete value to set:

```suggestion
    throw new Error(
      `exec host not allowed (requested ${renderExecTargetLabel(requestedTarget)}; ` +
        `configure tools.exec.host=${renderExecTargetLabel(requestedTarget)} to allow).`,
    );
```

Before this PR, `auto` would never reach this throw; the change makes this code path reachable for the first time, exposing the pre-existing misleading hint.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/agents/bash-tools.exec-runtime.test.ts
Line: 50-59

Comment:
**Narrow test coverage for the new restriction**

The single test only asserts that `requestedTarget: "node"` is rejected. The symmetrical `gateway` override (`requestedTarget: "gateway"`) and the still-valid `auto``auto` pass-through are not exercised. Consider adding:

```ts
it("also rejects gateway override when configured host is auto", () => {
  expect(() =>
    resolveExecTarget({
      configuredTarget: "auto",
      requestedTarget: "gateway",
      elevatedRequested: false,
      sandboxAvailable: true,
    }),
  ).toThrow("exec host not allowed");
});

it("allows explicit auto request when configured host is auto", () => {
  expect(
    resolveExecTarget({
      configuredTarget: "auto",
      requestedTarget: "auto",
      elevatedRequested: false,
      sandboxAvailable: true,
    }),
  ).toMatchObject({ selectedTarget: "auto", effectiveHost: "sandbox" });
});
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Merge branch 'main' into codex/fix-exec-..." | Re-trigger Greptile

Comment on lines +50 to 59
it("rejects host overrides when configured host is auto", () => {
expect(() =>
resolveExecTarget({
configuredTarget: "auto",
requestedTarget: "node",
elevatedRequested: false,
sandboxAvailable: false,
}),
).toMatchObject({
configuredTarget: "auto",
selectedTarget: "node",
effectiveHost: "node",
});
).toThrow("exec host not allowed");
});

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.

P2 Narrow test coverage for the new restriction

The single test only asserts that requestedTarget: "node" is rejected. The symmetrical gateway override (requestedTarget: "gateway") and the still-valid autoauto pass-through are not exercised. Consider adding:

it("also rejects gateway override when configured host is auto", () => {
  expect(() =>
    resolveExecTarget({
      configuredTarget: "auto",
      requestedTarget: "gateway",
      elevatedRequested: false,
      sandboxAvailable: true,
    }),
  ).toThrow("exec host not allowed");
});

it("allows explicit auto request when configured host is auto", () => {
  expect(
    resolveExecTarget({
      configuredTarget: "auto",
      requestedTarget: "auto",
      elevatedRequested: false,
      sandboxAvailable: true,
    }),
  ).toMatchObject({ selectedTarget: "auto", effectiveHost: "sandbox" });
});
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/bash-tools.exec-runtime.test.ts
Line: 50-59

Comment:
**Narrow test coverage for the new restriction**

The single test only asserts that `requestedTarget: "node"` is rejected. The symmetrical `gateway` override (`requestedTarget: "gateway"`) and the still-valid `auto``auto` pass-through are not exercised. Consider adding:

```ts
it("also rejects gateway override when configured host is auto", () => {
  expect(() =>
    resolveExecTarget({
      configuredTarget: "auto",
      requestedTarget: "gateway",
      elevatedRequested: false,
      sandboxAvailable: true,
    }),
  ).toThrow("exec host not allowed");
});

it("allows explicit auto request when configured host is auto", () => {
  expect(
    resolveExecTarget({
      configuredTarget: "auto",
      requestedTarget: "auto",
      elevatedRequested: false,
      sandboxAvailable: true,
    }),
  ).toMatchObject({ selectedTarget: "auto", effectiveHost: "sandbox" });
});
```

How can I resolve this? If you propose a fix, please make it concise.

@vincentkoc vincentkoc self-assigned this Apr 1, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

Addressed the review in follow-up commit 8eb3fd1.

What changed:

  • keep the stricter auto-host override guard
  • add the missing gateway override regression case
  • add the missing auto-to-auto pass-through case
  • tighten the error hint so it points at the requested host the caller would need to configure, not the already-configured host
  • drop the extra internal markdown file from the PR

Verification:

  • pnpm test -- src/agents/bash-tools.exec-runtime.test.ts
  • pnpm check

@openclaw-barnacle openclaw-barnacle Bot removed the docs Improvements or additions to documentation label Apr 1, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

Added the missing changelog entry in follow-up commit a5f828bdec.

@steipete
steipete force-pushed the codex/fix-exec-host-override-vulnerability branch from 3aecad3 to 52a0723 Compare April 2, 2026 17:25
@steipete
steipete requested a review from a team as a code owner April 2, 2026 17:25
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S and removed size: XS labels Apr 2, 2026
@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord channel: slack Channel integration: slack app: android App: android gateway Gateway runtime size: XL and removed size: S labels Apr 2, 2026
@steipete
steipete force-pushed the codex/fix-exec-host-override-vulnerability branch from 615325e to 68c3945 Compare April 2, 2026 17:36
@openclaw-barnacle openclaw-barnacle Bot removed the channel: discord Channel integration: discord label Apr 2, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: S and removed channel: slack Channel integration: slack app: android App: android gateway Gateway runtime size: XL labels Apr 2, 2026
@steipete
steipete merged commit 45c8207 into main Apr 2, 2026
9 checks passed
@steipete
steipete deleted the codex/fix-exec-host-override-vulnerability branch April 2, 2026 17:37
@steipete

steipete commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Landed via temp rebase onto main.

  • Gate: pnpm check && pnpm build && pnpm test
  • Land commit: 68c3945
  • Merge commit: 45c8207

Thanks @vincentkoc!

steipete added a commit to duncanita/openclaw that referenced this pull request Apr 4, 2026
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aardvark agents Agent runtime and tooling codex docs Improvements or additions to documentation maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants