Skip to content

Conversation

@loechel
Copy link
Member

@loechel loechel commented May 23, 2017

and make the test also a standalone pytest test

@loechel loechel requested a review from icemac May 23, 2017 21:48
Copy link
Member

@icemac icemac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation changes are fine to me. The code changes leave some questions open.

... """
>>>
>>> locals = {}
>>> byte_code = compile_restricted(source_code, '<inline>', 'exec')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second and third parameter are optional resp. you use the default arguments, so I'd suggest to remove them here to ease the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes in RestrictedPython those params are optional, but in the transfer to the builtin compile, there those are required params, so for the base example I would like to pass them in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How sad. But then it's okay.

README.rst Outdated
>>>
>>> locals = {}
>>> byte_code = compile_restricted(source_code, '<inline>', 'exec')
>>> exec(byte_code, safe_builtins, locals)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

locals is not such a nice name here as it might be confused with the locals built-in.
Even the code renderer of GitHub does this: it renders locals in blue but other variables in black.

... os.listdir('/')
... """
>>> byte_code = compile_restricted(source_code, '<inline>', 'exec')
>>> # exec(byte_code, safe_builtins, {})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does happen here? I think Python complains that __import__ is not defined as it is not in safe_builtins.
According to Guards.py it is provided by AccessControl.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it be a good idea to move some of the additional features used in Zope from AccessControl to RestrictedPython to make it easier adoptable, those import checks are one of those thing I would like to see.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import checks might be a bit too Zope specific as they involve SecurityInfo objects which are a subclass of Acquisition.Implicit.

setup.py Outdated
description='RestrictedPython provides a restricted execution '
'environment for Python, e.g. for running untrusted code.',
description='RestrictedPython is a defined subset of the Python language'
' which allows to provide a program input into a trusted'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the common case is to put the spaces at the end of the previous line.

@pytest.mark.parametrize(*e_exec)
def test_os_import(c_exec, e_exec):
"""Test that import should not work out of the box.
TODO: Why does this work.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works because RestrictedPython does not forbid import statements.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above, might be good to move that feature to RestrictedPython.

assert result.errors == ()

# with pytest.raises(NameError):
# e_exec(OS_IMPORT_EXAMPLE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code does not raise a NameError because you execute against the default globals() which provide __import__. To run against save_builtins you have to provide them as second argument to e_exec.

>>> source_code = """
... import os
...
... os.listdir('/')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this is the best example and what you want to show here: Code which RestrictedPython forbids? Code which should run through RestrictedPython as it would be harmful otherwise?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also not sure about which negative example we should use, but I think we should show an example that will be restricted.

@loechel
Copy link
Member Author

loechel commented May 24, 2017

@icemac most important part of this pull is the documentation changes, as they are shown on PyPI and that should reflect RestrictedPython as best as possible.

Could you please merge this request, even if the test_imports needs more work, and cut a release before saturday (PyCon.WEB) so if anybody looks a RestrictedPython did not get a wrong understanding and thinks of a sandbox.

Everything else we could discuss and solve on saturday after your talk or on Sunday.

@icemac icemac merged commit dc67d33 into master May 26, 2017
@icemac icemac deleted the better-description branch May 26, 2017 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants