Debian Codegraph @

PKG-INFO

raw
1 Metadata-Version: 2.4
2 Name: RestrictedPython
3 Version: 8.4
4 Summary: RestrictedPython is a defined subset of the Python language which allows to provide a program input into a trusted environment.
5 Author-email: Zope Foundation and contributors <[email protected]>
6 Maintainer-email: Plone Foundation and contributors <[email protected]>
7 License-Expression: ZPL-2.1
8 Project-URL: Documentation, https://restrictedpython.readthedocs.io/
9 Project-URL: Issues, https://github.com/zopefoundation/RestrictedPython/issues
10 Project-URL: Source, https://github.com/zopefoundation/RestrictedPython
11 Project-URL: Changelog, https://github.com/zopefoundation/RestrictedPython/blob/master/CHANGES.rst
12 Keywords: restricted,execution,security,untrusted,code
13 Classifier: Development Status :: 6 - Mature
14 Classifier: Programming Language :: Python
15 Classifier: Operating System :: OS Independent
16 Classifier: Programming Language :: Python :: 3
17 Classifier: Programming Language :: Python :: 3.10
18 Classifier: Programming Language :: Python :: 3.11
19 Classifier: Programming Language :: Python :: 3.12
20 Classifier: Programming Language :: Python :: 3.13
21 Classifier: Programming Language :: Python :: 3.14
22 Classifier: Programming Language :: Python :: Implementation :: CPython
23 Classifier: Topic :: Security
24 Classifier: Typing :: Typed
25 Requires-Python: <3.16,>=3.10
26 Description-Content-Type: text/x-rst
27 License-File: LICENSE.txt
28 Provides-Extra: test
29 Requires-Dist: pytest; extra == "test"
30 Requires-Dist: pytest-mock; extra == "test"
31 Provides-Extra: docs
32 Requires-Dist: Sphinx; extra == "docs"
33 Requires-Dist: furo; extra == "docs"
34 Provides-Extra: typecheck
35 Requires-Dist: mypy; extra == "typecheck"
36 Dynamic: license-file
37
38 .. image:: https://github.com/zopefoundation/RestrictedPython/actions/workflows/tests.yml/badge.svg
39 :target: https://github.com/zopefoundation/RestrictedPython/actions/workflows/tests.yml
40
41 .. image:: https://coveralls.io/repos/github/zopefoundation/RestrictedPython/badge.svg?branch=master
42 :target: https://coveralls.io/github/zopefoundation/RestrictedPython?branch=master
43
44 .. image:: https://readthedocs.org/projects/restrictedpython/badge/
45 :target: https://restrictedpython.readthedocs.org/
46 :alt: Documentation Status
47
48 .. image:: https://img.shields.io/pypi/v/RestrictedPython.svg
49 :target: https://pypi.org/project/RestrictedPython/
50 :alt: Current version on PyPI
51
52 .. image:: https://img.shields.io/pypi/pyversions/RestrictedPython.svg
53 :target: https://pypi.org/project/RestrictedPython/
54 :alt: Supported Python versions
55
56 .. image:: https://github.com/zopefoundation/RestrictedPython/raw/master/docs/logo.jpg
57
58 ================
59 RestrictedPython
60 ================
61
62 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.
63 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.
64
65 .. warning::
66
67 RestrictedPython only supports CPython. It does _not_ support PyPy and other Python implementations as it cannot provide its restrictions there.
68
69 For full documentation please see http://restrictedpython.readthedocs.io/.
70
71 Example
72 =======
73
74 To give a basic understanding what RestrictedPython does here two examples:
75
76 An unproblematic code example
77 -----------------------------
78
79 Python allows you to execute a large set of commands.
80 This would not harm any system.
81
82 .. code-block:: pycon
83
84 >>> from RestrictedPython import compile_restricted
85 >>> from RestrictedPython import safe_globals
86 >>>
87 >>> source_code = """
88 ... def example():
89 ... return 'Hello World!'
90 ... """
91 >>>
92 >>> loc = {}
93 >>> byte_code = compile_restricted(source_code, '<inline>', 'exec')
94 >>> exec(byte_code, safe_globals, loc)
95 >>>
96 >>> loc['example']()
97 'Hello World!'
98
99 Problematic code example
100 ------------------------
101
102 This example directly executed in Python could harm your system.
103
104 .. code-block:: pycon
105
106 >>> from RestrictedPython import compile_restricted
107 >>> from RestrictedPython import safe_globals
108 >>>
109 >>> source_code = """
110 ... import os
111 ...
112 ... os.listdir('/')
113 ... """
114 >>> byte_code = compile_restricted(source_code, '<inline>', 'exec')
115 >>> exec(byte_code, safe_globals, {})
116 Traceback (most recent call last):
117 ImportError: __import__ not found
118
119 Contributing to RestrictedPython
120 --------------------------------
121
122 If you want to help maintain RestrictedPython and contribute, please refer to
123 the documentation `Contributing page
124 <https://restrictedpython.readthedocs.io/en/latest/contributing/index.html>`_.
125
126 Changes
127 =======
128
129 8.4 (2026-07-10)
130 ----------------
131
132 - Add type annotations to the package code.
133 For clarification, restricted Python code does not support type annotations.
134
135 - Allow ``ast.Module``, ``ast.Expression`` and ``ast.Interactive`` as body in compile_restricted_function
136
137 - Disallow ``mode="function"`` in ``compile_restricted`` (it never worked).
138
139 - Prevent access to ``string.Formatter`` and its unsafe traversal methods via
140 ``safer_getattr``.
141
142 8.3 (2026-06-16)
143 ----------------
144
145 - Switch to PyPI Trusted Publishing for the package release process
146
147 - Also validate positional-only argument names (parameters before ``/``) so
148 they cannot start with an underscore, closing a sandbox escape where a
149 positional-only parameter could shadow an injected protected name such as
150 ``_getattr_``, ``_getitem_``, ``_write_`` or ``_print_``.
151
152
153 8.3a1.dev0 (2026-05-29)
154 -----------------------
155
156 - Allow to use the package with Python 3.15 -- Caution: No security audit has been done so far.
157
158
159 8.2 (2026-05-29)
160 ----------------
161
162 - Remove documentation that appears to promote unsupported direct guards usage.
163
164 - Move package metadata from setup.py to pyproject.toml.
165
166 - Drop support for Python 3.9.
167
168 - Allow the ``...`` (Ellipsis) statement.
169
170
171 8.1 (2025-10-19)
172 ----------------
173
174 - Allow to use the package with Python 3.14 including t-string support.
175
176
177 8.0 (2025-01-23)
178 ----------------
179
180 Backwards incompatible changes
181 ++++++++++++++++++++++++++++++
182
183 - Disallow ``try/except*`` clauses due to a possible sandbox escape and
184 probable uselessness of this feature in the context of ``RestrictedPython``.
185 In addition, remove ``ExceptionGroup`` from ``safe_builtins`` (as useful only
186 with ``try/except*``). - This feature was introduced into
187 ``RestrictedPython`` in version 6.0 for Python 3.11+. (CVE-2025-22153)
188
189 - Drop support for Python 3.8.
190
191 Features
192 ++++++++
193
194 - Update setuptools version pin.
195 (`#292 <https://github.com/zopefoundation/RestrictedPython/issues/292>`_)
196
197
198 7.4 (2024-10-09)
199 ----------------
200
201 - Allow to use the package with Python 3.13.
202
203 - Drop support for Python 3.7.
204
205 - Provide new function ``RestrictedPython.Guards.safer_getattr_raise``.
206 It is similar to ``safer_getattr`` but handles its parameter
207 ``default`` like ``getattr``, i.e. it raises ``AttributeError``
208 if the attribute lookup fails and this parameter is not provided,
209 fixes `#287 <https://github.com/zopefoundation/RestrictedPython/issues/287>`_.
210
211
212 7.3 (2024-09-30)
213 ----------------
214
215 - Increase the safety level of ``safer_getattr`` allowing applications to use
216 it as ``getattr`` implementation. Such use should now follow the same policy
217 and give the same level of protection as direct attribute access in an
218 environment based on ``RestrictedPython``'s ``safe_builtints``.
219 - Prevent information leakage via ``AttributeError.obj``
220 and the ``string`` module. (CVE-2024-47532)
221
222
223 7.2 (2024-08-02)
224 ----------------
225
226 - Remove unneeded setuptools fossils that may cause installation problems
227 with recent setuptools versions.
228 - Add support for single mode statements / execution.
229 - Fix a potential breakout capability in the provided ``safer_getattr`` method
230 that is part of the ``safer_builtins``.
231
232
233 7.1 (2024-03-14)
234 ----------------
235
236 - Add support for the matmul (``@``) operator.
237
238
239 7.0 (2023-11-17)
240 ----------------
241
242 Backwards incompatible changes
243 ++++++++++++++++++++++++++++++
244
245 - Drop support for Python 3.6.
246
247 Features
248 ++++++++
249
250 - Officially support Python 3.12.
251
252 Fixes
253 +++++
254
255 - Prevent DeprecationWarnings from ``ast.Str`` and ``ast.Num`` on Python 3.12
256
257 - Forbid using some attributes providing access to restricted Python internals.
258 (CVE-2023-37271)
259
260 - Fix information disclosure problems through Python's "format" functionality
261 (``format`` and ``format_map`` methods on ``str`` and its instances,
262 ``string.Formatter``). (CVE-2023-41039)
263
264
265 6.0 (2022-11-03)
266 ----------------
267
268 Backwards incompatible changes
269 ++++++++++++++++++++++++++++++
270
271 - Drop support for Python 2.7 and 3.5.
272
273 Features
274 ++++++++
275
276 - Officially support Python 3.11.
277
278 - Allow to use the Python 3.11 feature of exception groups and except\*
279 (PEP 654).
280
281
282 5.2 (2021-11-19)
283 ----------------
284
285 - Document that ``__name__`` is needed to define classes.
286
287 - Add support for Python 3.10. Auditing the Python 3.10 change log did not
288 reveal any changes which require actions in RestrictedPython.
289
290 - Avoid deprecation warnings when using Python 3.8+.
291 (`#192 <https://github.com/zopefoundation/RestrictedPython/issues/192>`_)
292
293
294 5.1 (2020-10-07)
295 ----------------
296
297 Features
298 ++++++++
299
300 - Add support for (Python 3.8+) assignment expressions (i.e. the ``:=`` operator)
301
302 - Add support for Python 3.9 after checking the security implications of the
303 syntax changes made in that version.
304
305 - Add support for the ``bytes`` and ``sorted`` builtins
306 (`#186 <https://github.com/zopefoundation/RestrictedPython/issues/186>`_)
307
308 Documentation
309 +++++++++++++
310
311 - Document parameter ``mode`` for the ``compile_restricted`` functions
312 (`#157 <https://github.com/zopefoundation/RestrictedPython/issues/157>`_)
313
314 - Fix documentation for ``compile_restricted_function``
315 (`#158 <https://github.com/zopefoundation/RestrictedPython/issues/158>`_)
316
317 Fixes
318 +++++
319
320 - Fix ``compile_restricted_function`` with SyntaxErrors that have no text
321 (`#181 <https://github.com/zopefoundation/RestrictedPython/issues/181>`_)
322
323 - Drop install dependency on ``setuptools``.
324 (`#189 <https://github.com/zopefoundation/RestrictedPython/issues/189>`_)
325
326
327 5.0 (2019-09-03)
328 ----------------
329
330 Breaking changes
331 ++++++++++++++++
332
333 - Revert the allowance of the ``...`` (Ellipsis) statement, as of 4.0. It is
334 not needed to support Python 3.8.
335 The security implications of the Ellipsis Statement is not 100 % clear and is
336 not checked. ``...`` (Ellipsis) is disallowed again.
337
338 Features
339 ++++++++
340
341 - Add support for f-strings in Python 3.6+.
342 (`#123 <https://github.com/zopefoundation/RestrictedPython/issues/123>`_)
343
344
345 4.0 (2019-05-10)
346 ----------------
347
348 Changes since 3.6.0:
349
350 Breaking changes
351 ++++++++++++++++
352
353 - The ``compile_restricted*`` functions now return a
354 ``namedtuple CompileResult`` instead of a simple ``tuple``.
355
356 - Drop the old implementation of version 3.x: `RCompile.py`,
357 `SelectCompiler.py`, `MutatingWorker.py`, `RestrictionMutator.py` and
358 `tests/verify.py`.
359
360 - Drop support for long-deprecated ``sets`` module.
361
362 Security related issues
363 +++++++++++++++++++++++
364
365 - RestrictedPython now ships with a default implementation for
366 ``_getattr_`` which prevents from using the ``format()`` method on
367 str/unicode as it is not safe, see:
368 http://lucumr.pocoo.org/2016/12/29/careful-with-str-format/
369
370 **Caution:** If you do not already have secured the access to this
371 ``format()`` method in your ``_getattr_`` implementation use
372 ``RestrictedPython.Guards.safer_getattr()`` in your implementation to
373 benefit from this fix.
374
375 Features
376 ++++++++
377
378 - Mostly complete rewrite based on Python AST module.
379 [loechel (Alexander Loechel), icemac (Michael Howitz),
380 stephan-hof (Stephan Hofmockel), tlotze (Thomas Lotze)]
381
382 - Add support for Python 3.5, 3.6, 3.7.
383
384 - Add preliminary support for Python 3.8. as of 3.8.0a3 is released.
385
386 - Warn when using another Python implementation than CPython as it is not safe
387 to use RestrictedPython with other versions than CPyton.
388 See https://bitbucket.org/pypy/pypy/issues/2653 for PyPy.
389
390 - Allow the ``...`` (Ellipsis) statement. It is needed to support Python 3.8.
391
392 - Allow `yield` and `yield from` statements.
393 Generator functions would now work in RestrictedPython.
394
395 - Allow the following magic methods to be defined on classes.
396 (`#104 <https://github.com/zopefoundation/RestrictedPython/issues/104>`_)
397 They cannot be called directly but by the built-in way to use them (e. g.
398 class instantiation, or comparison):
399
400 + ``__init__``
401 + ``__contains__``
402 + ``__lt__``
403 + ``__le__``
404 + ``__eq__``
405 + ``__ne__``
406 + ``__gt__``
407 + ``__ge__``
408
409 - Imports like ``from a import *`` (so called star imports) are now forbidden
410 as they allow to import names starting with an underscore which could
411 override protected build-ins.
412 (`#102 <https://github.com/zopefoundation/RestrictedPython/issues/102>`_)
413
414 - Allow to use list comprehensions in the default implementation of
415 ``RestrictionCapableEval.eval()``.
416
417 - Switch to pytest as test runner.
418
419 - Bring test coverage to 100 %.
420
421 Bug fixes
422 +++++++++
423
424 - Improve `.Guards.safer_getattr` to prevent accessing names starting with
425 underscore.
426 (`#142 <https://github.com/zopefoundation/RestrictedPython/issues/142>`_)
427
428
429 3.6.0 (2010-07-09)
430 ------------------
431
432 - Add name check for names assigned during imports using the
433 ``from x import y`` format.
434
435 - Add test for name check when assigning an alias using multiple-context
436 ``with`` statements in Python 2.7.
437
438 - Add tests for protection of the iterators for dict and set comprehensions
439 in Python 2.7.
440
441 3.6.0a1 (2010-06-05)
442 --------------------
443
444 - Remove support for ``DocumentTemplate.sequence`` - this is handled in the
445 DocumentTemplate package itself.
446
447 3.5.2 (2010-04-30)
448 ------------------
449
450 - Remove a testing dependency on ``zope.testing``.
451
452 3.5.1 (2009-03-17)
453 ------------------
454
455 - Add tests for ``Utilities`` module.
456
457 - Filter DeprecationWarnings when importing Python's ``sets`` module.
458
459 3.5.0 (2009-02-09)
460 ------------------
461
462 - Drop legacy support for Python 2.1 / 2.2 (``__future__`` imports
463 of ``nested_scopes`` / ``generators``.).
464
465 3.4.3 (2008-10-26)
466 ------------------
467
468 - Fix deprecation warning: ``with`` is now a reserved keyword on
469 Python 2.6. That means RestrictedPython should run on Python 2.6
470 now. Thanks to Ranjith Kannikara, GSoC Student for the patch.
471
472 - Add tests for ternary if expression and for ``with`` keyword and
473 context managers.
474
475 3.4.2 (2007-07-28)
476 ------------------
477
478 - Changed homepage URL to the PyPI site
479
480 - Improve ``README.txt``.
481
482 3.4.1 (2007-06-23)
483 ------------------
484
485 - Fix http://www.zope.org/Collectors/Zope/2295: Bare conditional in
486 a Zope 2 PythonScript followed by a comment causes SyntaxError.
487
488 3.4.0 (2007-06-04)
489 ------------------
490
491 - RestrictedPython now has its own release cycle as a separate project.
492
493 - Synchronized with RestrictedPython from Zope 2 tree.
494
495 3.2.0 (2006-01-05)
496 ------------------
497
498 - Corresponds to the verison of the RestrictedPython package shipped
499 as part of the Zope 3.2.0 release.
500
501 - No changes from 3.1.0.
502
503 3.1.0 (2005-10-03)
504 ------------------
505
506 - Corresponds to the verison of the RestrictedPython package shipped
507 as part of the Zope 3.1.0 release.
508
509 - Remove unused fossil module, ``SafeMapping``.
510
511 - Replaced use of deprecated ``whrandom`` module with ``random`` (aliased
512 to ``whrandom`` for backward compatibility).
513
514 3.0.0 (2004-11-07)
515 ------------------
516
517 - Corresponds to the verison of the RestrictedPython package shipped
518 as part of the Zope X3.0.0 release.