-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecurity_constitution.py
More file actions
57 lines (48 loc) · 1.95 KB
/
security_constitution.py
File metadata and controls
57 lines (48 loc) · 1.95 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
"""
Hard constraints and safety guidelines for the Active Inference Agent.
These are non-negotiable rules.
"""
HARD_CONSTRAINTS = [
"Never delete files from the user's system without explicit, verified permission.",
"Never share API keys, credentials, or personal information.",
"Never execute arbitrary code downloaded from the internet without sandboxing.",
"Do not perform destructive operations on databases or registries.",
"Always inform the user if an action involves potential financial cost (e.g., paid APIs).",
"Limit external API requests to avoid rate limits or abusive behavior."
]
def check_policy_against_constitution(policy_steps):
"""
Static pre-execution safety check against hard constitutional constraints.
EFE evaluation already vetted the plan; this is the final sanity gate
for truly catastrophic / irreversible system-level operations only.
"""
violations = []
# Only block ops that could nuke the host OS or leak credentials
BLOCKED_TOOLS = {
"drop_table", # database destruction
"truncate_table", # database destruction
"format_disk", # disk wipe
"wipe_disk", # disk wipe
"rm_rf_root", # system root wipe
}
BLOCKED_PATH_FRAGMENTS = [
"c:\\windows",
"c:/windows",
"/etc",
"/bin",
"/usr",
"/system32",
]
for step in policy_steps:
tool = step.get("tool", "").lower()
args = step.get("args", {})
path = str(args.get("path", "") or args.get("folder", "") or "").lower()
if tool in BLOCKED_TOOLS:
violations.append(f"Tool '{tool}' is constitutionally blocked.")
for fragment in BLOCKED_PATH_FRAGMENTS:
if fragment in path:
violations.append(
f"Path '{path}' contains a protected system path fragment '{fragment}'."
)
break
return violations