@@ -12,11 +12,10 @@ import { split } from 'shlex'
1212
1313export enum CommandCategory {
1414 ReadOnly ,
15- HighRisk ,
15+ Mutate ,
1616 Destructive ,
1717}
1818
19- export const dangerousPatterns = new Set ( [ '<(' , '$(' , '`' ] )
2019export const splitOperators = new Set ( [ '|' , '&&' , '||' , '>' ] )
2120export const splitOperatorsArray = Array . from ( splitOperators )
2221export const commandCategories = new Map < string , CommandCategory > ( [
@@ -47,45 +46,37 @@ export const commandCategories = new Map<string, CommandCategory>([
4746 [ 'netstat' , CommandCategory . ReadOnly ] ,
4847 [ 'ss' , CommandCategory . ReadOnly ] ,
4948 [ 'dig' , CommandCategory . ReadOnly ] ,
50- [ 'grep' , CommandCategory . ReadOnly ] ,
5149 [ 'wc' , CommandCategory . ReadOnly ] ,
5250 [ 'sort' , CommandCategory . ReadOnly ] ,
5351 [ 'diff' , CommandCategory . ReadOnly ] ,
5452 [ 'head' , CommandCategory . ReadOnly ] ,
5553 [ 'tail' , CommandCategory . ReadOnly ] ,
5654
57- // HighRisk commands
58- [ 'chmod' , CommandCategory . HighRisk ] ,
59- [ 'chown' , CommandCategory . HighRisk ] ,
60- [ 'mv' , CommandCategory . HighRisk ] ,
61- [ 'cp' , CommandCategory . HighRisk ] ,
62- [ 'ln' , CommandCategory . HighRisk ] ,
63- [ 'mount' , CommandCategory . HighRisk ] ,
64- [ 'umount' , CommandCategory . HighRisk ] ,
65- [ 'kill' , CommandCategory . HighRisk ] ,
66- [ 'killall' , CommandCategory . HighRisk ] ,
67- [ 'pkill' , CommandCategory . HighRisk ] ,
68- [ 'iptables' , CommandCategory . HighRisk ] ,
69- [ 'route' , CommandCategory . HighRisk ] ,
70- [ 'systemctl' , CommandCategory . HighRisk ] ,
71- [ 'service' , CommandCategory . HighRisk ] ,
72- [ 'crontab' , CommandCategory . HighRisk ] ,
73- [ 'at' , CommandCategory . HighRisk ] ,
74- [ 'tar' , CommandCategory . HighRisk ] ,
75- [ 'awk' , CommandCategory . HighRisk ] ,
76- [ 'sed' , CommandCategory . HighRisk ] ,
77- [ 'wget' , CommandCategory . HighRisk ] ,
78- [ 'curl' , CommandCategory . HighRisk ] ,
79- [ 'nc' , CommandCategory . HighRisk ] ,
80- [ 'ssh' , CommandCategory . HighRisk ] ,
81- [ 'scp' , CommandCategory . HighRisk ] ,
82- [ 'ftp' , CommandCategory . HighRisk ] ,
83- [ 'sftp' , CommandCategory . HighRisk ] ,
84- [ 'rsync' , CommandCategory . HighRisk ] ,
85- [ 'chroot' , CommandCategory . HighRisk ] ,
86- [ 'lsof' , CommandCategory . HighRisk ] ,
87- [ 'strace' , CommandCategory . HighRisk ] ,
88- [ 'gdb' , CommandCategory . HighRisk ] ,
55+ // Mutable commands
56+ [ 'chmod' , CommandCategory . Mutate ] ,
57+ [ 'curl' , CommandCategory . Mutate ] ,
58+ [ 'mount' , CommandCategory . Mutate ] ,
59+ [ 'umount' , CommandCategory . Mutate ] ,
60+ [ 'systemctl' , CommandCategory . Mutate ] ,
61+ [ 'service' , CommandCategory . Mutate ] ,
62+ [ 'crontab' , CommandCategory . Mutate ] ,
63+ [ 'at' , CommandCategory . Mutate ] ,
64+ [ 'nc' , CommandCategory . Mutate ] ,
65+ [ 'ssh' , CommandCategory . Mutate ] ,
66+ [ 'scp' , CommandCategory . Mutate ] ,
67+ [ 'ftp' , CommandCategory . Mutate ] ,
68+ [ 'sftp' , CommandCategory . Mutate ] ,
69+ [ 'rsync' , CommandCategory . Mutate ] ,
70+ [ 'chroot' , CommandCategory . Mutate ] ,
71+ [ 'strace' , CommandCategory . Mutate ] ,
72+ [ 'gdb' , CommandCategory . Mutate ] ,
73+ [ 'apt' , CommandCategory . Mutate ] ,
74+ [ 'yum' , CommandCategory . Mutate ] ,
75+ [ 'dnf' , CommandCategory . Mutate ] ,
76+ [ 'pacman' , CommandCategory . Mutate ] ,
77+ [ 'exec' , CommandCategory . Mutate ] ,
78+ [ 'eval' , CommandCategory . Mutate ] ,
79+ [ 'xargs' , CommandCategory . Mutate ] ,
8980
9081 // Destructive commands
9182 [ 'rm' , CommandCategory . Destructive ] ,
@@ -104,22 +95,17 @@ export const commandCategories = new Map<string, CommandCategory>([
10495 [ 'insmod' , CommandCategory . Destructive ] ,
10596 [ 'rmmod' , CommandCategory . Destructive ] ,
10697 [ 'modprobe' , CommandCategory . Destructive ] ,
107- [ 'apt' , CommandCategory . Destructive ] ,
108- [ 'yum' , CommandCategory . Destructive ] ,
109- [ 'dnf' , CommandCategory . Destructive ] ,
110- [ 'pacman' , CommandCategory . Destructive ] ,
111- [ 'perl' , CommandCategory . Destructive ] ,
112- [ 'python' , CommandCategory . Destructive ] ,
113- [ 'bash' , CommandCategory . Destructive ] ,
114- [ 'sh' , CommandCategory . Destructive ] ,
115- [ 'exec' , CommandCategory . Destructive ] ,
116- [ 'eval' , CommandCategory . Destructive ] ,
117- [ 'xargs' , CommandCategory . Destructive ] ,
98+ [ 'kill' , CommandCategory . Destructive ] ,
99+ [ 'killall' , CommandCategory . Destructive ] ,
100+ [ 'pkill' , CommandCategory . Destructive ] ,
101+ [ 'iptables' , CommandCategory . Destructive ] ,
102+ [ 'route' , CommandCategory . Destructive ] ,
103+ [ 'chown' , CommandCategory . Destructive ] ,
118104] )
119105export const maxBashToolResponseSize : number = 1024 * 1024 // 1MB
120106export const lineCount : number = 1024
121107export const destructiveCommandWarningMessage = '⚠️ WARNING: Destructive command detected:\n\n'
122- export const highRiskCommandWarningMessage = '⚠️ WARNING: High risk command detected :\n\n'
108+ export const mutateCommandWarningMessage = 'Mutation command:\n\n'
123109
124110export interface ExecuteBashParams {
125111 command : string
@@ -197,22 +183,12 @@ export class ExecuteBash {
197183 switch ( category ) {
198184 case CommandCategory . Destructive :
199185 return { requiresAcceptance : true , warning : destructiveCommandWarningMessage }
200- case CommandCategory . HighRisk :
201- return {
202- requiresAcceptance : true ,
203- warning : highRiskCommandWarningMessage ,
204- }
186+ case CommandCategory . Mutate :
187+ return { requiresAcceptance : true , warning : mutateCommandWarningMessage }
205188 case CommandCategory . ReadOnly :
206- if (
207- cmdArgs . some ( ( arg ) =>
208- Array . from ( dangerousPatterns ) . some ( ( pattern ) => arg . includes ( pattern ) )
209- )
210- ) {
211- return { requiresAcceptance : true , warning : highRiskCommandWarningMessage }
212- }
213189 continue
214190 default :
215- return { requiresAcceptance : true , warning : highRiskCommandWarningMessage }
191+ return { requiresAcceptance : true }
216192 }
217193 }
218194 return { requiresAcceptance : false }
0 commit comments