MCPcopy Create free account
hub / github.com/astercloud/aster / validateCommand

Method validateCommand

pkg/tools/builtin/bash.go:317–345  ·  view source on GitHub ↗
(cmd string)

Source from the content-addressed store, hash-verified

315}
316
317func (t *BashTool) validateCommand(cmd string) error {
318 // 检查危险命令模式
319 lowerCmd := strings.ToLower(cmd)
320 for _, pattern := range t.dangerousPatterns {
321 if pattern.MatchString(lowerCmd) {
322 return fmt.Errorf("dangerous command blocked: %s", cmd)
323 }
324 }
325
326 // 检查其他危险命令
327 dangerousCommands := []string{
328 "rm -rf /",
329 "sudo rm",
330 ":(){ :|:& };:",
331 "chmod 777 /",
332 "dd if=/dev/zero",
333 "mkfs",
334 "format",
335 "fdisk",
336 }
337
338 for _, dangerous := range dangerousCommands {
339 if strings.Contains(lowerCmd, dangerous) {
340 return fmt.Errorf("dangerous command blocked: %s", cmd)
341 }
342 }
343
344 return nil
345}
346
347func (t *BashTool) buildFullCommand(command string, environment map[string]string, shellType string) string {
348 var parts []string

Callers 1

ExecuteMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected