mirror of
https://github.com/shareAI-lab/analysis_claude_code.git
synced 2026-09-20 12:13:38 +08:00
fix(s03): match Windows del as a command word
This commit is contained in:
@@ -127,6 +127,10 @@ Agent が閉じている間も実行する必要がある場合は、crontab、s
|
||||
|
||||
---
|
||||
|
||||
## 継承する権限ルール
|
||||
|
||||
この章は s04 の permission hook を引き継ぐ。command の先頭または shell separator(`;`、`&&`、`||`、`|`、`&`、括弧、改行)の直後にある完全な `rm`/`del` command word だけを大文字小文字を区別せず検出する。`model`、`delimiter`、`echo del test.txt` は危険な command として扱わない。
|
||||
|
||||
## 試してみる
|
||||
|
||||
```sh
|
||||
|
||||
@@ -127,6 +127,10 @@ Use crontab, a systemd timer, or an external scheduler when jobs must run while
|
||||
|
||||
---
|
||||
|
||||
## Inherited permission rule
|
||||
|
||||
This chapter carries forward the permission hook from s04. It recognizes `rm` and `del` case-insensitively only as complete command words at the start of a command or after a shell separator (`;`, `&&`, `||`, `|`, `&`, parentheses, or a newline). It does not treat `model`, `delimiter`, or `echo del test.txt` as destructive.
|
||||
|
||||
## Try It
|
||||
|
||||
```sh
|
||||
|
||||
@@ -127,6 +127,10 @@ for job in fired:
|
||||
|
||||
---
|
||||
|
||||
## 继承的权限规则
|
||||
|
||||
本章沿用 s04 的权限 hook:只在命令开头或 shell 分隔符(`;`、`&&`、`||`、`|`、`&`、括号或换行)之后,按大小写不敏感方式识别完整的 `rm`/`del` 命令词。`model`、`delimiter` 和 `echo del test.txt` 不会被当成危险命令。
|
||||
|
||||
## 试一下
|
||||
|
||||
```sh
|
||||
|
||||
@@ -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"):
|
||||
|
||||
Reference in New Issue
Block a user