File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -134,7 +134,18 @@ export class Cline {
134134 }
135135
136136 protected isAllowedCommand ( command ?: string ) : boolean {
137- if ( ! command ) return false ;
137+ if ( ! command ) {
138+ return false ;
139+ }
140+ // Check for command chaining characters
141+ if ( command . includes ( '&&' ) ||
142+ command . includes ( ';' ) ||
143+ command . includes ( '||' ) ||
144+ command . includes ( '|' ) ||
145+ command . includes ( '$(' ) ||
146+ command . includes ( '`' ) ) {
147+ return false ;
148+ }
138149 const trimmedCommand = command . trim ( ) . toLowerCase ( ) ;
139150 return ALLOWED_AUTO_EXECUTE_COMMANDS . some ( prefix =>
140151 trimmedCommand . startsWith ( prefix . toLowerCase ( ) )
Original file line number Diff line number Diff line change @@ -388,5 +388,23 @@ describe('Cline', () => {
388388 expect ( cline . isAllowedCommand ( '' ) ) . toBe ( false )
389389 expect ( cline . isAllowedCommand ( ' ' ) ) . toBe ( false )
390390 } )
391+
392+ test ( 'returns false for commands with chaining operators' , ( ) => {
393+ const maliciousCommands = [
394+ 'npm install && rm -rf /' ,
395+ 'git status; dangerous-command' ,
396+ 'git log || evil-script' ,
397+ 'git status | malicious-pipe' ,
398+ 'git log $(evil-command)' ,
399+ 'git status `rm -rf /`' ,
400+ 'npm install && echo "malicious"' ,
401+ 'git status; curl http://evil.com' ,
402+ 'tsc --watch || wget malware' ,
403+ ] ;
404+
405+ maliciousCommands . forEach ( cmd => {
406+ expect ( cline . isAllowedCommand ( cmd ) ) . toBe ( false ) ;
407+ } ) ;
408+ } ) ;
391409 } )
392410} ) ;
You can’t perform that action at this time.
0 commit comments