vtcode_config/core/
commands.rs

1use serde::{Deserialize, Serialize};
2
3/// Command execution configuration
4#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
5#[derive(Debug, Clone, Deserialize, Serialize)]
6pub struct CommandsConfig {
7    /// Commands that can be executed without prompting
8    #[serde(default)]
9    pub allow_list: Vec<String>,
10
11    /// Commands that are always denied
12    #[serde(default)]
13    pub deny_list: Vec<String>,
14
15    /// Glob patterns allowed for shell commands (applies to run_terminal_cmd/Bash)
16    #[serde(default)]
17    pub allow_glob: Vec<String>,
18
19    /// Glob patterns denied for shell commands
20    #[serde(default)]
21    pub deny_glob: Vec<String>,
22
23    /// Regex allow patterns for shell commands
24    #[serde(default)]
25    pub allow_regex: Vec<String>,
26
27    /// Regex deny patterns for shell commands
28    #[serde(default)]
29    pub deny_regex: Vec<String>,
30}
31
32impl Default for CommandsConfig {
33    fn default() -> Self {
34        Self {
35            allow_list: vec![
36                "ls".to_string(),
37                "pwd".to_string(),
38                "cat".to_string(),
39                "grep".to_string(),
40                "find".to_string(),
41                "head".to_string(),
42                "tail".to_string(),
43                "wc".to_string(),
44                "git status".to_string(),
45                "git diff".to_string(),
46                "git log".to_string(),
47                "git show".to_string(),
48                "git branch".to_string(),
49                "git remote".to_string(),
50                "cargo check".to_string(),
51                "cargo build".to_string(),
52                "cargo build --release".to_string(),
53                "cargo build --profile release".to_string(),
54                "cargo test".to_string(),
55                "cargo run".to_string(),
56                "cargo clippy".to_string(),
57                "cargo fmt".to_string(),
58                "cargo tree".to_string(),
59                "cargo metadata".to_string(),
60                "cargo doc".to_string(),
61                "cargo nextest run".to_string(),
62                "cargo nextest".to_string(),
63                "rustc".to_string(),
64                "which".to_string(),
65                "echo".to_string(),
66                "printf".to_string(),
67                "date".to_string(),
68                "tree".to_string(),
69                "stat".to_string(),
70                "file".to_string(),
71                "sort".to_string(),
72                "uniq".to_string(),
73                "cut".to_string(),
74                "awk".to_string(),
75                "sed".to_string(),
76                "tar".to_string(),
77                "zip".to_string(),
78                "unzip".to_string(),
79                "gzip".to_string(),
80                "gunzip".to_string(),
81                "make".to_string(),
82                "cmake".to_string(),
83                "ninja".to_string(),
84                "python3".to_string(),
85                "python3 -m pip install".to_string(),
86                "python3 -m pytest".to_string(),
87                "python3 -m build".to_string(),
88                "python".to_string(),
89                "pip3".to_string(),
90                "pip".to_string(),
91                "virtualenv".to_string(),
92                "node".to_string(),
93                "npm".to_string(),
94                "npm run build".to_string(),
95                "npm run test".to_string(),
96                "npm install".to_string(),
97                "yarn".to_string(),
98                "yarn build".to_string(),
99                "yarn test".to_string(),
100                "pnpm".to_string(),
101                "pnpm build".to_string(),
102                "pnpm test".to_string(),
103                "bun".to_string(),
104                "bun install".to_string(),
105                "bun run".to_string(),
106                "bun test".to_string(),
107                "npx".to_string(),
108                "go".to_string(),
109                "go build".to_string(),
110                "go test".to_string(),
111                "gcc".to_string(),
112                "g++".to_string(),
113                "clang".to_string(),
114                "clang++".to_string(),
115                "javac".to_string(),
116                "java".to_string(),
117                "mvn".to_string(),
118                "gradle".to_string(),
119                "docker".to_string(),
120                "docker-compose".to_string(),
121            ],
122            deny_list: vec![
123                "rm -rf /".to_string(),
124                "rm -rf ~".to_string(),
125                "rm -rf /*".to_string(),
126                "rm -rf /home".to_string(),
127                "rm -rf /usr".to_string(),
128                "rm -rf /etc".to_string(),
129                "rm -rf /var".to_string(),
130                "rm -rf /opt".to_string(),
131                "rmdir /".to_string(),
132                "rmdir /home".to_string(),
133                "rmdir /usr".to_string(),
134                "shutdown".to_string(),
135                "reboot".to_string(),
136                "halt".to_string(),
137                "poweroff".to_string(),
138                "init 0".to_string(),
139                "init 6".to_string(),
140                "systemctl poweroff".to_string(),
141                "systemctl reboot".to_string(),
142                "systemctl halt".to_string(),
143                "sudo rm".to_string(),
144                "sudo chmod 777".to_string(),
145                "sudo chown".to_string(),
146                "sudo passwd".to_string(),
147                "sudo su".to_string(),
148                "sudo -i".to_string(),
149                "sudo bash".to_string(),
150                "su root".to_string(),
151                "su -".to_string(),
152                "format".to_string(),
153                "fdisk".to_string(),
154                "mkfs".to_string(),
155                "mkfs.ext4".to_string(),
156                "mkfs.xfs".to_string(),
157                "mkfs.vfat".to_string(),
158                "dd if=/dev/zero".to_string(),
159                "dd if=/dev/random".to_string(),
160                "dd if=/dev/urandom".to_string(),
161                "wget --no-check-certificate".to_string(),
162                "curl --insecure".to_string(),
163                "curl -k".to_string(),
164                ":(){ :|:& };:".to_string(), // Fork bomb
165                "nohup bash -i".to_string(),
166                "exec bash -i".to_string(),
167                "eval".to_string(),
168                "source /etc/bashrc".to_string(),
169                "source ~/.bashrc".to_string(),
170                "chmod 777".to_string(),
171                "chmod -R 777".to_string(),
172                "chown -R".to_string(),
173                "chgrp -R".to_string(),
174                "rm ~/.ssh/*".to_string(),
175                "rm -r ~/.ssh".to_string(),
176                "cat /etc/passwd".to_string(),
177                "cat /etc/shadow".to_string(),
178                "cat ~/.ssh/id_*".to_string(),
179                "tail -f /var/log".to_string(),
180                "head -n 1 /var/log".to_string(),
181            ],
182            allow_glob: vec![
183                "git *".to_string(),
184                "cargo *".to_string(),
185                "cargo nextest *".to_string(),
186                "rustc *".to_string(),
187                "python *".to_string(),
188                "python3 *".to_string(),
189                "pip *".to_string(),
190                "pip3 *".to_string(),
191                "node *".to_string(),
192                "npm *".to_string(),
193                "npm run *".to_string(),
194                "yarn *".to_string(),
195                "yarn run *".to_string(),
196                "pnpm *".to_string(),
197                "pnpm run *".to_string(),
198                "bun *".to_string(),
199                "bun run *".to_string(),
200                "npx *".to_string(),
201                "go *".to_string(),
202                "gcc *".to_string(),
203                "g++ *".to_string(),
204                "clang *".to_string(),
205                "clang++ *".to_string(),
206                "javac *".to_string(),
207                "java *".to_string(),
208                "mvn *".to_string(),
209                "gradle *".to_string(),
210                "make *".to_string(),
211                "cmake *".to_string(),
212                "ninja *".to_string(),
213                "docker *".to_string(),
214                "docker-compose *".to_string(),
215                "virtualenv *".to_string(),
216                "tar *".to_string(),
217                "zip *".to_string(),
218                "unzip *".to_string(),
219                "gzip *".to_string(),
220                "gunzip *".to_string(),
221            ],
222            deny_glob: vec![
223                "rm *".to_string(),
224                "sudo *".to_string(),
225                "chmod *".to_string(),
226                "chown *".to_string(),
227                "kill *".to_string(),
228                "pkill *".to_string(),
229                "systemctl *".to_string(),
230                "service *".to_string(),
231                "mount *".to_string(),
232                "umount *".to_string(),
233                "docker run *".to_string(),
234                "kubectl *".to_string(),
235            ],
236            allow_regex: vec![
237                r"^(ls|pwd|cat|grep|find|head|tail|wc|echo|printf|date|tree|stat|file|sort|uniq|cut|awk|sed|tar|zip|unzip|gzip|gunzip)\b".to_string(),
238                r"^git (status|diff|log|show|branch|remote)\b".to_string(),
239                r"^cargo (check|build|test|run|doc|clippy|fmt|tree|metadata|nextest)\b".to_string(),
240                r"^rustc\b".to_string(),
241                r"^(python|python3) (-m | )?\w*".to_string(),
242                r"^(pip|pip3)\b".to_string(),
243                r"^virtualenv\b".to_string(),
244                r"^(node|npm|yarn|pnpm|bun|npx)\b".to_string(),
245                r"^go\b".to_string(),
246                r"^(gcc|g\+\+|clang|clang\++)\b".to_string(),
247                r"^(javac|java)\b".to_string(),
248                r"^(mvn|gradle)\b".to_string(),
249                r"^(make|cmake)\b".to_string(),
250                r"^(docker|docker-compose)\b".to_string(),
251            ],
252            deny_regex: vec![
253                r"rm\s+(-rf|--force)".to_string(),
254                r"sudo\s+.*".to_string(),
255                r"chmod\s+.*".to_string(),
256                r"chown\s+.*".to_string(),
257                r"docker\s+run\s+.*--privileged".to_string(),
258                r"kubectl\s+(delete|drain|uncordon)".to_string(),
259            ],
260        }
261    }
262}