This repository was archived by the owner on Mar 23, 2026. It is now read-only.
Commit 0c5747a
authored
Fix security concerns (#515)
# Summary of Security Improvements
## 1. Strengthened AST Validation (code_verification.py)
- Added DANGEROUS_BUILTINS constant listing security-sensitive
functions/attributes
- Enhanced visit_Call() to detect:
- Subscript-based function calls (e.g., obj["method"]())
- Chained calls for dynamic resolution (e.g., getattr(obj, 'method')())
- Unrecognized call patterns
- Dangerous builtin functions
- Added visit_Subscript() to detect dictionary-based dunder access
(e.g., obj["__class__"])
- Added visit_Attribute() to detect direct dangerous attribute access
(e.g., obj.__class__)
## 2. Updated Default Blocklist (code_interpreter.py)
Added these dangerous functions to the default blocked list:
- getattr, setattr, delattr
- vars, globals, locals
- __getattribute__, __setattr__, __delattr__
## 3. Code Verification Enabled by Default for Local Mode
(code_interpreter.py)
- Code verification is now automatically enabled when running in local
mode
- A warning is logged to inform users about the security implications
- Users can still explicitly disable it, but this is discouraged
## 4. Security Guidance in Code Generator Prompt
(code_generator_prompt.yaml & code_generator.py)
Added explicit security guidelines that instruct the LLM to:
- Never use dangerous functions like eval(), exec(), getattr(), etc.
- Never access dunder attributes
- Never execute shell commands unless required
- Refuse requests that attempt to bypass security
- The security requirements are included in the prompt when code
verification is enabled
## 5. New Unit Tests (test_code_verification.py)
Added comprehensive tests for:
- Dynamic attribute access (getattr, setattr, delattr)
- globals() and locals() blocking
- Dunder attribute access (__class__, __bases__)
- Subscript-based dunder access
- Subscript-based function call bypass patterns
- vars() function blocking5 files changed
Lines changed: 286 additions & 46 deletions
File tree
- taskweaver/code_interpreter
- code_interpreter
- tests/unit_tests
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| |||
296 | 297 | | |
297 | 298 | | |
298 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
299 | 305 | | |
300 | 306 | | |
301 | 307 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
98 | 111 | | |
99 | 112 | | |
100 | 113 | | |
| |||
Lines changed: 25 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
57 | 67 | | |
58 | 68 | | |
59 | 69 | | |
| |||
97 | 107 | | |
98 | 108 | | |
99 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
100 | 124 | | |
101 | | - | |
| 125 | + | |
102 | 126 | | |
103 | 127 | | |
104 | 128 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
7 | 26 | | |
8 | 27 | | |
9 | 28 | | |
| |||
42 | 61 | | |
43 | 62 | | |
44 | 63 | | |
45 | | - | |
46 | | - | |
47 | | - | |
| 64 | + | |
48 | 65 | | |
49 | 66 | | |
50 | 67 | | |
51 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
52 | 83 | | |
53 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
54 | 91 | | |
55 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
56 | 102 | | |
57 | 103 | | |
58 | | - | |
| 104 | + | |
59 | 105 | | |
60 | 106 | | |
| 107 | + | |
| 108 | + | |
61 | 109 | | |
62 | 110 | | |
63 | 111 | | |
| |||
70 | 118 | | |
71 | 119 | | |
72 | 120 | | |
73 | | - | |
74 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
75 | 127 | | |
76 | | - | |
77 | | - | |
78 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
79 | 139 | | |
80 | | - | |
| 140 | + | |
81 | 141 | | |
82 | | - | |
| 142 | + | |
83 | 143 | | |
84 | 144 | | |
85 | | - | |
| 145 | + | |
86 | 146 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
| 147 | + | |
102 | 148 | | |
103 | 149 | | |
104 | 150 | | |
| |||
108 | 154 | | |
109 | 155 | | |
110 | 156 | | |
111 | | - | |
112 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
113 | 173 | | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
128 | 203 | | |
129 | 204 | | |
130 | 205 | | |
| |||
0 commit comments