@@ -62,10 +62,13 @@ class ExecutionSafetyManager:
6262
6363 DANGEROUS_PATTERNS = [
6464 (r"\brm\s+-rf\b" , "Recursive deletion is blocked." ),
65+ (r"\brm\s+/" , "Absolute-path deletion is blocked." ),
6566 (r"\bdel\s+/(?:f|q|s)" , "Destructive delete command is blocked." ),
67+ (r"\bdel\s+[A-Za-z]:(?:\\\\|/)" , "Absolute-path deletion is blocked." ),
6668 (r"\brmdir\s+/(?:s|q)" , "Recursive directory removal is blocked." ),
6769 (r"\brd\s+/s\s+/q\b" , "Recursive directory removal is blocked." ),
6870 (r"Remove-Item\s+.+-Recurse" , "Recursive PowerShell deletion is blocked." ),
71+ (r"Remove-Item\s+[\"'](?:[A-Za-z]:\\\\|/)" , "Deleting absolute-path items in PowerShell is blocked." ),
6972 (r"\bformat\s+[a-z]:" , "Disk formatting is blocked." ),
7073 (r"\bmkfs\b" , "Filesystem formatting is blocked." ),
7174 (r"\bshutdown\b" , "System shutdown commands are blocked." ),
@@ -75,8 +78,24 @@ class ExecutionSafetyManager:
7578 (r"\bcipher\s+/w\b" , "Secure wipe commands are blocked." ),
7679 (r"\bdiskpart\b" , "Disk management commands are blocked." ),
7780 (r"shutil\.rmtree\s*\(" , "Recursive directory deletion in code is blocked." ),
81+ # Block direct absolute-path deletes.
7882 (r"os\.remove\s*\(\s*[\"'](?:[A-Za-z]:\\\\|/)" , "Deleting absolute-path files is blocked." ),
7983 (r"os\.rmdir\s*\(\s*[\"'](?:[A-Za-z]:\\\\|/)" , "Removing absolute-path directories is blocked." ),
84+ # Block absolute-path deletes when the path is constructed via os.path.join().
85+ (r"os\.remove\s*\(\s*os\.path\.join\s*\(\s*[\"'](?:[A-Za-z]:\\\\|/)" , "Deleting absolute-path files is blocked." ),
86+ (r"os\.rmdir\s*\(\s*os\.path\.join\s*\(\s*[\"'](?:[A-Za-z]:\\\\|/)" , "Removing absolute-path directories is blocked." ),
87+ (r"shutil\.rmtree\s*\(\s*os\.path\.join\s*\(\s*[\"'](?:[A-Za-z]:\\\\|/)" , "Recursive directory deletion in code is blocked." ),
88+ # Catch absolute-path string literals anywhere inside delete function calls.
89+ (r"os\.remove\s*\(\s*[^)]*[\"'](?:[A-Za-z]:\\\\|/)" , "Deleting absolute-path files is blocked." ),
90+ (r"os\.rmdir\s*\(\s*[^)]*[\"'](?:[A-Za-z]:\\\\|/)" , "Removing absolute-path directories is blocked." ),
91+ # Node.js filesystem deletions on absolute paths:
92+ # In practice we see patterns like:
93+ # const directory = 'D:\\Temp';
94+ # const filePath = path.join(directory, file);
95+ # fs.unlinkSync(filePath);
96+ # The absolute path isn't inside unlinkSync(...), so we match both in the same script.
97+ (r"(?s)(?=.*fs\.(?:unlinkSync|rmSync))(?=.*[`'\"][A-Za-z]:[\\\\/])" , "Deleting absolute-path files is blocked." ),
98+ (r"(?s)(?=.*fs\.rmdirSync)(?=.*[`'\"][A-Za-z]:[\\\\/])" , "Removing absolute-path directories is blocked." ),
8099 (r"subprocess\.(?:run|Popen)\s*\(.+(?:rm -rf|shutdown|format)" , "Dangerous subprocess invocation is blocked." ),
81100 ]
82101
0 commit comments