RestrictedPython 6.0a1.dev0__py3-none-any.whl → 6.2__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/Guards.py +9 -2
- RestrictedPython/Utilities.py +15 -1
- RestrictedPython/_compat.py +1 -0
- RestrictedPython/transformer.py +37 -0
- {RestrictedPython-6.0a1.dev0.dist-info → RestrictedPython-6.2.dist-info}/METADATA +29 -10
- RestrictedPython-6.2.dist-info/RECORD +14 -0
- {RestrictedPython-6.0a1.dev0.dist-info → RestrictedPython-6.2.dist-info}/WHEEL +1 -1
- RestrictedPython-6.0a1.dev0.dist-info/RECORD +0 -14
- {RestrictedPython-6.0a1.dev0.dist-info → RestrictedPython-6.2.dist-info}/LICENSE.txt +0 -0
- {RestrictedPython-6.0a1.dev0.dist-info → RestrictedPython-6.2.dist-info}/top_level.txt +0 -0
RestrictedPython/Guards.py
CHANGED
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
import builtins
|
|
19
19
|
|
|
20
|
+
from RestrictedPython._compat import IS_PY311_OR_GREATER
|
|
21
|
+
|
|
20
22
|
|
|
21
23
|
safe_builtins = {}
|
|
22
24
|
|
|
@@ -103,6 +105,9 @@ _safe_exceptions = [
|
|
|
103
105
|
'ZeroDivisionError',
|
|
104
106
|
]
|
|
105
107
|
|
|
108
|
+
if IS_PY311_OR_GREATER:
|
|
109
|
+
_safe_exceptions.append("ExceptionGroup")
|
|
110
|
+
|
|
106
111
|
for name in _safe_names:
|
|
107
112
|
safe_builtins[name] = getattr(builtins, name)
|
|
108
113
|
|
|
@@ -241,9 +246,11 @@ def safer_getattr(object, name, default=None, getattr=getattr):
|
|
|
241
246
|
http://lucumr.pocoo.org/2016/12/29/careful-with-str-format/
|
|
242
247
|
|
|
243
248
|
"""
|
|
244
|
-
if
|
|
249
|
+
if name in ('format', 'format_map') and (
|
|
250
|
+
isinstance(object, str) or
|
|
251
|
+
(isinstance(object, type) and issubclass(object, str))):
|
|
245
252
|
raise NotImplementedError(
|
|
246
|
-
'Using format()
|
|
253
|
+
'Using the format*() methods of `str` is not safe')
|
|
247
254
|
if name.startswith('_'):
|
|
248
255
|
raise AttributeError(
|
|
249
256
|
'"{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
|
+
f"{self.__mod.__name__}.{attr} is not safe")
|
|
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/_compat.py
CHANGED
|
@@ -6,5 +6,6 @@ _version = sys.version_info
|
|
|
6
6
|
IS_PY37_OR_GREATER = _version.major == 3 and _version.minor >= 7
|
|
7
7
|
IS_PY38_OR_GREATER = _version.major == 3 and _version.minor >= 8
|
|
8
8
|
IS_PY310_OR_GREATER = _version.major == 3 and _version.minor >= 10
|
|
9
|
+
IS_PY311_OR_GREATER = _version.major == 3 and _version.minor >= 11
|
|
9
10
|
|
|
10
11
|
IS_CPYTHON = platform.python_implementation() == 'CPython'
|
RestrictedPython/transformer.py
CHANGED
|
@@ -63,6 +63,32 @@ FORBIDDEN_FUNC_NAMES = frozenset([
|
|
|
63
63
|
'breakpoint',
|
|
64
64
|
])
|
|
65
65
|
|
|
66
|
+
# inspect attributes. See also
|
|
67
|
+
# https://docs.python.org/3/library/inspect.html
|
|
68
|
+
INSPECT_ATTRIBUTES = frozenset([
|
|
69
|
+
# traceback
|
|
70
|
+
"tb_frame",
|
|
71
|
+
"tb_next",
|
|
72
|
+
# code
|
|
73
|
+
"co_code",
|
|
74
|
+
# frame
|
|
75
|
+
"f_back",
|
|
76
|
+
"f_builtins",
|
|
77
|
+
"f_code",
|
|
78
|
+
"f_globals",
|
|
79
|
+
"f_locals",
|
|
80
|
+
"f_trace",
|
|
81
|
+
# generator
|
|
82
|
+
"gi_frame",
|
|
83
|
+
"gi_code",
|
|
84
|
+
"gi_yieldfrom",
|
|
85
|
+
# coroutine
|
|
86
|
+
"cr_await",
|
|
87
|
+
"cr_frame",
|
|
88
|
+
"cr_code",
|
|
89
|
+
"cr_origin",
|
|
90
|
+
])
|
|
91
|
+
|
|
66
92
|
|
|
67
93
|
# When new ast nodes are generated they have no 'lineno', 'end_lineno',
|
|
68
94
|
# 'col_offset' and 'end_col_offset'. This function copies these fields from the
|
|
@@ -844,6 +870,13 @@ class RestrictingNodeTransformer(ast.NodeTransformer):
|
|
|
844
870
|
'"{name}" is an invalid attribute name because it ends '
|
|
845
871
|
'with "__roles__".'.format(name=node.attr))
|
|
846
872
|
|
|
873
|
+
if node.attr in INSPECT_ATTRIBUTES:
|
|
874
|
+
self.error(
|
|
875
|
+
node,
|
|
876
|
+
f'"{node.attr}" is a restricted name,'
|
|
877
|
+
' that is forbidden to access in RestrictedPython.',
|
|
878
|
+
)
|
|
879
|
+
|
|
847
880
|
if isinstance(node.ctx, ast.Load):
|
|
848
881
|
node = self.node_contents_visit(node)
|
|
849
882
|
new_node = ast.Call(
|
|
@@ -1127,6 +1160,10 @@ class RestrictingNodeTransformer(ast.NodeTransformer):
|
|
|
1127
1160
|
"""Allow `try` without restrictions."""
|
|
1128
1161
|
return self.node_contents_visit(node)
|
|
1129
1162
|
|
|
1163
|
+
def visit_TryStar(self, node):
|
|
1164
|
+
"""Allow `ExceptionGroup` without restrictions."""
|
|
1165
|
+
return self.node_contents_visit(node)
|
|
1166
|
+
|
|
1130
1167
|
def visit_ExceptHandler(self, node):
|
|
1131
1168
|
"""Protect exception handlers."""
|
|
1132
1169
|
node = self.node_contents_visit(node)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: RestrictedPython
|
|
3
|
-
Version: 6.
|
|
3
|
+
Version: 6.2
|
|
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,18 +10,17 @@ 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
|
|
17
16
|
Classifier: Operating System :: OS Independent
|
|
18
17
|
Classifier: Programming Language :: Python :: 3
|
|
19
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
18
|
Classifier: Programming Language :: Python :: 3.6
|
|
21
19
|
Classifier: Programming Language :: Python :: 3.7
|
|
22
20
|
Classifier: Programming Language :: Python :: 3.8
|
|
23
21
|
Classifier: Programming Language :: Python :: 3.9
|
|
24
22
|
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
25
24
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
26
25
|
Classifier: Topic :: Security
|
|
27
26
|
Requires-Python: >=3.6, <3.12
|
|
@@ -115,11 +114,33 @@ This example directly executed in Python could harm your system.
|
|
|
115
114
|
Traceback (most recent call last):
|
|
116
115
|
ImportError: __import__ not found
|
|
117
116
|
|
|
117
|
+
Contributing to RestrictedPython
|
|
118
|
+
--------------------------------
|
|
119
|
+
|
|
120
|
+
If you want to help maintain RestrictedPython and contribute, please refer to
|
|
121
|
+
the documentation `Contributing page
|
|
122
|
+
<https://restrictedpython.readthedocs.io/en/latest/contributing/index.html>`_.
|
|
123
|
+
|
|
118
124
|
Changes
|
|
119
125
|
=======
|
|
120
126
|
|
|
121
|
-
6.
|
|
122
|
-
|
|
127
|
+
6.2 (2023-08-30)
|
|
128
|
+
----------------
|
|
129
|
+
|
|
130
|
+
- Fix information disclosure problems through
|
|
131
|
+
Python's "format" functionality
|
|
132
|
+
(``format`` and ``format_map`` methods on ``str`` and its instances,
|
|
133
|
+
``string.Formatter``).
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
6.1 (2023-07-08)
|
|
137
|
+
----------------
|
|
138
|
+
|
|
139
|
+
- Forbid using some attributes providing access to restricted Python internals.
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
6.0 (2022-11-03)
|
|
143
|
+
----------------
|
|
123
144
|
|
|
124
145
|
Backwards incompatible changes
|
|
125
146
|
++++++++++++++++++++++++++++++
|
|
@@ -129,10 +150,10 @@ Backwards incompatible changes
|
|
|
129
150
|
Features
|
|
130
151
|
++++++++
|
|
131
152
|
|
|
132
|
-
-
|
|
133
|
-
been done so far.
|
|
153
|
+
- Officially support Python 3.11.
|
|
134
154
|
|
|
135
|
-
-
|
|
155
|
+
- Allow to use the Python 3.11 feature of exception groups and except\*
|
|
156
|
+
(PEP 654).
|
|
136
157
|
|
|
137
158
|
|
|
138
159
|
5.2 (2021-11-19)
|
|
@@ -372,5 +393,3 @@ Bug fixes
|
|
|
372
393
|
|
|
373
394
|
- Corresponds to the verison of the RestrictedPython package shipped
|
|
374
395
|
as part of the Zope X3.0.0 release.
|
|
375
|
-
|
|
376
|
-
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
RestrictedPython/Eval.py,sha256=pa79tc-JsT7xfzwg0ceMkxyioIEnFbNHc_PsKUhkkj8,3201
|
|
2
|
+
RestrictedPython/Guards.py,sha256=XXupE0TwcWdb6qAsSexWUYEIeT3bVLTdOVvn94eoqs0,7646
|
|
3
|
+
RestrictedPython/Limits.py,sha256=dORpuly21vSjy8gzNac9IYfIXMMWRVFvqUiKKIeZ3OM,1866
|
|
4
|
+
RestrictedPython/PrintCollector.py,sha256=bBCpnUPOuKz1wJDuSgh7wo2aoKfcTJeeT8OYnM-K9F8,1137
|
|
5
|
+
RestrictedPython/Utilities.py,sha256=7R6Op1Oqw9-fSxy_eWVa6ioZPx-SAxa7OolDObTWRkU,2937
|
|
6
|
+
RestrictedPython/__init__.py,sha256=qB_s6zDxuXPAGMoKYKBMc-xZ0gTnQ0ZvtY5FxdAG3aM,1862
|
|
7
|
+
RestrictedPython/_compat.py,sha256=WqDm8KKQcQfQjxsCNlumBwI2adh3sz-Xegs9pUA_9Vs,381
|
|
8
|
+
RestrictedPython/compile.py,sha256=IhcF733t-bkPcvfQ2_NyBeCbSIPtHYxR-GQNNHnaMHM,6727
|
|
9
|
+
RestrictedPython/transformer.py,sha256=0rPty6jsmADsDx69cCR1fcYAkHX9CEEqE_w1DVKr5Zw,41788
|
|
10
|
+
RestrictedPython-6.2.dist-info/LICENSE.txt,sha256=PmcdsR32h1FswdtbPWXkqjg-rKPCDOo_r1Og9zNdCjw,2070
|
|
11
|
+
RestrictedPython-6.2.dist-info/METADATA,sha256=j3kDEHIBSxG2ISYRa2Gdn6sdEKgNClG24dTtJuMUsTY,11880
|
|
12
|
+
RestrictedPython-6.2.dist-info/WHEEL,sha256=5sUXSg9e4bi7lTLOHcm6QEYwO5TIF1TNbTSVFVjcJcc,92
|
|
13
|
+
RestrictedPython-6.2.dist-info/top_level.txt,sha256=E1-3ARWcduVJnQAScms0FgqnBx_PovrzYsNMYuLGwa0,17
|
|
14
|
+
RestrictedPython-6.2.dist-info/RECORD,,
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
RestrictedPython/Eval.py,sha256=pa79tc-JsT7xfzwg0ceMkxyioIEnFbNHc_PsKUhkkj8,3201
|
|
2
|
-
RestrictedPython/Guards.py,sha256=be11vrdnducE3ULdrfHwo6ZjFTKyqsfVGRGanyvW1C4,7431
|
|
3
|
-
RestrictedPython/Limits.py,sha256=dORpuly21vSjy8gzNac9IYfIXMMWRVFvqUiKKIeZ3OM,1866
|
|
4
|
-
RestrictedPython/PrintCollector.py,sha256=bBCpnUPOuKz1wJDuSgh7wo2aoKfcTJeeT8OYnM-K9F8,1137
|
|
5
|
-
RestrictedPython/Utilities.py,sha256=EL64bcEHOJEFjJ_Y9vCjAuI5OThY3RqY_knE21yzXYI,2485
|
|
6
|
-
RestrictedPython/__init__.py,sha256=qB_s6zDxuXPAGMoKYKBMc-xZ0gTnQ0ZvtY5FxdAG3aM,1862
|
|
7
|
-
RestrictedPython/_compat.py,sha256=gbX6ySRVG3gyGy-KZ3YiawwUnoWowzYa9icEHy0TD6w,314
|
|
8
|
-
RestrictedPython/compile.py,sha256=IhcF733t-bkPcvfQ2_NyBeCbSIPtHYxR-GQNNHnaMHM,6727
|
|
9
|
-
RestrictedPython/transformer.py,sha256=Sa8zvxf1UipklaDg9cfer0DvjotNWpYyV-ymSvprbpY,40975
|
|
10
|
-
RestrictedPython-6.0a1.dev0.dist-info/LICENSE.txt,sha256=PmcdsR32h1FswdtbPWXkqjg-rKPCDOo_r1Og9zNdCjw,2070
|
|
11
|
-
RestrictedPython-6.0a1.dev0.dist-info/METADATA,sha256=Uo0CFuNYl-hBLLmhnJw9ozophOfiBwv1mf5NxJJoISM,11350
|
|
12
|
-
RestrictedPython-6.0a1.dev0.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
13
|
-
RestrictedPython-6.0a1.dev0.dist-info/top_level.txt,sha256=E1-3ARWcduVJnQAScms0FgqnBx_PovrzYsNMYuLGwa0,17
|
|
14
|
-
RestrictedPython-6.0a1.dev0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|