NewApp Monitoring is liveSign up free
AgentbeamBeta
AI agent vulnerability · Other MCP servers and tools

CVE-2026-53710: mcp-contextforge-gateway has RestrictedPython sandbox bypass via getattr builtin in python_sandbox_server

criticalCVSS 3.1 10.0GHSA-xm98-3vcf-fph7

The `python_sandbox_server` sub-project of IBM ContextForge (`mcp-contextforge-gateway` 1.0.1 and earlier) can be escaped. Its RestrictedPython sandbox exposes raw `getattr`, so submitted code can reach `subprocess.Popen` and run OS commands. If the server is reachable over HTTP or SSE, no login is needed. Upgrade to 1.0.2.

Published Aug 24, 2026 · Updated Oct 15, 2026 · Analysis Nov 1, 2026

What an attacker can do

The code lives in mcp-servers/python/python_sandbox_server/src/python_sandbox_server/server_fastmcp.py. Three weaknesses combine.

First, safe_builtins includes the raw getattr, which sidesteps the _getattr_ guard that RestrictedPython uses to mediate attribute access. Second, validate_code rejects only literal dangerous dunder strings, but the payload builds those names at runtime. Third, the execute_code MCP tool can be served over HTTP or SSE with no authentication layer.

The PoC builds the dunder names on the fly, walks the class hierarchy with getattr, finds subprocess.Popen and runs a harmless marker command. The validator reported Code passed validation, and the output contained the marker.

An attacker who can reach the HTTP endpoint, for instance when the sandbox is registered as a gateway in a running ContextForge instance, sends the payload through tools/call and runs commands with the server process's privileges. With host mounts or internal network reach, that can become file access or a pivot. The advisory says the core gateway and proxy are not directly affected, and that stdio-only deployments reduce the attack vector. The 10.0 score assumes HTTP reachability.

Who is affected

mcp-contextforge-gateway 1.0.1 and earlier, specifically deployments that run the python_sandbox_server sub-project over HTTP or SSE. The report was made against commit f855e54d5b7bc1c91b977574a03b91eff6b86bb6. Check:

pip show mcp-contextforge-gateway

Then look for a running python_sandbox_server and any gateway registration that points at it.

mcp-contextforge-gateway

Ecosystem
PyPI
Affected
<= 1.0.1
Fixed in
1.0.2
Check
pip show mcp-contextforge-gateway

How to fix it

Upgrade to 1.0.2:

pip install --upgrade mcp-contextforge-gateway==1.0.2

The fix is in commit 63a2900e6301b9c8a483a38d3737a1beb3a7ce89. The advisory's suggested design is to drop raw getattr and setattr from safe_builtins, allow only policy-controlled attribute access, replace substring filtering with a stricter RestrictedPython policy, and require authentication for all tools/call requests over HTTP. Until you upgrade, use stdio only and do not register the sandbox server as a reachable gateway.

How to tell if you were hit

Look in the sandbox server's logs and HTTP access logs for execute_code calls from unexpected clients, and for code containing getattr with string concatenation or joins that assemble names containing double underscores. On the host, look for child processes of the sandbox server such as sh or other binaries started through subprocess, and for unusual outbound connections from it.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

Commit: f855e54d5b7bc1c91b977574a03b91eff6b86bb6 Component: mcp-servers/python/python_sandbox_server/src/python_sandbox_server/server_fastmcp.py

Vulnerability

RestrictedPython's sandbox in ContextForge's python_sandbox_server sub-project allows arbitrary Python execution via three compounding weaknesses:

  1. Raw getattr is exposed in safe_builtins, bypassing _getattr_ mediation.
  2. validate_code checks for literal dangerous dunder strings, but the payload constructs those names at runtime.
  3. The execute_code MCP tool can be exposed over HTTP/SSE transport with no authentication layer.

Proof of Concept

The local PoC was executed against the real pinned sandbox code path. It constructs dunder names at runtime, walks Python's class hierarchy through the exposed getattr, finds subprocess.Popen, and executes a harmless marker command.

Transcript excerpt:

POC: IBM/mcp-context-forge RestrictedPython getattr sandbox bypass
validation={'valid': True, 'message': 'Code passed validation', 'warnings': None}
success=True
stdout="FOUND_POPEN\nb'IBM_SANDBOX_POC_PASS'\n"
IBM_RESTRICTEDPYTHON_GETATTR_POPEN_REPRO_PASS

PoC artifact hashes:

beb2d856c5a1b7c10005c9c0fccaf3d491d4fbcc2a69bc54b5e95c5730c0874b  run.py
1037dcb4f0831a3c96ca728527f939af1d3e19514b23ef54f663707875748ff8  run.sh
7026e676ee31916886f10feed959ffdbe486fda05b17421387e4717acbf90ba6  transcript.txt

Production Deployment Context

ContextForge's documentation describes registering MCP servers as gateways in a running ContextForge instance. If this sandbox server is reachable over HTTP in that pattern, any client that can reach the endpoint can submit the payload through tools/call.

Impact

An attacker with access to the python_sandbox_server HTTP endpoint can execute OS commands with the privileges of the server process. In containerized deployments with host mounts or internal network reachability, this can become filesystem compromise or network pivoting from the gateway host.

Suggested Fix

Remove raw getattr and setattr from safe_builtins, expose only policy-controlled attribute access if dynamic lookup is required, replace substring filtering with a stricter RestrictedPython policy pipeline, and add authentication to HTTP transport for all tools/call requests.

Caveats

This report covers the python_sandbox_server sub-project. The core ContextForge gateway and proxy components are not directly affected. The Critical score assumes HTTP reachability; stdio-only deployments reduce the attack vector.

Credited to dodge1218.

Questions

Is the whole ContextForge gateway vulnerable?

No. The advisory says the issue is in the python_sandbox_server sub-project and the core gateway and proxy are not directly affected.

Does the attacker need credentials?

Not if the sandbox is exposed over HTTP or SSE, since the execute_code tool has no authentication layer there.

Does the string filter in validate_code help?

No. It checks for literal dunder strings, and the exploit builds the names at runtime, so validation passes.

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology

More Other MCP servers and tools vulnerabilities

All Other MCP servers and tools entries