-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_security.py
More file actions
56 lines (49 loc) · 1.94 KB
/
fix_security.py
File metadata and controls
56 lines (49 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
filepath = 'src/lib/security.ts'
with open(filepath, 'r') as f:
lines = f.readlines()
new_lines = []
in_block_categories = False
in_ask_categories = False
in_validate_command = False
for line in lines:
if 'const BLOCK_CATEGORIES' in line:
in_block_categories = True
new_lines.append('const ALL_PATTERNS = [\n')
continue
if in_block_categories:
if '];' in line:
in_block_categories = False
# We'll add the dangerous_git category here
new_lines.append(" { category: 'dangerous_git', patterns: DANGEROUS_GIT_PATTERNS },\n")
new_lines.append('];\n')
else:
new_lines.append(line)
continue
if 'const ASK_CATEGORIES' in line:
in_ask_categories = True
continue
if in_ask_categories:
if '];' in line:
in_ask_categories = False
continue
if 'export function validateCommand' in line:
in_validate_command = True
new_lines.append(line)
new_lines.append(" for (const { category, patterns } of ALL_PATTERNS) {\n")
new_lines.append(" for (const pattern of patterns) {\n")
new_lines.append(" if (pattern.test(command)) {\n")
new_lines.append(" return {\n")
new_lines.append(" status: 'ask',\n")
new_lines.append(" category,\n")
new_lines.append(" feedback: `⚠️ DANGEROUS: Detected ${category} pattern. Operation requires human confirmation. Command: ${redactString(command).slice(0, 50)}...`,\n")
new_lines.append(" };\n")
new_lines.append(" }\n")
new_lines.append(" }\n")
new_lines.append(" }\n")
new_lines.append(" return { status: 'allow' };\n")
new_lines.append("}\n")
break # Skip the rest of the original function
new_lines.append(line)
with open(filepath, 'w') as f:
f.writelines(new_lines)