Skip to content

Commit

Permalink
Fix README:
Browse files Browse the repository at this point in the history
The wrong usage of `safe_builtins` allows access to the Python built-in
`getattr` allowing all sorts of access.
  • Loading branch information
Michael Howitz committed Oct 26, 2018
1 parent 719c096 commit bb93cd6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.rst
Expand Up @@ -25,7 +25,7 @@ This would not harm any system.
.. code-block:: pycon
>>> from RestrictedPython import compile_restricted
>>> from RestrictedPython import safe_builtins
>>> from RestrictedPython import safe_globals
>>>
>>> source_code = """
... def example():
Expand All @@ -34,7 +34,7 @@ This would not harm any system.
>>>
>>> loc = {}
>>> byte_code = compile_restricted(source_code, '<inline>', 'exec')
>>> exec(byte_code, safe_builtins, loc)
>>> exec(byte_code, safe_globals, loc)
>>>
>>> loc['example']()
'Hello World!'
Expand Down
3 changes: 3 additions & 0 deletions src/RestrictedPython/Guards.py
Expand Up @@ -314,3 +314,6 @@ def guarded_unpack_sequence(it, spec, _getiter_):
ret[idx] = guarded_unpack_sequence(ret[idx], child_spec, _getiter_)

return ret


safe_globals = {'__builtins__': safe_builtins}
1 change: 1 addition & 0 deletions src/RestrictedPython/__init__.py
Expand Up @@ -27,6 +27,7 @@

# predefined builtins
from RestrictedPython.Guards import safe_builtins # isort:skip
from RestrictedPython.Guards import safe_globals # isort:skip
from RestrictedPython.Limits import limited_builtins # isort:skip
from RestrictedPython.Utilities import utility_builtins # isort:skip

Expand Down

0 comments on commit bb93cd6

Please sign in to comment.