The /api/compiler/execute endpoint never ran in a container
The compiler blueprint at backend/routes/compiler.py registers POST /execute. The route has no auth decorator and no session check. The handler reads the request body, dispatches on a language field, and calls one of execute_python, execute_java, execute_javascript, execute_cpp, or execute_c. The Python branch is sixty lines. The dispatch is subprocess.run:
def execute_python(code, input_data=""):
"""Execute Python code"""
try:
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
f.write(code)
temp_file = f.name
try:
start_time = time.time()
result = subprocess.run(
['python3', temp_file],
input=input_data,
text=True,
capture_output=True,
timeout=10, # 10 second timeout
cwd=tempfile.gettempdir()
)
There is no container. There is no chroot. There is no resource isolation. The Flask process spawns python3 /tmp/tmpXXXXXX.py as a child process with the caller's source on disk. The child inherits the Flask process's environment variables, its uid, its filesystem view, and its network namespace. The Java, JavaScript, C, and C++ branches are the same shape with different binaries and a subprocess.run(['javac', ...]) step in front of java.
The PoC's --shell mode probes this endpoint first. Its initial gadget is import os; print(os.getuid()). On a default docker compose deployment of OpenLearnX itself, the Flask container's entrypoint runs as root, and the response is UID:0. The PoC's evidence file records "auth_required": false. The advisory's CVSS vector is PR:L. The PoC's field is the accurate one.
A sandbox escape requires a sandbox. The compiler blueprint did not have one.
The /api/coding/execute endpoint mounted os.path.dirname(temp_file)
The coding blueprint at backend/routes/coding.py is the path the "sandbox escape" language was probably written about. Its /execute route is decorated with @secure_execution_required and delegates to execute_in_container. The pre-patch implementation:
def execute_in_container(code, language, test_cases):
"""Execute code in secure Docker container"""
try:
client = docker.from_env()
containers = {
'python': 'python:3.9-alpine',
'java': 'openjdk:11-alpine',
'javascript': 'node:16-alpine'
}
with tempfile.NamedTemporaryFile(mode='w', suffix=f'.{get_file_extension(language)}', delete=False) as f:
f.write(code)
temp_file = f.name
try:
container = client.containers.run(
containers[language],
command=get_run_command(language, temp_file),
volumes={os.path.dirname(temp_file): {'bind': '/app', 'mode': 'ro'}},
working_dir='/app',
mem_limit='128m',
cpu_period=100000,
cpu_quota=50000, # 50% CPU limit
network_mode='none', # No network access
remove=True,
timeout=10, # 10 second timeout
detach=False
)
The developer wrote in every isolation knob they thought to write. mem_limit='128m'. cpu_quota=50000. network_mode='none'. remove=True. mode='ro' on the volume. Each one is a deliberate addition. Each one targets a different exfiltration channel: memory pressure, CPU starvation, outbound network, persistence. The comments next to two of them (# 50% CPU limit, # No network access) are the developer narrating their threat model to themselves while they write the function.
The threat model in the comments does not mention the mount source. The volume entry reads os.path.dirname(temp_file). The developer's mental model of that expression is "the directory I just wrote my user's code into." That mental model is wrong on Linux. tempfile.NamedTemporaryFile() with no dir argument calls tempfile.gettempdir(), which returns $TMPDIR if set and /tmp otherwise. The directory the developer thinks belongs to their function is the system-wide scratch directory every other process on the host shares with them.
The mode='ro' flag does not save them. Read-only prevents the container from corrupting other tenants' files. Read-only does not prevent the container from reading them. The PoC's secrets gadget walks /app/*.conf, /app/*.pem, /app/*.key, /app/*.env, /app/*.json, /app/*.yml, /app/*.yaml, /app/*.cfg, /app/*.ini, /app/*.secret, /app/*.sock and prints the first 800 bytes of each match. The submissions gadget lists every .py file in /app other than the attacker's own and prints the first 600 bytes:
"code": textwrap.dedent("""\
import os, glob
own = os.path.abspath(__file__) if '__file__' in dir() else ''
pyfiles = [f for f in glob.glob('/app/*.py')
if os.path.isfile(f) and os.path.abspath(f) != own]
if pyfiles:
print(f"SUBMISSIONS:{len(pyfiles)}")
for f in sorted(pyfiles)[:10]:
print(f"\\n--- {os.path.basename(f)} ({os.path.getsize(f)}B) ---")
print(open(f).read()[:600])
""")
Both gadgets land because the container's /app is the host's /tmp, and the host's /tmp contains every other student's submission still being graded, every credential the application or its sidecars wrote there during initialization, and every key the operator left in a temp location during deployment.
The "sandbox escape" the advisory names is not an escape. The attacker uses the container's documented function: read the file it was given, print the contents to stdout. The contents happen to be every other tenant's homework and the platform's MongoDB connection string.
The secure_execution_required decorator checks a flag the caller sets
The coding blueprint's auth gate is twelve lines:
def secure_execution_required(f):
@wraps(f)
def decorated_function(*args, **kwargs):
if not session.get('secure_coding_mode'):
return jsonify({"error": "Secure coding mode required"}), 403
return f(*args, **kwargs)
return decorated_function
The decorator reads session['secure_coding_mode']. The session is the Flask client session, signed by the server but populated by route handlers. The route that populates it is start-session, in the same blueprint:
@bp.route("/start-session", methods=["POST"])
def start_coding_session():
"""Start a secure coding session"""
try:
data = request.json
...
session['coding_session_id'] = session_id
session['secure_coding_mode'] = True
...
There is no decorator on start-session. The route is callable without authentication. Any HTTP client that can POST /api/coding/start-session gets secure_coding_mode=True written into its own session cookie. It then POSTs to /api/coding/execute with that cookie, the decorator's session.get('secure_coding_mode') returns True, and the request enters the vulnerable execute_in_container. The "auth" is a question the application asks the caller about themselves. The caller answers yes.
The CVSS vector's PR:L describes this gate. The gate's privilege requirement is "ability to call another unauthenticated endpoint first."
What the patch had to add
Commit 14765d7d1856d564747c55c5412e2f38feab079e is the security fix. It deletes execute_in_container's body and replaces it with a call into a new real_compiler_service.execute_code. The new service's container invocation:
with tempfile.TemporaryDirectory(prefix="openlearnx_exec_") as temp_dir:
os.chmod(temp_dir, 0o755)
code_path = os.path.join(temp_dir, config["file_name"])
...
container = docker_client.containers.run(
config["image"],
command=self._build_execution_command(config),
volumes={temp_dir: {"bind": "/workspace", "mode": "rw"}},
working_dir="/workspace",
mem_limit=config["memory_limit"],
memswap_limit=config["memory_limit"],
cpu_period=100000,
cpu_quota=cpu_quota,
pids_limit=64,
network_mode="none",
detach=True,
stdin_open=False,
tty=False,
cap_drop=["ALL"],
security_opt=["no-new-privileges:true"],
read_only=True,
user="65534:65534",
tmpfs={
"/tmp": "rw,noexec,nosuid,size=64m",
},
...
)
The diff has eight pieces. tempfile.TemporaryDirectory(prefix="openlearnx_exec_") is the structural fix: a fresh per-execution directory, never the system shared tempdir. cap_drop=["ALL"] drops every Linux capability. security_opt=["no-new-privileges:true"] blocks set-uid escalation. user="65534:65534" is the nobody uid. read_only=True makes the container's rootfs immutable. tmpfs={"/tmp": "rw,noexec,nosuid,size=64m"} gives the container its own scratch space so attacker code that writes to /tmp does not touch the host's /tmp. pids_limit=64 blocks fork bombs. memswap_limit=mem_limit blocks swap-based pressure.
Each of these closes a different exposure. The headline closure is the first one. The other seven are defense-in-depth for what should have been a layered defense at v1. The pre-patch code added every knob the developer thought to add and missed the one whose name does not appear in the Docker SDK's "security" page: the value passed as the mount source.
The compiler blueprint at backend/routes/compiler.py is restructured in the same commit. The execute route now delegates to real_compiler_service.execute_code for every language, eliminating the on-host subprocess path. Two endpoints, two different shapes of bug, one commit. The advisory references only the commit.
OpenLearnX is a code-execution sandbox by occupation
the-detector-is-the-target names the shape where a product whose role obligates it to accept hostile input is itself the attack surface. The pattern's published exhibits, FortiSandbox, vm2, radare2, Zabbix's audit log, sit at the enterprise-security end of the spectrum: appliances and libraries whose value proposition is "we will run the bad thing and tell you what it did." OpenLearnX is the same shape with a different blast radius. The product's stated function is to let students submit code and execute it. Every student account is a hostile-input channel, by design. The platform's threat model is identical to a malware sandbox's threat model: the input is, by occupation, attacker-controlled.
What sets this exhibit apart from the FortiSandbox class is that the OpenLearnX implementation did not attempt to harden the sandbox the way an enterprise malware vendor does. The compiler blueprint runs Python via host subprocess. The coding blueprint hands the container the most-shared directory on the system. Neither is the architectural error of a researcher who has thought hard about isolation and found a subtle bypass. Both are the default the language gives a developer who calls tempfile.NamedTemporaryFile() and subprocess.run() without thinking about where the resulting paths point.
design-debt-driver names what comes next. The patch closes this CVE on the two endpoints the diff touches. The substrate is the architecture: a Flask app in charge of orchestrating sibling Docker containers, with a shared filesystem between the orchestrator and the sandboxes, with secure_execution_required as the auth gate, with the language's default tempfile API supplying the mount sources. The architecture survived the patch. The next CVE arrives when a third endpoint reaches for subprocess or docker_client.containers.run and the developer reuses the orchestrator's defaults again.
The cve.org title for this CVE is OpenLearnX has Critical Remote Code Execution Through Python Sandbox Escape via Code Execution Environment. The pre-patch code has no Python sandbox. There is a Flask handler that calls subprocess.run(['python3', tmpfile]), and there is a sibling-container invocation whose mount source is /tmp. Neither construction is what "sandbox" means anywhere else in the security literature. The advisory's framing was written by someone who knew the patch closed the right thing and did not look at what the patch replaced.
PoC: Christbowel/CVE-2026-41900-POC