Skip to content

fix(exec): accept POSIX \<newline> in allowlisted commands; distinct error for unparseable syntax - #71154

Closed
scottgl9 wants to merge 2 commits into
openclaw:mainfrom
scottgl9:fix/exec-allowlist-line-continuations
Closed

scottgl9 wants to merge 2 commits into
openclaw:mainfrom
scottgl9:fix/exec-allowlist-line-continuations

Conversation

@scottgl9

Copy link
Copy Markdown
Contributor

Summary

  • Splice POSIX \<newline> line continuations before exec-allowlist analysis so multi-line invocations with an allowlisted leading binary resolve the same as their single-line form (fixes exec allowlist: multi-line (\<newline>) commands fail with "allowlist miss" even when binary is allowlisted #71153).
  • Disambiguate denial signals: when a command cannot be parsed, the gateway throws exec denied: unsupported shell syntax and the node host emits SYSTEM_RUN_DENIED: unsupported shell syntax with event reason unsupported-shell-syntax. allowlist miss is reserved for the true case where analysis succeeded but the resolved binary is not on the allowlist.
  • New joinShellLineContinuations helper walks the command once with the same quote/heredoc/comment state machine used by splitShellPipeline, so splicing respects single-quoted strings, quoted-heredoc bodies, and # comments. Inside double quotes and unquoted heredoc bodies, \<newline> is spliced (matching bash).

Why the old behavior

evaluateShellAllowlist() previously rejected any command containing \<newline> before analysis and emitted allowlist miss. Agents with allowlisted binaries but multi-line commands therefore concluded their binary was blocked (or the downstream service was down), and escalated incorrectly.

The comment at the old guard noted a concern that line-continuation semantics "can rewrite token boundaries at runtime". POSIX 2.2.1 is unambiguous: outside single-quotes and outside quoted-heredoc bodies, \<newline> is removed before tokenization. Pre-splicing produces exactly the tokens the shell would see, so the allowlist decision cannot drift between analyzer and runtime — provided the splicing walker respects single-quote and quoted-heredoc exceptions, which it does.

Key files

  • src/infra/exec-approvals-analysis.ts — new joinShellLineContinuations helper, parseHeredocDelimiter lifted to module scope for reuse.
  • src/infra/exec-approvals-allowlist.ts — drop the early-reject, normalize via joinShellLineContinuations before analysis.
  • src/agents/bash-tools.exec-host-gateway.ts — split error-string path: unsupported-shell-syntax vs allowlist-miss.
  • src/node-host/exec-policy.ts, src/node-host/invoke-system-run.ts, src/agents/exec-approval-result.ts — matching reason/message additions.

Test plan

  • New src/infra/exec-approvals-allowlist.test.ts: multi-line allowlisted curl with \<LF> and \<CRLF> resolves identically to single-line; non-allowlisted binary still misses cleanly; direct joinShellLineContinuations unit tests cover quote state, comments, heredoc bodies (quoted and unquoted), unterminated quote fallback, and CRLF.
  • Extended src/agents/bash-tools.exec-host-gateway.test.ts: new assertion that unparseable input throws the distinct exec denied: unsupported shell syntax message while the true allowlist-miss case still throws the original string.
  • Extended src/node-host/exec-policy.test.ts: parallel coverage for SYSTEM_RUN_DENIED: unsupported shell syntax with eventReason: "unsupported-shell-syntax".
  • pnpm check:changed green (typecheck, lint, import cycles, changed-test lanes).
  • Targeted regression sweep across pi-tools.safe-bins, exec-approvals-parity, exec-approvals-safe-bins, exec-approvals-policy, invoke-system-run, server-node-events, and exec-approval-result suites: all passing.

Risk notes

  • Parity with runtime shell: POSIX line-continuation splicing happens before word-splitting. The walker respects single-quotes, quoted heredocs, and # comments, so splicing matches bash semantics.
  • Rollback: additive helper + one branch swap in evaluateShellAllowlist + one error-string split; small diff.
  • No command that previously succeeded changes outcome; only commands previously rejected as "allowlist miss" can now either succeed (multi-line with allowlisted binary) or emit the clearer unsupported shell syntax signal.

Fixes #71153.

The exec allowlist previously hard-rejected any command containing
`\<newline>` (POSIX line continuation) before analysis. The gateway and
node-host then surfaced that rejection as `exec denied: allowlist miss`
(or `SYSTEM_RUN_DENIED: allowlist miss`), indistinguishable from a true
unapproved-binary denial. Agents that issued legitimate multi-line
`curl`/`ssh`/etc. invocations with allowlisted binaries concluded their
binary was blocked or the downstream service was down and escalated
incorrectly.

Instead of rejecting, splice `\<newline>` before tokenization in
`evaluateShellAllowlist` via a new `joinShellLineContinuations` helper
that walks the command with the same quote/heredoc/comment state machine
used by `splitShellPipeline`. Splicing matches POSIX 2.2.1: outside
single-quotes and outside quoted-heredoc bodies, `\<newline>` is removed
(joining the lines); inside single-quotes and `#` comments it is
preserved verbatim. After splicing, downstream analysis sees exactly the
tokens the shell would, so the allowlist decision cannot drift between
analyzer and runtime.

Also disambiguate the denial signal: when the command cannot be parsed
(inside or outside allowlist mode), the gateway now throws
`exec denied: unsupported shell syntax` and the node-host emits
`SYSTEM_RUN_DENIED: unsupported shell syntax` with event reason
`unsupported-shell-syntax`. `allowlist miss` is reserved for the
true case where analysis succeeded but the resolved binary is not on
the allowlist.

Tests: new `exec-approvals-allowlist.test.ts` covers the helper and the
multi-line-resolves-identically case; gateway and node-host policy tests
pick up the new error branch.
@aisle-research-bot

aisle-research-bot Bot commented Apr 24, 2026 •

Copy link
Copy Markdown

🔒 Aisle Security Analysis

We found 1 potential security issue(s) in this PR:

# Severity Title
1 🟠 High Durable approvals bypass allowlist denial for unparseable shell commands (analysisOk=false)
1. 🟠 Durable approvals bypass allowlist denial for unparseable shell commands (analysisOk=false)
Property Value
Severity High
CWE CWE-285
Location src/node-host/exec-policy.ts:123-149

Description

In allowlist mode, commands that fail allowlist analysis (analysisOk=false, e.g. unsupported/unparseable shell syntax) are intended to be denied. However, the new denial reason classification (unsupported-shell-syntax) is only applied when no durable approval is satisfied. If a durable approval exists, the policy returns allowed: true even when analysisOk=false, allowing execution of un-analyzable shell content.

This creates a policy bypass path:

  • Input: attacker-controlled or user-provided command string containing unsupported/unparseable shell syntax, resulting in analysisOk=false
  • Shortcut: if durableApprovalSatisfied is true (e.g., an exact-command durable approval persisted earlier), requiresExecApproval returns false and evaluateSystemRunPolicy allows execution
  • Sink: command proceeds to execution despite failing analysis/allowlist parsing

Relevant code (allowing execution when durableApprovalSatisfied is true even under allowlist miss conditions):

if (params.security === "allowlist" && (!analysisOk || !allowlistSatisfied) && !approvedByAsk) {
  if (params.durableApprovalSatisfied) {
    return { allowed: true, ... };
  }
  if (!analysisOk && !shellWrapperBlocked) {
    return { allowed: false, eventReason: "unsupported-shell-syntax", ... };
  }
  return { allowed: false, eventReason: "allowlist-miss", ... };
}

The same bypass exists at the gateway layer because hasGatewayAllowlistMiss is conditioned on !durableApprovalSatisfied, so resolveGatewayDeniedReason() returns null when durable approval is satisfied, even when analysisOk=false.

Impact depends on threat model, but in typical "allowlist" deployments this undermines the safety guarantee that only analyzable/allowlisted shell commands run; a previously persisted durable approval (especially exact-command based) can enable execution of commands whose syntax cannot be analyzed or segmented, which may also defeat inline-eval/segment-based controls.

Recommendation

Make analysisOk=false a hard deny in allowlist mode, regardless of durableApprovalSatisfied, unless there is an explicit, tightly-scoped override that is clearly surfaced to the user.

For example:

if (params.security === "allowlist" && !analysisOk && !shellWrapperBlocked) {
  return {
    allowed: false,
    eventReason: "unsupported-shell-syntax",
    errorMessage: formatSystemRunUnsupportedShellSyntaxMessage(),
    ...
  };
}

if (params.security === "allowlist" && !allowlistSatisfied && !approvedByAsk) {
  if (params.durableApprovalSatisfied) {
    return { allowed: true, ... };
  }
  return { allowed: false, eventReason: "allowlist-miss", ... };
}

Also align gateway logic (hasGatewayAllowlistMiss / resolveGatewayDeniedReason) to deny when analysisOk=false even if a durable approval exists (or explicitly document and gate that behavior).


Analyzed PR: #71154 at commit b1c80c3

Last updated on: 2026-04-24T15:46:06Z

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L labels Apr 24, 2026
@greptile-apps

greptile-apps Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes multi-line shell command handling in the exec allowlist by splicing POSIX \<newline> continuations before analysis (replacing the former blanket rejection), and disambiguates parse failures from true allowlist misses with a new unsupported-shell-syntax error signal propagated through gateway, node-host policy, and event reason layers. The change is well-scoped, additive, and the fallback path (returning the original command on unterminated state) preserves safety for malformed input.

Confidence Score: 5/5

Safe to merge; the one identified issue is a narrow edge case with no security impact.

All findings are P2. The heredocLine reset in the unquoted heredoc continuation path is a correctness issue for the contrived case of a heredoc terminator split by \<newline>, but it cannot cause a security bypass — downstream analysis would fail and surface unsupported-shell-syntax. No previously accepted commands change outcome.

src/infra/exec-approvals-analysis.ts — the heredocLine = "" reset inside the unquoted-heredoc continuation branch.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/infra/exec-approvals-analysis.ts
Line: 179-186

Comment:
When a `\<newline>` continuation is encountered inside an **unquoted heredoc body**, `heredocLine` is reset to `""` instead of preserving the content accumulated so far on the same logical line. This means a heredoc terminator that is itself split across lines (e.g. `EO\<LF>F` for `<<EOF`) is never recognized as the terminator: after the reset, only `F` is accumulated, the delimiter check `"F" === "EOF"` fails, and the parser continues treating subsequent lines as heredoc body. This does not cause a security bypass (downstream analysis would fail, producing `unsupported-shell-syntax`) but causes a confusing result for any command that uses a continuation inside a heredoc terminator row.

```suggestion
      if (current && !current.quoted) {
        const skip = isContinuation(i);
        if (skip) {
          // Do NOT reset heredocLine: the continuation joins lines, so the
          // characters already accumulated on this logical line must be kept
          // to correctly detect a delimiter like "EO\<LF>F" for <<EOF.
          i += skip;
          continue;
        }
      }
```

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

Reviews (1): Last reviewed commit: "fix(exec): accept POSIX line continuatio..." | Re-trigger Greptile

Comment thread src/infra/exec-approvals-analysis.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4e64cf5bc0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/infra/exec-approvals-analysis.ts Resolved
Review feedback on openclaw#71154:

- Do not reset the accumulated heredoc logical line when splicing a
  `\<newline>` inside an unquoted heredoc body. Bash joins the lines,
  so a terminator whose characters are split across a continuation
  (`EO\<LF>F` for `<<EOF`) should still terminate the heredoc, and
  conversely a continued body line whose tail happens to equal the
  delimiter (`foo \<LF>EOF`) should *not* terminate. The previous code
  cleared `heredocLine` on splice and mis-classified both edges.
  (Greptile / Codex reviews.)

- Build the output and heredoc-line buffers via `string[]` +
  `join("")` instead of `+=` concatenation in a loop, so very large
  commands (big heredoc bodies) stay linear regardless of engine
  concatenation strategy. (Aisle security review.)

Tests extended: new cases for the `EO\<LF>F` terminator and the
`foo \<LF>EOF` non-terminator edges.
@scottgl9

Copy link
Copy Markdown
Contributor Author

Addressed the Aisle Security flag in b1c80c3: joinShellLineContinuations now builds its output via string[] + join("") for both the output buffer and the per-line heredoc accumulator, so growth stays linear on large commands regardless of engine-specific concat optimizations. No input-size cap added — the helper is only ever called on commands already delivered through the agent pipeline where upstream size limits apply.

@clawsweeper

clawsweeper Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded: the merged planner rewrite now owns POSIX exec authorization and intentionally treats line-continuation syntax as unplanned/approval-gated, so this stale legacy-parser splice should not remain a landing candidate.

Root-cause cluster
Relationship: superseded
Canonical: #84172
Summary: The merged planner PR now owns the command-authorization boundary this PR attempted to patch in the legacy parser.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Keep the shipped planner policy as canonical; if maintainers want to accept line continuations later, implement it as a new planner-scoped, security-reviewed PR with real exec proof.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Keep the shipped planner policy as canonical; if maintainers want to accept line continuations later, implement it as a new planner-scoped, security-reviewed PR with real exec proof.

Do we have a high-confidence way to reproduce the issue?

Yes by source inspection: current main marks line-continuation shell commands as an unanalyzable planner risk and tests assert they stay out of allow-always approval. I did not run live exec in this read-only review.

Is this the best way to solve the issue?

No. This was a plausible old-parser fix, but the best current path is either the shipped planner policy or a new planner-scoped change, not reviving join-before-analysis in the legacy allowlist analyzer.

Security review:

Security review needs attention: The diff touches the exec authorization boundary and conflicts with shipped planner policy for line-continuation syntax.

  • [medium] Legacy splice bypasses planner authorization — src/infra/exec-approvals-allowlist.ts:1094
    The branch splices backslash-newline before legacy allowlist analysis, while current main treats the same syntax as an unplanned command requiring approval rather than reusable allowlist execution.
    Confidence: 0.88
  • [medium] Unsupported syntax is not hard-denied before durable trust — src/node-host/exec-policy.ts:136
    The new unsupported-shell-syntax denial branch is reached after durableApprovalSatisfied can allow the command, so analysisOk=false is not a hard deny in the branch's node-host policy.
    Confidence: 0.76

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy read: Root AGENTS.md was read fully and applied; scoped src/agents/AGENTS.md was also read because the PR touches agent exec gateway code. (AGENTS.md:1, 8ed6c78b7891)
  • Current main planner boundary: Current main routes non-Windows shell allowlist evaluation through planShellAuthorization before allowlist evaluation, so the old POSIX parser path patched by this PR is no longer the owner boundary. (src/infra/exec-approvals-allowlist.ts:1344, 8ed6c78b7891)
  • Current main line-continuation policy: Current main includes line-continuation in the planner's unanalyzable risks, making it an approval/planner risk rather than a reusable allowlisted shell form. (src/infra/exec-authorization-plan.ts:98, 8ed6c78b7891)
  • Current regression coverage: Current tests assert that line-continuation shell commands produce analysisOk=false with authorizationPlan reason line-continuation and stay out of allow-always approval. (src/infra/exec-authorization-allowlist.test.ts:156, 8ed6c78b7891)
  • Submitted branch conflicts with current policy: The PR branch normalizes backslash-newline continuations before legacy allowlist analysis, the opposite of current planner policy. (src/infra/exec-approvals-allowlist.ts:1094, b1c80c38fa05)
  • Branch security concern: The branch's unsupported-shell-syntax denial is reached after durableApprovalSatisfied can allow an analysisOk=false command, so the new denial is not a hard deny. (src/node-host/exec-policy.ts:136, b1c80c38fa05)

Likely related people:

  • jesse-merhi: Authored the merged planner rewrite that now owns POSIX command authorization, line-continuation risk classification, allow-always persistence, and gateway approval behavior. (role: recent area contributor; confidence: high; commits: c9707ab635b9; files: src/infra/exec-authorization-plan.ts, src/infra/exec-authorization-allowlist.test.ts, src/infra/exec-approvals-allowlist.ts)
  • steipete: The original fail-closed line-continuation guard this branch tried to relax appears in the security hardening commit for shell-wrapper line-continuation bypasses. (role: earlier exec allowlist security contributor; confidence: medium; commits: 3f0b9dbb36c8; files: src/infra/exec-approvals-allowlist.ts, src/infra/exec-approvals-analysis.ts)

Codex review notes: model internal, reasoning high; reviewed against 8ed6c78b7891.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels May 20, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 20, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels May 20, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added stale Marked as stale due to inactivity and removed stale Marked as stale due to inactivity labels Jun 14, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Jun 29, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jun 29, 2026
@steipete steipete closed this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

exec allowlist: multi-line (\<newline>) commands fail with "allowlist miss" even when binary is allowlisted

2 participants