You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
The /custom_tools/test endpoint is vulnerable to Remote Code Execution (RWE) via unsafe code execution in the input_model parameter, despite attempts to restrict execution using a namespace. While the endpoint uses exec(request.input_model, namespace) with a limited namespace containing only BaseModel and Field, attackers can bypass these restrictions by injecting arbitrary Python code. The exec() function executes the entire input_model string in the provided namespace, but injected code can:
Execute system commands directly within the input_model payload.
This occurs because the exec() context allows imported modules or functions to escape the namespace’s intended constraints, enabling full control over the server’s environment.
Exploit
An attacker can craft an input_model payload that defines a seemingly valid Pydantic model while simultaneously injecting malicious code. For example:
Description
The
/custom_tools/test
endpoint is vulnerable to Remote Code Execution (RWE) via unsafe code execution in theinput_model
parameter, despite attempts to restrict execution using a namespace. While the endpoint usesexec(request.input_model, namespace)
with a limited namespace containing onlyBaseModel
andField
, attackers can bypass these restrictions by injecting arbitrary Python code. Theexec()
function executes the entireinput_model
string in the provided namespace, but injected code can:os
,subprocess
),__import__
),input_model
payload.This occurs because the
exec()
context allows imported modules or functions to escape the namespace’s intended constraints, enabling full control over the server’s environment.introspect/backend/tools/tool_routes.py
Line 488 in a8e4dbb
Exploit
An attacker can craft an
input_model
payload that defines a seemingly valid Pydantic model while simultaneously injecting malicious code. For example:How it works:
exec()
function executes the entire payload, including the__import__
line.__import__("os")
dynamically imports theos
module outside the restricted namespace, granting access to system commands.curl | bash
) is executed with the server’s privileges.Bypassing Namespace Limitations:
BaseModel
andField
, theexec()
context allows attackers to:__import__
oreval
to load forbidden modules.;
or newlines) in theinput_model
string.Affected
code from
introspect/backend/tools/tool_routes.py
Line 488 in a8e4dbb
From v0.1.0 to v0.1.4
The latest main branch also has this vulnerability.
The text was updated successfully, but these errors were encountered: