CVE-2026-76825: RestrictedPython: Sandbox escape via string.Formatter field resolution
RestrictedPython is a tool that helps define a subset of the Python language for accepting program input in a trusted environment. Prior to 8.4, RestrictedPython could allow a sandbox escape when a custom import policy or globals exposed the standard library string module, the string.Formatter class, a Formatter instance, or a Formatter subclass to restricted code. The string.Formatter methods format, getfield, getvalue, and vformat performed attribute and item traversal internally without passing through RestrictedPython's safergetattr protections. Restricted code could use those live object references to reach function globals, builtins, file access, or code execution primitives, affecting confidentiality, integrity, and availability in the host environment. This issue is fixed in version 8.4.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
RestrictedPythonto a version that resolves this vulnerability.Fixed in 8.4
Event History
Frequently Asked Questions
Which deployments are exposed to this issue?
Deployments using RestrictedPython before version 8.4 are exposed if restricted code can access the standard-library string module, string.Formatter, a Formatter instance, or a Formatter subclass through custom import policy or supplied globals. The issue is not described as affecting configurations that do not expose any of those objects to restricted code.
What does an attacker need to exploit it?
An attacker needs the ability to submit or run restricted Python code and access to a live string.Formatter-related object through the sandbox's imports or globals. They can then abuse Formatter's internal attribute and item traversal, which bypasses RestrictedPython's safer_getattr protections.
What could successful exploitation allow?
Restricted code may escape the sandbox and reach function globals, builtins, file-access capabilities, or code-execution primitives in the host environment. This can affect confidentiality, integrity, and availability.
What should be done if an immediate upgrade is not possible?
Prevent restricted code from accessing the string module, string.Formatter, Formatter instances, and Formatter subclasses through custom import policies or supplied globals. This removes the object references identified as the path to exploitation until version 8.4 can be deployed.