Skip to content
RCE Write-up Advanced

Type Confusion in RestrictedPython (CVE-2025–22153)

A type confusion bug in CPython's try/except* syntax allowed RestrictedPython's sandbox to be bypassed, enabling arbitrary code execution. The text claims an attacker could craft input that breaks out of the restricted environment.

medium.com

Published on medium.com

This vulnerability in RestrictedPython is due to a type confusion bug in CPython versions 3.11 to 3.13.1, specifically when using the try/except syntax. This syntax was introduced in Python 3.11 for handling exception groups.

Rhoda Smart, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the way RestrictedPython processes try/except* clauses fails to handle unexpected object types, so exception-handling logic is misinterpreted and the sandbox is bypassed.

Impact

An attacker could break out of the restricted execution environment and execute arbitrary code, though the text gives no working exploit and only promises a proof of concept later.

What the attacker needed

Python 3.11 to 3.13.1; RestrictedPython 6.0 to below 8.0; ability to run try/except* in sandbox

The fix

RestrictedPython was fixed in version 8.0, which removes support for try/except*; as a workaround, use Python 3.10 or lower.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

RestrictedPython is a tool that lets a program run other people's Python code in a safe box, so that code cannot do harmful things. A bug in how Python itself handles a newer error-handling feature meant that the safe box could be escaped, letting the untrusted code run freely. The text does not show the actual exploit, only that the escape is possible.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.