feat(approvals): detect exec-via-flag escapes on read-only commands (port kilocode#11890) - #59899
Closed
teknium1 wants to merge 1 commit into
Closed
feat(approvals): detect exec-via-flag escapes on read-only commands (port kilocode#11890)#59899teknium1 wants to merge 1 commit into
teknium1 wants to merge 1 commit into
Conversation
…port kilocode#11890)
Flags on otherwise read-only commands that execute an arbitrary program
(sort --compress-program, rg --pre/--hostname-bin, ag --pager,
man -P/--pager/--html) were invisible to approval detection: the flag
value is opaque argument text, so 'sort --compress-program=sh f' ran
without a prompt and a hardline payload smuggled through the flag
('sort --compress-program="rm -rf /" f') bypassed the unconditional
floor entirely.
Two layers, mirroring Kilo-Org/kilocode#11890:
- New DANGEROUS_PATTERNS entries flag the mechanism itself, so the
command requires approval even when the payload is a script whose
contents we cannot see.
- _exec_flag_payloads() surfaces each flag's program value as its own
detection variant in _command_detection_variants(), so hardline
payloads anchor at command position and hit the floor.
E2E: 11 attack shapes detected, 5 hardline payloads reach the floor,
11 legit commands (rg --pretty, grep -P, pip install --pre, man -k
pager) unflagged. 554 approval-suite tests green.
Contributor
Author
|
Closing — this exec-via-flag detection already landed on main via |
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.
Summary
The approval system now detects exec-via-flag escapes on otherwise read-only commands —
sort --compress-program,rg --pre/--hostname-bin,ag --pager, andman -P/--pager/--html— and surfaces payloads smuggled through those flags to the hardline floor.Port of Kilo-Org/kilocode#11890 ("close read-only bash exec-flag escapes"), adapted to Hermes's regex-based dangerous-pattern detection instead of Kilo's glob allow/deny rule list.
The gap (confirmed live on main): these flags make an innocuous-looking command execute an arbitrary program. Before this change,
sort --compress-program=sh names.txtran with zero approval, and — worse —sort --compress-program='rm -rf --no-preserve-root /' fbypassed the unconditional hardline floor entirely, because the payload was opaque argument text that never anchored at a command position.Changes
tools/approval.py:DANGEROUS_PATTERNSentries flagging the mechanism itself (approval required even when the payload is a script whose contents we cannot inspect)._exec_flag_payloads()+ wiring in_command_detection_variants(): extracts each flag's program value and yields it as its own detection variant, so a hardline payload inside the flag anchors at command position and hits the floor.man's short-P/-Hflags are scoped to amancommand context sogrep -P(perl regex) never false-positives.tests/tools/test_exec_via_flag_guard.py: 30 tests — attack shapes, hardline-payload floor coverage, legit-command negatives (rg --pretty,pip install --pre,man -k pager,grep -P), payload-extraction unit tests.Adaptation notes
readOnlyBash) on their allowlist agent; Hermes has no per-agent allowlist, so the port lands in the sharedDANGEROUS_PATTERNS/ detection-variant machinery that guards every terminal call.sort --files0-fromdeny was not ported: it only reads a file list, which is within Hermes's threat model for the agent (it hasread_fileanyway) — flagging it would be a pointless approval prompt.Validation
sort --compress-program=sh fsort --compress-program='rm -rf /' fman -P 'rm -rf /' lsrg --pretty,grep -P,pip install --pre554 tests green across the approval suites (
test_approval,test_hardline_blocklist,test_approval_deny_rules,test_smart_approval_injection,test_exec_via_flag_guard+ interrupt/cron/write/clean-slate suites).Infographic