fix(s03): match Windows del as a command word

This commit is contained in:
mameikagou
2026-08-26 00:18:53 +08:00
parent 04486201fc
commit 44e33d0ec3
55 changed files with 866 additions and 331 deletions

View File

@@ -16,6 +16,7 @@ s12_cron_scheduler.py - Cron Scheduler
import glob
import json
import os
import re
import secrets
import subprocess
import threading
@@ -173,7 +174,14 @@ def trigger_hooks(event: str, *args):
DENY_LIST = ["rm -rf /", "sudo", "shutdown", "reboot", "mkfs", "dd if="]
DESTRUCTIVE = ["rm ", "> /etc/", "chmod 777"]
DESTRUCTIVE_COMMAND_WORD = re.compile(
r"(?i)(?:^|[;&|()\n])\s*(?:rm|del)(?=\s|$|[;&|()])"
)
DESTRUCTIVE = ["> /etc/", "chmod 777"]
def contains_destructive_command(command: str) -> bool:
return bool(DESTRUCTIVE_COMMAND_WORD.search(command))
def request_permission(block, reason: str) -> str | None:
@@ -195,7 +203,9 @@ def permission_hook(block):
if pattern in command:
print(f"\n\033[31m[blocked] '{pattern}'\033[0m")
return "Permission denied by deny list"
if any(keyword in command for keyword in DESTRUCTIVE):
if contains_destructive_command(command) or any(
keyword in command for keyword in DESTRUCTIVE
):
return request_permission(block, "Potentially destructive command")
if block.name in ("read_file", "write_file", "edit_file"):