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

High 8.4 Published Updated

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.

PackageAffectedFixed in
restrictedpython PyPIAll versions5.3
restrictedpython PyPIAll versions5.3
restrictedpython PyPIAll versions5.3
restrictedpython PyPIFrom 6.0a1.dev06.1
RestrictedPython PyPIAll versions5.3
RestrictedPython PyPIFrom 6.0a1.dev06.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.

Sources

Also known as DEBIAN-CVE-2023-37271, GHSA-wqc8-x2pr-7jqh, PYSEC-2023-118, UBUNTU-CVE-2023-37271.

Is CVE-2023-37271 in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free