fix(command-mode): detect destructive commands in chained segments#432
Open
postoso wants to merge 1 commit into
Open
fix(command-mode): detect destructive commands in chained segments#432postoso wants to merge 1 commit into
postoso wants to merge 1 commit into
Conversation
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
CommandModeService.isDestructiveCommandapplied its prefix checks to the whole command string, so a destructive command hidden after a shell chaining separator bypassed the confirm gate and auto-ran. Examples that returned false (auto-run):echo ok && killall Finder,true; shred secret.txt,echo a || killall Finder,echo ok & killall Finder, and a newline-chainedsudo reboot.How
Split the command on chaining separators (
&&,||,;,&, newline) into segments, trim each, and apply the existing detection per segment (factored intoisDestructiveSegment).&&is normalized before the single&so it is not read as two background separators. Pipe (|) is intentionally not a split point: piped destructive commands stay matched by the existing| rm/| sudo/| ddsubstring patterns. Verified that2>&1andsleep 10 & echo donedo not false-positive.Tests
New
CommandModeDestructiveCommandTests(15 methods): each separator hiding a destructive command, safe chains, a backgrounded-safe command, and preserved single-command plus piped detection.xcodebuild testis green andswiftlint --strictis clean.Note
Focused follow-up to #428 (which hardens the same function for pipe-to-shell and output redirects). The two address independent gaps; this is structured so it rebases cleanly after #428 merges (the new per-segment
isDestructiveSegmenthelper is where #428's added patterns belong).