Vulnerabilities in pkg:pypi/restrictedpython
PACKAGECVE-2023-37271 is a HIGH (CVSS 8.4) restrictedpython vulnerable to arbitrary code vulnerability (CWE-913: Improper Control of Dynamically-Managed Code Resources) affecting RestrictedPython libraries in the PyPI ecosystem. The issue involves restrictedpython vulnerable to arbitrary code execution via stack frame sandbox escape. Remediation is available by upgrading affected packages to version 5.3, 6.1.
pkg:pypi/restrictedpython
Vulnerability advisories affecting package pkg:pypi/restrictedpython. Select an advisory below to view technical details or fixes.
| Advisory ID | CVE / NVD | Severity | Summary |
|---|---|---|---|
| GHSA-wqc8-x2pr-7jqh | CVE-2023-37271 | HIGH | RestrictedPython vulnerable to arbitrary code execution via stack frame sandbox escape |
CVE-2023-37271 at a Glance
Security Impact
CVSS: 8.4
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L).
How to Fix CVE-2023-37271
To remediate this vulnerability, upgrade all affected RestrictedPython dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
pip install RestrictedPython>=5.3
pip install RestrictedPython>=6.1
pip install restrictedpython>=5.3
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
pip show RestrictedPython
How to Check if You Are Affected
To determine whether your Python environment is affected by CVE-2023-37271, inspect your installed packages using pip:
pip show RestrictedPython
Analyze the terminal output to locate any version of RestrictedPython in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 5.3), your application is affected.
Note: The pip show RestrictedPython command checks currently installed packages in your active Python environment.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-913: Improper Control of Dynamically-Managed Code Resources, where the product does not properly restrict reading from or writing to dynamically-managed code resources such as variables, objects, classes, attributes, functions, or executable instructions or statements. In RestrictedPython, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2023-37271 Affected RestrictedPython Versions
3 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
RestrictedPython
|
PyPI |
< 5.3
|
5.3
|
|
RestrictedPython
|
PyPI |
≥ 6.0a1.dev0
< 6.1
|
6.1
|
|
restrictedpython
|
PyPI |
< 5.3
|
5.3
|
References
Frequently Asked Questions
What is CVE-2023-37271?
Which RestrictedPython versions are affected?
What version fixes CVE-2023-37271?
Is RestrictedPython affected?
Is restrictedpython affected?
What is the CVSS score of CVE-2023-37271?
What CWE is associated with CVE-2023-37271?
How can I check PyPI dependencies for CVE-2023-37271?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-wqc8-x2pr-7jqh",
"modified" : "2023-07-11T19:40:20Z",
"published" : "2023-07-10T21:53:22Z",
"aliases" : [ "CVE-2023-37271" ],
"summary" : "RestrictedPython vulnerable to arbitrary code execution via stack frame sandbox escape",
"details" : "### Impact\n\nRestrictedPython 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.\n\nAll 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.\n\n### Patches\n\nThe problem has been fixed in releases 5.3 and 6.1.\n\n### Workarounds\n\nThere is no workaround available. If you cannot upgrade to the latest release you should ensure the RestrictedPython environment is only available for trusted users.\n\n### References\n\n- [RestrictedPython security advisory GHSA-wqc8-x2pr-7jqh](https://github.com/zopefoundation/RestrictedPython/security/advisories/GHSA-wqc8-x2pr-7jqh)\n\n## For more information\n\nIf you have any questions or comments about this advisory:\n\n- Open an issue in the [RestrictedPython issue tracker](https://github.com/zopefoundation/RestrictedPython/issues)\n- Email us at [security@plone.org](mailto:security@plone.org)\n\n## Credits\n\nThanks for analysing and reporting the go to:\n- Nakul Choudhary (Quasar0147 on GitHub)\n- despawningbone on GitHub\n- Robert Xiao (nneonneo on GitHub)",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:C/C:H/I:H/A:L"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "PyPI",
"name" : "RestrictedPython"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "5.3"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "RestrictedPython"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "6.0a1.dev0"
}, {
"fixed" : "6.1"
} ]
} ]
}, {
"package" : {
"ecosystem" : "PyPI",
"name" : "restrictedpython"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "5.3"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/zopefoundation/RestrictedPython/security/advisories/GHSA-wqc8-x2pr-7jqh"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-37271"
}, {
"type" : "WEB",
"url" : "https://github.com/zopefoundation/RestrictedPython/commit/c8eca66ae49081f0016d2e1f094c3d72095ef531"
}, {
"type" : "WEB",
"url" : "https://github.com/pypa/advisory-database/tree/main/vulns/restrictedpython/PYSEC-2023-118.yaml"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/zopefoundation/RestrictedPython"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-913" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2023-07-10T21:53:22Z",
"nvd_published_at" : "2023-07-11T18:15:20Z"
}
}