Repository navigation
fix(macos): align exec command parity - #50386
Conversation
🔒 Aisle Security AnalysisWe found 1 potential security issue(s) in this PR:
1. 🟡 PATH-based allowlist broadening via busybox/toybox shell applet unwrapping
Description
This can cause persisted allowlist entries (created when a user selects Allow Always) to be generated for an executable resolved via Impact:
Vulnerable code (key behavior): if let shellMultiplexer = self.unwrapShellMultiplexerInvocation(command) {
self.collectAllowAlwaysPatterns(command: shellMultiplexer, ...)
}
...
return Array(argv[appletIndex...]) // starts with applet like "sh", dropping busybox/toyboxRecommendationAvoid generating allowlist patterns based on a PATH-resolved applet name when the actual invoked binary is Safer options:
Example mitigation sketch (preserve wrapper path for persistence): // Instead of returning ["sh", ...], keep the wrapper identity
// and treat it as the allowlist target.
private static func unwrapShellMultiplexerInvocation(_ argv: [String]) -> (wrapperArgv: [String], applet: String)? {
...
return (wrapperArgv: argv, applet: normalizedApplet)
}
// In collectAllowAlwaysPatterns, when busybox/toybox is detected:
// - add allowlist pattern for resolved busybox/toybox path
// - optionally parse the applet-specific flags/payload to add additional patternsAnalyzed PR: #50386 at commit Last updated on: 2026-03-19T12:19:55Z |
Greptile SummaryThis PR aligns the macOS Swift exec-command suite with the shared TypeScript contract by separating two previously conflated concerns: allowlist evaluation (which executable to match against in the allowlist, now preserving Key changes:
Confidence Score: 4/5
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1ae64b67b2
ℹ️ 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".
|
@chatgpt-codex-connector @greptile-apps pushed follow-up fixes in Verification rerun on the updated branch:
Please take another look at the latest commit when available. |
| guard depth < 3, !command.isEmpty else { | ||
| return | ||
| } |
There was a problem hiding this comment.
Silent pattern truncation at depth limit
When depth == 3, collectAllowAlwaysPatterns returns without collecting any pattern and without any indication to the caller. A realistic chain that hits this limit: busybox ash -c "busybox sh -c 'something'" — busybox unwrap (0→1), shell detection + segment split (1→2), inner busybox unwrap (2→3), inner shell segment (blocked at 3).
The limit is a sound DoS guard, but silently dropping patterns means the allow-always store may be incomplete for deeply nested commands that are genuinely approved. Consider at minimum logging a debug trace when the guard fires so test failures or production mismatches are diagnosable. A // depth guard: deliberate DoS protection comment would also help future readers understand this isn't accidental.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/macos/Sources/OpenClaw/ExecCommandResolution.swift
Line: 129-131
Comment:
**Silent pattern truncation at depth limit**
When `depth == 3`, `collectAllowAlwaysPatterns` returns without collecting any pattern and without any indication to the caller. A realistic chain that hits this limit: `busybox ash -c "busybox sh -c 'something'"` — busybox unwrap (0→1), shell detection + segment split (1→2), inner busybox unwrap (2→3), inner shell segment (blocked at 3).
The limit is a sound DoS guard, but silently dropping patterns means the allow-always store may be incomplete for deeply nested commands that are genuinely approved. Consider at minimum logging a debug trace when the guard fires so test failures or production mismatches are diagnosable. A `// depth guard: deliberate DoS protection` comment would also help future readers understand this isn't accidental.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5385e533aa
ℹ️ 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".
| if let token0 = command.first?.trimmingCharacters(in: .whitespacesAndNewlines), | ||
| ExecCommandToken.basenameLower(token0) == "env", | ||
| let envUnwrapped = ExecEnvInvocationUnwrapper.unwrap(command), | ||
| !envUnwrapped.isEmpty | ||
| { |
There was a problem hiding this comment.
Persist the same pattern that allowlist matching resolves
resolveAllowAlwaysPatterns now unwraps env modifiers to the inner executable, but resolveForAllowlist still resolves the same argv to /usr/bin/env (see the new expectations in ExecAllowlistTests). After a user approves allow-always for /usr/bin/env FOO=bar /usr/bin/printf ok, this code stores /usr/bin/printf, and the next identical request still misses ExecAllowlistMatcher.matchAll because its resolution remains /usr/bin/env. That makes allow-always ineffective for env-modified commands, including shell payloads like sh -lc 'env FOO=bar ...'.
Useful? React with 👍 / 👎.
| guard depth < 3, !command.isEmpty else { | ||
| return |
There was a problem hiding this comment.
Reuse the shared wrapper-depth limit for allow-always parsing
collectAllowAlwaysPatterns stops recursing once depth == 3, but the rest of the exec pipeline accepts up to ExecEnvInvocationUnwrapper.maxWrapperDepth (4). Commands with an extra supported wrapper layer—e.g. nested env invocations before sh -lc ...—can still be approved and run once, yet allow-always records no pattern because this helper bails out before reaching the leaf executable. Users will keep getting prompted for the same command.
Useful? React with 👍 / 👎.
* fix(macos): align exec command parity * fix(macos): address exec review follow-ups
* fix(macos): align exec command parity * fix(macos): address exec review follow-ups
* fix(macos): align exec command parity * fix(macos): address exec review follow-ups
* fix(macos): align exec command parity * fix(macos): address exec review follow-ups
* fix(macos): align exec command parity * fix(macos): address exec review follow-ups
* fix(macos): align exec command parity * fix(macos): address exec review follow-ups
* fix(macos): align exec command parity * fix(macos): address exec review follow-ups
* fix(macos): align exec command parity * fix(macos): address exec review follow-ups
* fix(macos): align exec command parity * fix(macos): address exec review follow-ups
* fix(macos): align exec command parity * fix(macos): address exec review follow-ups
* fix(macos): align exec command parity * fix(macos): address exec review follow-ups
* fix(macos): align exec command parity * fix(macos): address exec review follow-ups
Summary
Describe the problem and fix in 2–5 bullets:
apps/macosdrifted from the shared exec-command contract and wrapper-resolution behavior, so the macOS Swift suite failed onmain.CommandResolverTests, and replaced a flaky timestamp assertion with a stable file-identity assertion.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
None.
Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) YesYes/No) NoYes, explain risk + mitigation:This changes how the macOS app classifies
envwrappers and raw-command/display-command binding for exec approval paths. Risk is misclassifying wrappers or loosening validation. Mitigation: behavior was aligned to the existing shared TypeScript fixtures, and both the full macOS Swift suite and the shared TypeScript contract/parity tests pass after the change.Repro + Verification
Environment
pnpmSteps
swift testinapps/macosonmainbefore the fix.CommandResolverTests,ExecAllowlistTests,ExecSystemRunCommandValidatorTests, and a flakyExecApprovalsStoreRefactorTestsassertion.swift testinapps/macos.pnpm test -- src/infra/system-run-command.contract.test.ts src/infra/exec-approvals-parity.test.ts.Expected
apps/macostest suite passes cleanly.Actual
swift testinapps/macospassed:420 tests in 106 suites.29 testsacross2files.Evidence
Attach at least one:
Human Verification (required)
What you personally verified (not just CI), and how:
apps/macosswift test; shared TypeScript contract/parity tests for system-run and exec-approvals.envwith modifiers, shell-wrapper raw-command binding, Node minimum-version fallback path, and rewrite-vs-no-rewrite file-store behavior.Review Conversations
If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.
Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoFailure Recovery (if this breaks)
1ae64b67b2envmodifier chains as direct executables, orapps/macostest regressions in the exec-related suites.Risks and Mitigations
List only real risks for this PR. Add/remove entries as needed. If none, write
None.