-
Notifications
You must be signed in to change notification settings - Fork 42
add a better Description for PyPI #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a47bd2f
b282c5f
378f276
d3b1d3a
aff8e7a
0a4c54b
66428dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,49 @@ | |
| RestrictedPython | ||
| ================ | ||
|
|
||
| RestrictedPython is a defined subset of the Python language which allows to provide a program input into a trusted environment. | ||
| RestrictedPython is a tool that helps to define a subset of the Python language which allows to provide a program input into a trusted environment. | ||
| RestrictedPython is not a sandbox system or a secured environment, but it helps to define a trusted environment and execute untrusted code inside of it. | ||
|
|
||
| For full documentation please see http://restrictedpython.readthedocs.io/ or the local ``docs/index``. | ||
|
|
||
| Example | ||
| ======= | ||
|
|
||
| To give a basic understanding what RestrictedPython does here two examples: | ||
|
|
||
| An unproblematic code example | ||
| ----------------------------- | ||
|
|
||
| Python allows you to execute a large set of commands. | ||
| This would not harm any system. | ||
|
|
||
| >>> from RestrictedPython import compile_restricted | ||
| >>> from RestrictedPython import safe_builtins | ||
| >>> | ||
| >>> source_code = """ | ||
| ... def example(): | ||
| ... return 'Hello World!' | ||
| ... """ | ||
| >>> | ||
| >>> loc = {} | ||
| >>> byte_code = compile_restricted(source_code, '<inline>', 'exec') | ||
| >>> exec(byte_code, safe_builtins, loc) | ||
| >>> | ||
| >>> loc['example']() | ||
| 'Hello World!' | ||
|
|
||
| Problematic code example | ||
| ------------------------ | ||
|
|
||
| This example directly executed in Python could harm your system. | ||
|
|
||
| >>> from RestrictedPython import compile_restricted | ||
| >>> from RestrictedPython import safe_builtins | ||
| >>> | ||
| >>> source_code = """ | ||
| ... import os | ||
| ... | ||
| ... os.listdir('/') | ||
| ... """ | ||
| >>> byte_code = compile_restricted(source_code, '<inline>', 'exec') | ||
| >>> # exec(byte_code, safe_builtins, {}) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does happen here? I think Python complains that There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| """ | ||
| Tests about imports | ||
| """ | ||
|
|
||
| from RestrictedPython import safe_builtins | ||
| from tests import c_exec | ||
| from tests import e_exec | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| OS_IMPORT_EXAMPLE = """ | ||
| import os | ||
|
|
||
| os.listdir('/') | ||
| """ | ||
|
|
||
|
|
||
| @pytest.mark.parametrize(*c_exec) | ||
| @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. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works because RestrictedPython does not forbid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above, might be good to move that feature to RestrictedPython. |
||
| """ | ||
| result = c_exec(OS_IMPORT_EXAMPLE, safe_builtins) | ||
| # TODO: there is a tests/__init__.py problem, as it seems to pass the | ||
| # safe_builtins into the compile function instead of the source. | ||
| assert result.code is None | ||
| # assert result.errors == () | ||
|
|
||
| with pytest.raises(NameError): | ||
| e_exec(OS_IMPORT_EXAMPLE, safe_builtins) | ||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.