CVE-2023-37271 RestrictedPython vulnerable to arbitrary code execution via stack frame sandbox escape
Attackers can escape the RestrictedPython sandbox via stack frame access to execute arbitrary code, affecting deployments allowing untrusted Python code.
- Exploited in the wild
- Not known
- Login needed
- Any signed-in user
- Attackable
- Over the internet
- Victim action needed
- Not needed
- Fix
- Available
What is CVE-2023-37271?
CVE-2023-37271 is a high-severity code injection vulnerability in zopefoundation RestrictedPython, published on 11 Jul 2023. Any signed-in user can exploit it over the network, with no action from the victim.
Official 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.
Weakness: CWE-913
Which versions are affected by CVE-2023-37271?
6 open source packages ship an affected version, including restrictedpython and RestrictedPython. It affects 1 product.
| Package | Affected | Fixed in |
|---|---|---|
restrictedpython PyPI | All versions | 5.3 |
restrictedpython PyPI | All versions | 5.3 |
restrictedpython PyPI | All versions | 5.3 |
restrictedpython PyPI | From 6.0a1.dev0 | 6.1 |
RestrictedPython PyPI | All versions | 5.3 |
RestrictedPython PyPI | From 6.0a1.dev0 | 6.1 |
Products include Zope Restrictedpython.
How do I fix CVE-2023-37271?
Upgrade restrictedpython to a fixed version for your release line: 5.3 or 6.1.
Upgrade, and never evaluate templates, expressions or code built from user input. More about Code injection.
Is CVE-2023-37271 being exploited?
There is no known exploitation of CVE-2023-37271 in the wild and no public exploit code.
Other vulnerabilities in zopefoundation RestrictedPython
Sources
Also known as DEBIAN-CVE-2023-37271, GHSA-wqc8-x2pr-7jqh, PYSEC-2023-118, UBUNTU-CVE-2023-37271.