Skip to content

Commit 36fd5b2

Browse files
committed
Allow input() while updating blocked built-ins and related tests
1 parent 4cb996e commit 36fd5b2

5 files changed

Lines changed: 12 additions & 5 deletions

File tree

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ All source lives in `evaluation_function/`:
5555
`_SecurityVisitor` walks the AST before any execution and blocks:
5656

5757
- **Modules**: `os`, `sys`, `subprocess`, `socket`, `urllib`, `http`, `requests`, `shutil`, `pathlib`, `ftplib`, `smtplib`, `ctypes`, `multiprocessing`, `threading`, `importlib`, `pickle`, `builtins`
58-
- **Builtins**: `exec`, `eval`, `compile`, `open`, `__import__`, `input`
58+
- **Builtins**: `exec`, `eval`, `compile`, `open`, `__import__`
5959
- **Dunder attribute access**: any `__attr__` style attribute
6060

6161
## Key commands

docs/dev.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ Called before evaluation. Parses the student code as an AST and checks for secur
118118
| Category | Blocked items |
119119
|----------|--------------|
120120
| Module imports | `os`, `sys`, `subprocess`, `socket`, `urllib`, `http`, `requests`, `shutil`, `pathlib`, `ftplib`, `smtplib`, `ctypes`, `multiprocessing`, `threading`, `importlib`, `pickle`, `builtins` |
121-
| Builtins | `exec`, `eval`, `compile`, `open`, `__import__`, `input` |
121+
| Builtins | `exec`, `eval`, `compile`, `open`, `__import__` |
122122
| Attribute access | Any dunder (`__attr__`) attribute |
123123

124124
### Response

docs/user.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Params:
158158
Students' code is checked before execution. The following are blocked and will return an error before the code runs:
159159

160160
- Importing: `os`, `sys`, `subprocess`, `socket`, `requests`, `pathlib`, and other system/network modules
161-
- Calling: `exec`, `eval`, `compile`, `open`, `__import__`
161+
- Calling: `exec`, `eval`, `compile`, `open`, `__import__` (but **`input()` is allowed**)
162162
- Accessing dunder attributes (`__class__`, `__dict__`, etc.)
163163

164164
These restrictions cannot be bypassed; attempts result in an error feedback item rather than execution.

evaluation_function/preview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"pickle", "builtins",
1010
}
1111

12-
_BLOCKED_BUILTINS = {"exec", "eval", "compile", "open", "__import__", "input"}
12+
_BLOCKED_BUILTINS = {"exec", "eval", "compile", "open", "__import__"}
1313

1414

1515
class _SecurityVisitor(ast.NodeVisitor):

evaluation_function/preview_test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,11 @@ def test_dunder_access(self):
4646
result = preview_function(response, params)
4747

4848
self.assertIn("preview", result)
49-
self.assertIn("Unsafe", result["preview"].get("feedback", ""))
49+
self.assertIn("Unsafe", result["preview"].get("feedback", ""))
50+
51+
def test_input_is_allowed(self):
52+
response, params = "x = int(input())", Params()
53+
result = preview_function(response, params)
54+
55+
self.assertIn("preview", result)
56+
self.assertNotIn("Unsafe", result["preview"].get("feedback", ""))

0 commit comments

Comments
 (0)