-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Handle zsh process substitution correctly #7658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -71,6 +71,7 @@ type ShellToken = string | { op: string } | { command: string } | |||||
| * - ${var=value} with escape sequences - Can embed commands via \140 (backtick), \x60, or \u0060 | ||||||
| * - ${!var} - Indirect variable references | ||||||
| * - <<<$(...) or <<<`...` - Here-strings with command substitution | ||||||
| * - =(...) - Zsh process substitution that executes commands | ||||||
| * | ||||||
| * @param source - The command string to analyze | ||||||
| * @returns true if dangerous substitution patterns are detected, false otherwise | ||||||
|
|
@@ -100,9 +101,17 @@ export function containsDangerousSubstitution(source: string): boolean { | |||||
| // <<<$(...) or <<<`...` can execute commands | ||||||
| const hereStringWithSubstitution = /<<<\s*(\$\(|`)/.test(source) | ||||||
|
|
||||||
| // Check for zsh process substitution =(...) which executes commands | ||||||
| // =(...) creates a temporary file containing the output of the command, but executes it | ||||||
| const zshProcessSubstitution = /=\([^)]+\)/.test(source) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider handling edge cases in the regex pattern. The current pattern
Suggested change
This would use |
||||||
|
|
||||||
| // Return true if any dangerous pattern is detected | ||||||
| return ( | ||||||
| dangerousParameterExpansion || parameterAssignmentWithEscapes || indirectExpansion || hereStringWithSubstitution | ||||||
| dangerousParameterExpansion || | ||||||
| parameterAssignmentWithEscapes || | ||||||
| indirectExpansion || | ||||||
| hereStringWithSubstitution || | ||||||
| zshProcessSubstitution | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The pattern will match |
||||||
| ) | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good comprehensive test coverage! Is it intentional that this test case duplicates the one at line 351? If so, perhaps add a comment noting that line 351 specifically tests the reported exploit, while this section tests various forms more generally.