-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Handle substitution patterns in command validation #7390
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
Conversation
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.
Thank you for your contribution! I've reviewed the changes and found that the implementation correctly addresses the security vulnerability by replacing subshell detection with dangerous substitution detection. The code quality is excellent with comprehensive test coverage. I have a few suggestions for improvement.
|
|
||
| // Return true if any subshell pattern is detected | ||
| return commandSubstitutionPatterns || subshellGroupingPattern | ||
| export function containsDangerousSubstitution(source: string): boolean { |
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.
Great implementation of the dangerous substitution detection! The function correctly identifies the ${var@P} vulnerability and other dangerous parameter expansions. Is it intentional that we're not checking for Unicode escape sequences like \u0060 which could also represent backticks? This might be worth considering for completeness.
| const hereStringWithSubstitution = /<<<\s*(\$\(|`)/.test(source) | ||
|
|
||
| // Return true if any dangerous pattern is detected | ||
| return ( |
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.
Performance consideration: The function now checks 4 different regex patterns sequentially. While this is likely not a bottleneck, have you considered combining some patterns or short-circuiting on the most common cases first if this function is called frequently?
| expect(isAutoApprovedSingleCommand("npm test", [])).toBe(false) | ||
| }) | ||
| }) | ||
|
|
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.
Excellent test coverage for the dangerous substitution patterns! The tests comprehensively cover the exact exploit pattern from the security report. Consider adding a test case for Unicode escape sequences (\u0060) if you decide to support them.
Important
Replaces subshell detection with dangerous substitution detection in command validation to enhance security against parameter expansion vulnerabilities.
containsSubshellwithcontainsDangerousSubstitutionincommand-validation.tsto detect dangerous parameter expansions.getCommandDecisionto prevent auto-approval for commands with dangerous substitutions.containsDangerousSubstitutionincommand-validation.spec.tsto cover various dangerous patterns like${var@P}, octal, hex, and unicode escapes.getCommandDecision.This description was created by
for 038ae47. You can customize this summary. It will automatically update as commits are pushed.