CVE-2023-37271
RestrictedPython vulnerable to arbitrary code execution via stack frame sandbox escape
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.
Attack profile
How easy it is to exploit
- Attack vector
- Network
- Complexity
- High
- Privileges needed
- Low
- User interaction
- None
What an attacker can affect
- Confidentiality
- High
- Integrity
- High
- Availability
- Low
Exploit likelihood
What each source reports
CVE List Score used
8.4
RestrictedPython vulnerable to arbitrary code execution via stack frame sandbox escape
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.
- Record
CVE-2023-37271- CVSS 3.1
- 8.4 High
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L - Weakness
- CWE-913
- Updated
- 2026-11-02
EUVDEUVD-2023-0228
8.4
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.
- Record
EUVD-2023-0228- CVSS 3.1
- 8.4 High
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L - Updated
- 2026-11-03
GitHub AdvisoriesGHSA-wqc8-x2pr-7jqh
8.4
RestrictedPython vulnerable to arbitrary code execution via stack frame sandbox escape
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:
- Open an issue in the RestrictedPython issue tracker
- Email us at [email protected]
Credits
Thanks for analysing and reporting the go to:
- Nakul Choudhary (Quasar0147 on GitHub)
- despawningbone on GitHub
- Robert Xiao (nneonneo on GitHub)
- Record
GHSA-wqc8-x2pr-7jqh- CVSS 3.1
- 8.4 High
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L - Weakness
- CWE-913
- Updated
- 2026-11-02
NVD
8.4
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.
- Record
CVE-2023-37271- CVSS 3.1
- 8.4 High
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L - CVSS 3.1
- 9.9 Critical
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H - Weakness
- CWE-913
- Updated
- 2026-11-02
OSV
8.4
RestrictedPython vulnerable to arbitrary code execution via stack frame sandbox escape
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.
- Record
CVE-2023-37271- CVSS 3.1
- 8.4 High
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L - Weakness
- CWE-913
- Updated
- 2026-11-02
OSVDEBIAN-CVE-2023-37271
9.9
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.
- Record
DEBIAN-CVE-2023-37271- CVSS 3.1
- 9.9 Critical
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H - Updated
- 2026-11-02
Show 4 moreShow less
OSVGHSA-wqc8-x2pr-7jqh
8.4
RestrictedPython vulnerable to arbitrary code execution via stack frame sandbox escape
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:
- Open an issue in the RestrictedPython issue tracker
- Email us at [email protected]
Credits
Thanks for analysing and reporting the go to:
- Nakul Choudhary (Quasar0147 on GitHub)
- despawningbone on GitHub
- Robert Xiao (nneonneo on GitHub)
- Record
GHSA-wqc8-x2pr-7jqh- CVSS 3.1
- 8.4 High
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L - Weakness
- CWE-913
- Updated
- 2026-11-02
OSVUBUNTU-CVE-2023-37271
8.4
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.
- Record
UBUNTU-CVE-2023-37271- CVSS 3.1
- 8.4 High
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L - CVSS 3.1
- 9.9 Critical
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H - Updated
- 2026-11-02
OSVPYSEC-2023-118 No score
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.
- Record
PYSEC-2023-118- Updated
- 2026-11-02
OSVUSN-7355-1 No score
restrictedpython vulnerabilities
Nakul Choudhary and Robert Xiao discovered that RestrictedPython did not properly sanitize certain inputs. An attacker could possibly use this issue to execute arbitrary code. This issue only affected Ubuntu 20.04 LTS and Ubuntu 22.04 LTS. (CVE-2023-37271)
Abhishek Govindarasu, Ankush Menat and Ward Theunisse discovered that RestrictedPython did not correctly handle certain format strings. An attacker could possibly use this issue to leak sensitive information. This issue only affected Ubuntu 20.04 LTS and Ubuntu 22.04 LTS. (CVE-2023-41039)
It was discovered that RestrictedPython did not correctly restrict access to certain fields. An attacker could possibly use this issue to leak sensitive information. (CVE-2024-47532)
It was discovered that RestrictedPython contained a type confusion vulnerability. An attacker could possibly use this issue to execute arbitrary code. This issue only affected Ubuntu 24.04 LTS and Ubuntu 24.10. (CVE-2025-22153)
- Record
USN-7355-1- Updated
- 2026-11-02
Affected products
Affected packages
| Package | Affected | Fixed |
|---|---|---|
restrictedpythonPyPI |
before 5.3 | 5.3 |
restrictedpythonPyPI |
6.0a1.dev0 up to 6.1 | 6.1 |
restrictedpythonDebian:12 |
All versions, plus listed versions 4.0~b3-36.2-18.0-18.1-18.4-1 |
None known |
restrictedpythonDebian:13 |
before 6.2-1 | 6.2-1 |
restrictedpythonDebian:14 |
before 6.2-1 | 6.2-1 |
restrictedpythonPyPI |
before 5.3, plus listed versions 3.4.23.4.33.5.03.5.13.5.2 Show 19 moreShow less3.6.03.6.0a14.04.0a14.0a24.0a34.0b14.0b24.0b34.0b44.0b54.0b64.0b74.0b85.05.15.25.2a1.dev05.3a1.dev0 |
5.3 |
restrictedpythonPyPI |
6.0a1.dev0 up to 6.1, plus listed versions 6.0 |
6.1 |
restrictedpythonUbuntu:Pro:20.04:LTS |
before 4.0~b3-2ubuntu0.1~esm1, plus listed versions 4.0~b3-2 |
4.0~b3-2ubuntu0.1~esm1 |
restrictedpythonUbuntu:Pro:22.04:LTS |
before 4.0~b3-3ubuntu0.1~esm1, plus listed versions 4.0~b3-24.0~b3-2ubuntu14.0~b3-3 |
4.0~b3-3ubuntu0.1~esm1 |
restrictedpythonUbuntu:Pro:20.04:LTS From an advisory covering 4 CVEs |
before 4.0~b3-2ubuntu0.1~esm1, plus listed versions 4.0~b3-2 |
4.0~b3-2ubuntu0.1~esm1 |
restrictedpythonUbuntu:Pro:22.04:LTS From an advisory covering 4 CVEs |
before 4.0~b3-3ubuntu0.1~esm1, plus listed versions 4.0~b3-24.0~b3-2ubuntu14.0~b3-3 |
4.0~b3-3ubuntu0.1~esm1 |
restrictedpythonUbuntu:Pro:24.04:LTS From an advisory covering 4 CVEs |
before 6.2-1ubuntu0.24.04.1~esm1, plus listed versions 4.0~b3-36.2-1 |
6.2-1ubuntu0.24.04.1~esm1 |
History
| Recorded | Changed | Sources |
|---|---|---|
| affected, facts | ||
| aliases | EUVD | |
| first indexed | CVE List, GitHub Advisories, NVD, OSV |
Dates are when Every CVE recorded each change. Upstream dates may differ.
In short
CVE-2023-37271 is a high vulnerability (CVSS 8.4) in Zope Restrictedpython, published July 10, 2023. No source lists public exploit code. EPSS puts the chance of exploitation in the next 30 days at 0.85%, the 58th percentile. Fixed in restrictedpython 5.3.
References
github.com/zopefoundation/RestrictedPython/security/advisories/GHSA-wqc8-x2pr-7jqh
github.com/zopefoundation/RestrictedPython/commit/c8eca66ae49081f0016d2e1f094c3d72095ef531
nvd.nist.gov/vuln/detail/CVE-2023-37271
github.com/pypa/advisory-database/tree/main/vulns/restrictedpython/PYSEC-2023-118.yaml
github.com/advisories/GHSA-wqc8-x2pr-7jqh
github.com/CVEProject/cvelistV5/tree/main/cves/2023/37xxx/CVE-2023-37271.json
Show 8 moreShow less
security-tracker.debian.org/tracker/CVE-2023-37271
github.com/zopefoundation/RestrictedPython
ubuntu.com/security/CVE-2023-37271
cve.org/CVERecord?id=CVE-2023-37271
ubuntu.com/security/notices/USN-7355-1
ubuntu.com/security/CVE-2023-41039
ubuntu.com/security/CVE-2024-47532
ubuntu.com/security/CVE-2025-22153