GHSA-hp3v-5vw7-fx9w: Infoleak
Impact RestrictedPython could allow a sandbox escape when a policy exposes the standard library string module, or otherwise exposes string.Formatter, to restricted code.
string.Formatter field resolution methods such as getfield can perform attribute and item traversal internally and return live object references. This can bypass RestrictedPython's normal attribute guards and may allow access to sensitive objects such as function globals, builtins, file access, or code execution primitives.
Users are impacted if they run untrusted code with RestrictedPython and expose string.Formatter, directly or indirectly, for example through a custom import policy or globals.
Patches The problem has been patched by blocking access to string.Formatter and unsafe string.Formatter traversal methods in safergetattr.
Users should upgrade to the patched release once available. Affected and patched version numbers should be filled in when the release is published.
Workarounds Do not expose the standard library string module or string.Formatter to restricted code.
If a custom import hook is used, deny imports of string or provide only a restricted wrapper that does not expose Formatter. If custom globals are supplied, ensure neither string.Formatter nor Formatter instances are available to restricted code.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/RestrictedPythonto a version that resolves this vulnerability.Fixed in 8.4 - Configuration
Ensure `safer_getattr` blocks access to the standard library `string.Formatter` and unsafe `string.Formatter` traversal methods (e.g., methods like `get_field`), so restricted code cannot obtain live object references via field resolution.
RestrictedPython safer_getattr (attribute access behavior) = block `string.Formatter` and unsafe `string.Formatter` traversal methods - Configuration
Do not expose the standard library `string` module or `string.Formatter` to restricted code. Also ensure that `Formatter` instances are not available to restricted code via any custom globals supplied.
RestrictedPython policy / sandbox globals Availability of `string` module and `string.Formatter` = not exposed to restricted code - Configuration
If a custom import hook is used, deny imports of `string`, or provide only a restricted wrapper that does not expose `Formatter` to restricted code.
RestrictedPython custom import hook Denied imports = deny `string` (or provide only a restricted wrapper that does not expose `Formatter`) - Compensating control
If you cannot upgrade yet, restrict how untrusted code is executed so that restricted code cannot reach `string.Formatter` (directly or indirectly) through a custom import policy or provided globals.
Event History
Frequently Asked Questions
Which deployments are exposed to this issue?
Deployments that execute untrusted code with RestrictedPython are impacted if that code can access the standard-library string module or string.Formatter, whether directly or indirectly. This can occur through custom import policies or globals exposed to restricted code.
What access does an attacker need to exploit the issue?
An attacker needs the ability to run restricted, untrusted code in a deployment that exposes string.Formatter or the string module. The vulnerable Formatter field-resolution behavior can then return live object references while traversing attributes or items.
What can be done before a patched release is available?
Do not expose the string module or string.Formatter to restricted code. Where a custom import hook is used, deny imports of string or provide only a restricted wrapper that does not expose Formatter traversal methods.
What is the potential impact of successful exploitation?
The sandbox escape may bypass normal attribute guards and allow access to sensitive objects, including function globals, builtins, file access, or code-execution primitives.