This commit is contained in:
lpf
2026-02-13 23:45:05 +08:00
parent 3f209b6486
commit b57b4b14e7
6 changed files with 266 additions and 7 deletions

View File

@@ -15,6 +15,8 @@ import (
"clawgo/pkg/logger"
)
var blockedRootWipePattern = regexp.MustCompile(`(?i)(^|[;&|\n])\s*rm\s+-rf\s+/\s*($|[;&|\n])`)
type ExecTool struct {
workingDir string
timeout time.Duration
@@ -146,6 +148,10 @@ func (t *ExecTool) guardCommand(command, cwd string) string {
cmd := strings.TrimSpace(command)
lower := strings.ToLower(cmd)
if blockedRootWipePattern.MatchString(lower) {
return "Command blocked by safety guard (rm -rf / is forbidden)"
}
for _, pattern := range t.denyPatterns {
if pattern.MatchString(lower) {
return "Command blocked by safety guard (dangerous pattern detected)"