High

RestrictedPython vulnerable to arbitrary code execution via stack frame sandbox escape

  • Disclosed: 10.07.2023
  • Updated: 11.10.2026 15:17

Impact

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. 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 scope allowing the call of unrestricted Python code and therefore 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.

Patches

The problem has been fixed in releases 5.3 and 6.1.

Workarounds

There is no workaround available. If you cannot upgrade to the latest release you should ensure the RestrictedPython environment is only available for trusted users.

References

For more information

If you have any questions or comments about this advisory:

Credits

Thanks for analysing and reporting the go to:

  • Nakul Choudhary (Quasar0147 on GitHub)
  • despawningbone on GitHub
  • Robert Xiao (nneonneo on GitHub)

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
Python (PyPI) restrictedpython < 5.3, >= 6.0a1.dev0, < 6.1, < 5.3 5.3, 6.1

References

CVSS score 8.4/10
CVSS vector
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L
Weakness (CWE)
CWE-913
Platform
Python (PyPI)
Package
restrictedpython
Disclosed
10.07.2023
Updated
11.10.2026 15:17

Sources and licenses

OSV / GitHub Advisory Database - PYSEC-2023-118 - PyPA Advisory Database; CC BY 4.0

OSV / GitHub Advisory Database - GHSA-wqc8-x2pr-7jqh - CC BY 4.0

Vulnerability history: restrictedpython

All published vulnerabilities of this package (Python (PyPI)), newest first. Shows whether this is a one-off slip or a package that needs watching.

Total entries
6
First → latest
07.2023 09.2026
Without a fix
0
Exploited in attacks
0

Severity breakdown

  • High 6

Disclosures per year

  1. 2023: 2
  2. 2024: 1
  3. 2025: 1
  4. 2026: 2
  1. High · 8.3 CVE-2023-41039 < 5.4, >= 6.0, < 6.2 5.4, 6.2
  2. RestrictedPython vulnerable to arbitrary code execution via stack frame sandbox escape this entry
    High · 8.4 CVE-2023-37271 < 5.3, >= 6.0a1.dev0, < 6.1, < 5.3 5.3, 6.1

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.