RestrictedPython 5.3a1.dev0__py2.py3-none-any.whl → 5.4__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- RestrictedPython/Eval.py +2 -2
- RestrictedPython/Guards.py +5 -2
- RestrictedPython/Utilities.py +15 -1
- RestrictedPython/compile.py +3 -3
- RestrictedPython/transformer.py +38 -4
- {RestrictedPython-5.3a1.dev0.dist-info → RestrictedPython-5.4.dist-info}/METADATA +18 -9
- RestrictedPython-5.4.dist-info/RECORD +14 -0
- {RestrictedPython-5.3a1.dev0.dist-info → RestrictedPython-5.4.dist-info}/WHEEL +1 -1
- RestrictedPython-5.3a1.dev0.dist-info/RECORD +0 -14
- {RestrictedPython-5.3a1.dev0.dist-info → RestrictedPython-5.4.dist-info}/LICENSE.txt +0 -0
- {RestrictedPython-5.3a1.dev0.dist-info → RestrictedPython-5.4.dist-info}/top_level.txt +0 -0
RestrictedPython/Eval.py
CHANGED
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
##############################################################################
|
|
13
13
|
"""Restricted Python Expressions."""
|
|
14
14
|
|
|
15
|
-
import ast
|
|
16
|
-
|
|
17
15
|
from ._compat import IS_PY2
|
|
18
16
|
from .compile import compile_restricted_eval
|
|
19
17
|
|
|
18
|
+
import ast
|
|
19
|
+
|
|
20
20
|
|
|
21
21
|
if IS_PY2: # pragma: PY2
|
|
22
22
|
from string import maketrans
|
RestrictedPython/Guards.py
CHANGED
|
@@ -264,9 +264,12 @@ def safer_getattr(object, name, default=None, getattr=getattr):
|
|
|
264
264
|
http://lucumr.pocoo.org/2016/12/29/careful-with-str-format/
|
|
265
265
|
|
|
266
266
|
"""
|
|
267
|
-
if
|
|
267
|
+
if name in ('format', 'format_map') and (
|
|
268
|
+
isinstance(object, _compat.basestring) or (
|
|
269
|
+
isinstance(object, type)
|
|
270
|
+
and issubclass(object, _compat.basestring))):
|
|
268
271
|
raise NotImplementedError(
|
|
269
|
-
'Using
|
|
272
|
+
'Using the string format* methods is not safe')
|
|
270
273
|
if name.startswith('_'):
|
|
271
274
|
raise AttributeError(
|
|
272
275
|
'"{name}" is an invalid attribute name because it '
|
RestrictedPython/Utilities.py
CHANGED
|
@@ -18,7 +18,21 @@ import string
|
|
|
18
18
|
|
|
19
19
|
utility_builtins = {}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
|
|
22
|
+
class _AttributeDelegator:
|
|
23
|
+
def __init__(self, mod, *excludes):
|
|
24
|
+
"""delegate attribute lookups outside *excludes* to module *mod*."""
|
|
25
|
+
self.__mod = mod
|
|
26
|
+
self.__excludes = excludes
|
|
27
|
+
|
|
28
|
+
def __getattr__(self, attr):
|
|
29
|
+
if attr in self.__excludes:
|
|
30
|
+
raise NotImplementedError(
|
|
31
|
+
"{}.{} is not safe".format(self.__mod.__name__, attr))
|
|
32
|
+
return getattr(self.__mod, attr)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
utility_builtins['string'] = _AttributeDelegator(string, "Formatter")
|
|
22
36
|
utility_builtins['math'] = math
|
|
23
37
|
utility_builtins['random'] = random
|
|
24
38
|
utility_builtins['whrandom'] = random
|
RestrictedPython/compile.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import ast
|
|
2
|
-
import warnings
|
|
3
1
|
from collections import namedtuple
|
|
4
|
-
|
|
5
2
|
from RestrictedPython._compat import IS_CPYTHON
|
|
6
3
|
from RestrictedPython._compat import IS_PY2
|
|
7
4
|
from RestrictedPython.transformer import RestrictingNodeTransformer
|
|
8
5
|
|
|
6
|
+
import ast
|
|
7
|
+
import warnings
|
|
8
|
+
|
|
9
9
|
|
|
10
10
|
CompileResult = namedtuple(
|
|
11
11
|
'CompileResult', 'code, errors, warnings, used_names')
|
RestrictedPython/transformer.py
CHANGED
|
@@ -22,16 +22,16 @@ the parsed python code to create a modified AST for a byte code generation.
|
|
|
22
22
|
# http://docs.plone.org/develop/styleguide/python.html
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
import ast
|
|
26
|
-
import contextlib
|
|
27
|
-
import textwrap
|
|
28
|
-
|
|
29
25
|
from ._compat import IS_PY2
|
|
30
26
|
from ._compat import IS_PY3
|
|
31
27
|
from ._compat import IS_PY34_OR_GREATER
|
|
32
28
|
from ._compat import IS_PY35_OR_GREATER
|
|
33
29
|
from ._compat import IS_PY38_OR_GREATER
|
|
34
30
|
|
|
31
|
+
import ast
|
|
32
|
+
import contextlib
|
|
33
|
+
import textwrap
|
|
34
|
+
|
|
35
35
|
|
|
36
36
|
# For AugAssign the operator must be converted to a string.
|
|
37
37
|
IOPERATOR_TO_STR = {
|
|
@@ -77,6 +77,32 @@ FORBIDDEN_FUNC_NAMES = frozenset([
|
|
|
77
77
|
'breakpoint',
|
|
78
78
|
])
|
|
79
79
|
|
|
80
|
+
# inspect attributes. See also
|
|
81
|
+
# https://docs.python.org/3/library/inspect.html
|
|
82
|
+
INSPECT_ATTRIBUTES = frozenset([
|
|
83
|
+
# traceback
|
|
84
|
+
"tb_frame",
|
|
85
|
+
"tb_next",
|
|
86
|
+
# code
|
|
87
|
+
"co_code",
|
|
88
|
+
# frame
|
|
89
|
+
"f_back",
|
|
90
|
+
"f_builtins",
|
|
91
|
+
"f_code",
|
|
92
|
+
"f_globals",
|
|
93
|
+
"f_locals",
|
|
94
|
+
"f_trace",
|
|
95
|
+
# generator
|
|
96
|
+
"gi_frame",
|
|
97
|
+
"gi_code",
|
|
98
|
+
"gi_yieldfrom",
|
|
99
|
+
# coroutine
|
|
100
|
+
"cr_await",
|
|
101
|
+
"cr_frame",
|
|
102
|
+
"cr_code",
|
|
103
|
+
"cr_origin",
|
|
104
|
+
])
|
|
105
|
+
|
|
80
106
|
|
|
81
107
|
# When new ast nodes are generated they have no 'lineno' and 'col_offset'.
|
|
82
108
|
# This function copies these two fields from the incoming node
|
|
@@ -923,6 +949,14 @@ class RestrictingNodeTransformer(ast.NodeTransformer):
|
|
|
923
949
|
'"{name}" is an invalid attribute name because it ends '
|
|
924
950
|
'with "__roles__".'.format(name=node.attr))
|
|
925
951
|
|
|
952
|
+
if node.attr in INSPECT_ATTRIBUTES:
|
|
953
|
+
msg = ('"%s" is a restricted name,'
|
|
954
|
+
' that is forbidden to access in RestrictedPython.')
|
|
955
|
+
self.error(
|
|
956
|
+
node,
|
|
957
|
+
msg % node.attr,
|
|
958
|
+
)
|
|
959
|
+
|
|
926
960
|
if isinstance(node.ctx, ast.Load):
|
|
927
961
|
node = self.node_contents_visit(node)
|
|
928
962
|
new_node = ast.Call(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: RestrictedPython
|
|
3
|
-
Version: 5.
|
|
3
|
+
Version: 5.4
|
|
4
4
|
Summary: RestrictedPython is a defined subset of the Python language which allows to provide a program input into a trusted environment.
|
|
5
5
|
Home-page: https://github.com/zopefoundation/RestrictedPython
|
|
6
6
|
Author: Zope Foundation and Contributors
|
|
@@ -10,7 +10,6 @@ Project-URL: Documentation, https://restrictedpython.readthedocs.io/
|
|
|
10
10
|
Project-URL: Source, https://github.com/zopefoundation/RestrictedPython
|
|
11
11
|
Project-URL: Tracker, https://github.com/zopefoundation/RestrictedPython/issues
|
|
12
12
|
Keywords: restricted execution security untrusted code
|
|
13
|
-
Platform: UNKNOWN
|
|
14
13
|
Classifier: Development Status :: 6 - Mature
|
|
15
14
|
Classifier: License :: OSI Approved :: Zope Public License
|
|
16
15
|
Classifier: Programming Language :: Python
|
|
@@ -26,7 +25,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
26
25
|
Classifier: Programming Language :: Python :: 3.10
|
|
27
26
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
28
27
|
Classifier: Topic :: Security
|
|
29
|
-
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <3.
|
|
28
|
+
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <3.11
|
|
30
29
|
Description-Content-Type: text/x-rst
|
|
31
30
|
License-File: LICENSE.txt
|
|
32
31
|
Provides-Extra: docs
|
|
@@ -120,11 +119,23 @@ This example directly executed in Python could harm your system.
|
|
|
120
119
|
Changes
|
|
121
120
|
=======
|
|
122
121
|
|
|
123
|
-
5.
|
|
124
|
-
|
|
122
|
+
5.4 (2023-08-30)
|
|
123
|
+
----------------
|
|
124
|
+
|
|
125
|
+
Fixes
|
|
126
|
+
+++++
|
|
127
|
+
|
|
128
|
+
- Fix information disclosure problems through
|
|
129
|
+
Python's "format" functionality
|
|
130
|
+
(``format`` and ``format_map`` methods on ``str``/``unicode`` and
|
|
131
|
+
their instances,
|
|
132
|
+
``string.Formatter``).
|
|
125
133
|
|
|
126
|
-
|
|
127
|
-
|
|
134
|
+
|
|
135
|
+
5.3 (2023-07-08)
|
|
136
|
+
----------------
|
|
137
|
+
|
|
138
|
+
- Forbid using some attributes providing access to restricted Python internals.
|
|
128
139
|
|
|
129
140
|
|
|
130
141
|
5.2 (2021-11-19)
|
|
@@ -364,5 +375,3 @@ Bug fixes
|
|
|
364
375
|
|
|
365
376
|
- Corresponds to the verison of the RestrictedPython package shipped
|
|
366
377
|
as part of the Zope X3.0.0 release.
|
|
367
|
-
|
|
368
|
-
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
RestrictedPython/Eval.py,sha256=Aoe0YPXAmaY2DcTAycV76mXMtY7AyrvrHZk5pW6t4-4,3345
|
|
2
|
+
RestrictedPython/Guards.py,sha256=TXAXFqwA5M1IPE_eTViyNMOJuDMWF2HPfbB6SWYjwKQ,8143
|
|
3
|
+
RestrictedPython/Limits.py,sha256=dORpuly21vSjy8gzNac9IYfIXMMWRVFvqUiKKIeZ3OM,1866
|
|
4
|
+
RestrictedPython/PrintCollector.py,sha256=jFXjgp8WLj4mEkojEBn5EH0CbpVxVL7qkPq-9czTsgg,1183
|
|
5
|
+
RestrictedPython/Utilities.py,sha256=NpWDdA0H5GrxB8Ljtx4zv_0Xj89gJjXeB_kW6pisijc,2967
|
|
6
|
+
RestrictedPython/__init__.py,sha256=qB_s6zDxuXPAGMoKYKBMc-xZ0gTnQ0ZvtY5FxdAG3aM,1862
|
|
7
|
+
RestrictedPython/_compat.py,sha256=0yS5CXqTswBoH0iNYFGYzpWv-VFLYiZPPaOJS70Ji6Q,713
|
|
8
|
+
RestrictedPython/compile.py,sha256=vQkXBUDTC4Ng_gX5lGK9AVp61yvy8VdKv9xEamdtv9I,6920
|
|
9
|
+
RestrictedPython/transformer.py,sha256=T9tzDZW8NrkCvG78HzlB9KRbgQztAckAFeCmDoc27Yk,50038
|
|
10
|
+
RestrictedPython-5.4.dist-info/LICENSE.txt,sha256=PmcdsR32h1FswdtbPWXkqjg-rKPCDOo_r1Og9zNdCjw,2070
|
|
11
|
+
RestrictedPython-5.4.dist-info/METADATA,sha256=0hQNUC2lZ3PEr2MIGNeQ9M8c_ZTgbsBpkuIQ4jrSO30,11509
|
|
12
|
+
RestrictedPython-5.4.dist-info/WHEEL,sha256=m9WAupmBd2JGDsXWQGJgMGXIWbQY3F5c2xBJbBhq0nY,110
|
|
13
|
+
RestrictedPython-5.4.dist-info/top_level.txt,sha256=E1-3ARWcduVJnQAScms0FgqnBx_PovrzYsNMYuLGwa0,17
|
|
14
|
+
RestrictedPython-5.4.dist-info/RECORD,,
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
RestrictedPython/Eval.py,sha256=oV0hkMJsXGnNEIjEbVkVj69uuhL9G5BgfTfQy-tHx6A,3345
|
|
2
|
-
RestrictedPython/Guards.py,sha256=qFF0tgfZBkx3wFxAEljnorItuuUzXR1ue40fbimqP8k,8033
|
|
3
|
-
RestrictedPython/Limits.py,sha256=dORpuly21vSjy8gzNac9IYfIXMMWRVFvqUiKKIeZ3OM,1866
|
|
4
|
-
RestrictedPython/PrintCollector.py,sha256=jFXjgp8WLj4mEkojEBn5EH0CbpVxVL7qkPq-9czTsgg,1183
|
|
5
|
-
RestrictedPython/Utilities.py,sha256=55M4T7k59Zugkf0Tt_kOddITLajxEobD9Hq0kJEmSMQ,2505
|
|
6
|
-
RestrictedPython/__init__.py,sha256=qB_s6zDxuXPAGMoKYKBMc-xZ0gTnQ0ZvtY5FxdAG3aM,1862
|
|
7
|
-
RestrictedPython/_compat.py,sha256=0yS5CXqTswBoH0iNYFGYzpWv-VFLYiZPPaOJS70Ji6Q,713
|
|
8
|
-
RestrictedPython/compile.py,sha256=L5s5y1ZRo3DvKYqpjEbPt7Jm78sqEbeVlcc6m_NqWR0,6920
|
|
9
|
-
RestrictedPython/transformer.py,sha256=QgQnESMhulAznEs99kt4DHcf_Q-fWco-lkmMxbh9WVg,49337
|
|
10
|
-
RestrictedPython-5.3a1.dev0.dist-info/LICENSE.txt,sha256=PmcdsR32h1FswdtbPWXkqjg-rKPCDOo_r1Og9zNdCjw,2070
|
|
11
|
-
RestrictedPython-5.3a1.dev0.dist-info/METADATA,sha256=2CUPDTQt4Iaj9dVH152WDfmw1r_eDOZV6npF3X4JbJQ,11326
|
|
12
|
-
RestrictedPython-5.3a1.dev0.dist-info/WHEEL,sha256=z9j0xAa_JmUKMpmz72K0ZGALSM_n-wQVmGbleXx2VHg,110
|
|
13
|
-
RestrictedPython-5.3a1.dev0.dist-info/top_level.txt,sha256=E1-3ARWcduVJnQAScms0FgqnBx_PovrzYsNMYuLGwa0,17
|
|
14
|
-
RestrictedPython-5.3a1.dev0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|