CVE-2026-55830: RestrictedPython guard hooks can be shadowed via positional-only arguments
Impact
RestrictedPython rewrites sensitive operations to go through guard hooks. Attribute access becomes getattr(obj, name), item access becomes getitem(obj, key), writes go through write, and print goes through print. The embedding application supplies these hooks to enforce its policy.
Argument-name validation rejects these protected names for regular arguments, args, kwargs, and keyword-only arguments, but it misses positional-only arguments (the ones before /). So a function like:
python def f(getattr=evil, /): return o.x
makes getattr a local that shadows the policy hook, and the rewritten access calls evil instead. The same works for getitem, write, and print. Shadowing print can also be used to capture the internal getattr hook that RestrictedPython passes in.
The result is that sandboxed code can bypass the access policy the embedding application relies on. In applications that also handle sandbox-controlled objects unsafely (for example serializing them with pickle), this primitive can be chained further, up to remote code execution. That part depends on the embedding application, but the underlying guard bypass is in RestrictedPython.
Proof of concept
On an unpatched RestrictedPython this prints shadowed and an empty calls list, meaning the policy getattr never ran. With the fix, compilerestricted rejects the code.
python from RestrictedPython import compilerestricted from RestrictedPython.Guards import safeglobals, safergetattr
calls = [] def policygetattr(obj, name, default=None): calls.append(name) # the real guard records every access return safergetattr(obj, name, default)
src = """ def f(o, getattr=lambda obj, name: "shadowed", /): return o.x """
code = compilerestricted(src, "<s>", "exec") # currently compiles, should be rejected g = dict(safeglobals) g["getattr"] = policygetattr exec(code, g)
class O: x = "secret"
print(g"f")) # -> "shadowed" (attacker's local was used) print(calls) # -> [] (policy getattr never ran)
Patches
The fix validates positional-only argument names the same way the other argument kinds are already validated. It will ship in the next release.
Workarounds
None other than upgrading. If you cannot upgrade immediately, reject any submitted code whose function or lambda definitions use positional-only parameters with leading-underscore names before compiling.
Other sources
RestrictedPython is a tool that helps to define a subset of the Python language which allows to provide a program input into a trusted environment. Prior to 8.3, checkfunctionargumentnames() rejected protected guard hook names for regular, variadic, and keyword-only arguments but omitted positional-only arguments, allowing getattr, getitem, write, or print to be shadowed by a local parameter and bypass the embedding application's access policy. This issue is fixed in version 8.3.
— MITRE
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.3 - Upgrade
Upgrade
RestrictedPythonto a version that resolves this vulnerability.Fixed in 8.3 - Compensating control
If you cannot upgrade immediately, reject any submitted code whose function or lambda definitions use positional-only parameters with leading-underscore names (i.e., positional-only arguments before `/` with names that are protected guard hook names) before compiling with RestrictedPython.
Event History
Frequently Asked Questions
What is the severity of CVE-2026-55830?
CVE-2026-55830 has a severity rating of 8.3, categorized as high risk.
How do I fix CVE-2026-55830?
To fix CVE-2026-55830, upgrade to version 8.3 or later of RestrictedPython.
What are the potential impacts of CVE-2026-55830?
CVE-2026-55830 may allow unauthorized access to protected guard hook names, which poses a security risk.
What software is affected by CVE-2026-55830?
CVE-2026-55830 affects the RestrictedPython library.
When was CVE-2026-55830 published?
CVE-2026-55830 was published on July 8, 2026.