Skip to content

Conversation

@mrubens
Copy link
Collaborator

@mrubens mrubens commented Sep 4, 2025

Thanks @MaccariTA for reporting this issue.

Important

Add detection for zsh process substitution in command validation to flag as dangerous.

  • Behavior:
    • containsDangerousSubstitution in command-validation.ts now detects zsh process substitution =() as dangerous.
    • Commands with zsh process substitution are flagged to require user approval.
  • Tests:
    • Added tests in command-validation.spec.ts to verify detection of zsh process substitution patterns like ls =(open -a Calculator).
    • Ensures various forms of zsh process substitution are correctly identified as dangerous.
    • Tests confirm that commands with these patterns are not auto-approved.

This description was created by Ellipsis for e05098e. You can customize this summary. It will automatically update as commits are pushed.

@mrubens mrubens requested review from cte and jr as code owners September 4, 2025 05:05
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 4, 2025
Copy link
Contributor

@roomote roomote bot left a 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! This PR adds important security protection against zsh process substitution. The implementation is clean and follows existing patterns well. I've left a few minor suggestions inline for your consideration.


// 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider handling edge cases in the regex pattern. The current pattern /=\([^)]+\)/ requires at least one character inside the parentheses. While =() with empty parentheses is invalid zsh syntax, you might want to consider if the pattern should also catch this for completeness:

Suggested change
const zshProcessSubstitution = /=\([^)]+\)/.test(source)
const zshProcessSubstitution = /=\([^)]*\)/.test(source)

This would use * instead of + to match zero or more characters.

expect(containsDangerousSubstitution('result="${cmd=\\x60pwd\\x60}${cmd@P}"')).toBe(true)

// The new zsh process substitution exploit
expect(containsDangerousSubstitution("ls =(open -a Calculator)")).toBe(true)
Copy link
Contributor

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.

parameterAssignmentWithEscapes ||
indirectExpansion ||
hereStringWithSubstitution ||
zshProcessSubstitution
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern will match =() anywhere in the string, including potentially in contexts where it might not be process substitution (e.g., within strings or comments). However, this approach is consistent with how other dangerous patterns are detected in this module, appropriately favoring security over precision. Just noting this for awareness.

@mrubens mrubens merged commit 966ed76 into main Sep 4, 2025
15 checks passed
@mrubens mrubens deleted the fix_zsh_substitution branch September 4, 2025 05:14
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Sep 4, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants