CVE-2023-37271: 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
- RestrictedPython security advisory GHSA-wqc8-x2pr-7jqh
For more information
If you have any questions or comments about this advisory:
- Open an issue in the RestrictedPython issue tracker - Email us at security@plone.org
Credits
Thanks for analysing and reporting the go to: - Nakul Choudhary (Quasar0147 on GitHub) - despawningbone on GitHub - Robert Xiao (nneonneo on GitHub)
Other sources
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.
— MITRE
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/restrictedpythonto a version that resolves this vulnerability.Fixed in 5.3 - Upgrade
Upgrade
pip/RestrictedPythonto a version that resolves this vulnerability.Fixed in 6.1 - Upgrade
Upgrade
pip/RestrictedPythonto a version that resolves this vulnerability.Fixed in 5.3 - Upgrade
Upgrade
debian/restrictedpythonto a version that resolves this vulnerability.Fixed in 8.0-1 - Upgrade
Upgrade
RestrictedPythonto a version that resolves this vulnerability.Fixed in 5.3 - Upgrade
Upgrade
RestrictedPythonto a version that resolves this vulnerability.Fixed in 6.1 - Compensating control
Ensure the RestrictedPython environment is only available for trusted users (because any deployment that allows untrusted users to write Python code in the RestrictedPython environment is at risk). In Zope/Plone terms, limit administrator ability for untrusted users to create/edit object types: `Script (Python)`, `DTML Method`, `DTML Document`, or `Zope Page Template`.
Event History
Frequently Asked Questions
What is CVE-2023-37271?
CVE-2023-37271 is a vulnerability that affects RestrictedPython, a tool used to define a subset of the Python language.
What is the impact of CVE-2023-37271?
The impact of CVE-2023-37271 is that it allows an attacker with access to a RestrictedPython environment to write code that can access stack frames and their attributes, potentially leading to unauthorized access or privilege escalation.
What software is affected by CVE-2023-37271?
The software affected by CVE-2023-37271 is Zope RestrictedPython version up to 5.3, Zope RestrictedPython version 6.0-a1.dev0, and Zope RestrictedPython version 6.0.
How severe is CVE-2023-37271?
CVE-2023-37271 has a severity rating of critical with a severity value of 9.
How can I fix CVE-2023-37271?
To fix CVE-2023-37271, update to Zope RestrictedPython version 6.1 or higher, or update the pip package 'restrictedpython' to version 5.3 or higher.