moo.core.tests.test_security_sandbox
Security tests: RestrictedPython write/read guards and string formatting.
Covers: _write_.__setitem__, _getitem_, str.format/format_map, dict.update known gap (passes 3, 4, 5).
Functions
dict.update({'__class__': x}) inserts underscore keys at C level, bypassing _write_.__setitem__. |
|
Normal (non-underscore) key reads must continue to work. |
|
Reading d['__class__'] in restricted code must raise KeyError. |
|
The format string can be constructed at runtime to defeat static scanning. |
|
str.format(template, arg) calls format as a class-level unbound method. |
|
str.format with a dunder chain in the template must also be blocked. |
|
str.format() is blocked to prevent C-level dunder traversal. |
|
str.format_map() is blocked for the same reason as str.format(). |
|
Blocking .format must not affect other string methods. |
|
str.replace() is the safe substitution method used by message verbs. |
|
obj['__class__'] = x must raise KeyError in restricted code. |