fix: prevent array assignments from triggering zsh process substitution detection #11365
+41
−2
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
zshProcessSubstitutionregex incontainsDangerousSubstitution()used=\([^)]+\)which incorrectly matched bash/zsh array assignments likefiles=(a b c)as dangerous zsh process substitutions like=(whoami).This caused auto-approve to be bypassed (returning
ask_userinstead ofauto_approve) even when the user had*wildcard in their allowed commands list.Changes
src/core/auto-approval/commands.ts: Added negative lookbehind(?<![a-zA-Z0-9_])to the regex so that=(preceded by a variable name character (array assignment) is not flagged, while standalone=(cmd)process substitution still issrc/core/auto-approval/commands.ts: Updated doc comment to note that array assignments are excluded from detectionsrc/core/auto-approval/__tests__/commands.spec.ts: Added 7 test cases:files=(a b c),var=(item1 item2),x=(hello))=(whoami),=(ls),echo =(cat /etc/passwd))getCommandDecisionreturnsauto_approvefor array assignment commands with*wildcardImportant
Fixes regex in
commands.tsto prevent array assignments from being flagged as zsh process substitutions, with updated tests incommands.spec.ts.containsDangerousSubstitution()incommands.tsto exclude array assignments from zsh process substitution detection.commands.tsto clarify exclusion of array assignments.commands.spec.tsto verify correct detection of array assignments and process substitutions.getCommandDecisionto ensureauto_approvefor array assignments with wildcard allowlist.This description was created by
for f20ab30. You can customize this summary. It will automatically update as commits are pushed.