fix(cli): close read-only bash exec-flag escapes - #11890
Merged
Merged
Conversation
The readOnlyBash allowlist permits sort/rg/ag/man but relied on blocklisting only a couple of writer flags. GNU sort execs an arbitrary program via --compress-program (e.g. sort --compress-program sh), and rg --pre, ag --pager, and man -P/-H have equivalent exec-via-flag escapes. Deny those flags, and dedupe the now-overlapping operator and sort output rules.
markijbema
marked this pull request as ready for review
July 2, 2026 13:01
markijbema
enabled auto-merge
July 2, 2026 13:01
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (3 files)
Notes
lgtm Reviewed by claude-sonnet-5-20260630 · Input: 38 · Output: 17.9K · Cached: 1.1M Review guidance: REVIEW.md from base branch |
RSO
approved these changes
Jul 2, 2026
This was referenced Jul 3, 2026
t7tran
pushed a commit
to t7tran/kilocode
that referenced
this pull request
Aug 14, 2026
…ec-flag-denies fix(cli): close read-only bash exec-flag escapes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Harden the
readOnlyBashpermission allowlist (used by the ask/plan/explore agents) against commands that are "read-only" in spirit but can still execute an arbitrary program through a flag.The allowlist permits
sort,rg,ag,man, etc., and previously relied on blocklisting only a couple ofsortwriter flags (-o,--output). That approach missed several exec-via-flag escapes:sort --compress-program <prog>— GNU sort execs the program (the reported bypass:echo ... | sort -S 1b --compress-program "sh"), plus--files0-fromrg --pre <prog>/--pre=<prog>/--hostname-bin— ripgrep runs an arbitrary preprocessorag --pager <prog>man -P <prog>/--pager/-H— man runs an arbitrary pager/browser (including the glued short formman -Psh)These are now denied. While in there, the operator and sort-output deny rules were deduplicated: since
*matches any run of characters (spaces and empty),*>*already subsumes>>/>|/spaced variants and*&*subsumes&&, so the redundant lines were collapsed and commented.Why
An allowed but prompt-injected/untrusted agent could run
sort --compress-program sh(and friends) to execute arbitrary shell without triggering an approval prompt.Note
This is defense-in-depth on top of a string-matching allowlist, not a real sandbox. Command-line blocklists are inherently leaky (env-based vectors like
LESSOPEN,GIT_PAGER, etc. remain). The durable fix is OS-level sandboxing of bash execution — worth a separate follow-up. Comments in the file now say as much.Testing
Added deny cases in
test/kilocode/ask-agent-permissions.test.tsfor every new vector (including the gluedman -Pshform). Rule logic was validated against the exactWildcard.match+findLastsemantics (all deny vectors caught;sort foo-o bar,rg --pre-glob,man --help,sort -S 1bremain allowed — no false positives).