Commit d6421dc
authored
fix: Require an explicit opt in to unsafety; defer decision to call time (#246)
Codejail currently makes a decision at module load time of whether it
should run all code safely or unsafely, and defaults to unsafely. This
causes several problems:
- Any misconfiguration of codejail (such as a missing Django setting or
middleware) results in the application becoming immediately and entirely
vulnerable to anyone who can submit code.
- Codejail's behavior changes depending on when the `codejail.safe_exec`
module is loaded during application initialization. This causes unstable
behavior and is confusing for developers.
This change switches the `ALWAYS_BE_UNSAFE` check to occur only at the time
that `safe_exec` is actually called, rather than at module load time.
The check for whether codejail is configured for Python is also moved to
call time, but no longer automatically switches codejail to unsafe mode.
Instead, it raises an exception to notify the user of their error.1 parent 766be1d commit d6421dc
File tree
4 files changed
+70
-50
lines changed- codejail
- tests
4 files changed
+70
-50
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 13 | + | |
21 | 14 | | |
22 | 15 | | |
23 | 16 | | |
| |||
64 | 57 | | |
65 | 58 | | |
66 | 59 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
71 | 66 | | |
72 | 67 | | |
73 | 68 | | |
| |||
166 | 161 | | |
167 | 162 | | |
168 | 163 | | |
169 | | - | |
170 | | - | |
| 164 | + | |
| 165 | + | |
171 | 166 | | |
172 | 167 | | |
173 | 168 | | |
| |||
176 | 171 | | |
177 | 172 | | |
178 | 173 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
| 174 | + | |
183 | 175 | | |
184 | 176 | | |
185 | 177 | | |
| |||
214 | 206 | | |
215 | 207 | | |
216 | 208 | | |
217 | | - | |
| 209 | + | |
218 | 210 | | |
219 | 211 | | |
220 | 212 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
| |||
80 | 86 | | |
81 | 87 | | |
82 | 88 | | |
83 | | - | |
84 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
85 | 105 | | |
86 | 106 | | |
87 | 107 | | |
| |||
257 | 277 | | |
258 | 278 | | |
259 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
260 | 285 | | |
261 | 286 | | |
262 | 287 | | |
| |||
286 | 311 | | |
287 | 312 | | |
288 | 313 | | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
| |||
176 | 179 | | |
177 | 180 | | |
178 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
179 | 207 | | |
180 | 208 | | |
181 | 209 | | |
182 | 210 | | |
183 | 211 | | |
184 | 212 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | 213 | | |
192 | 214 | | |
0 commit comments