-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The `/api/compiler/execute` endpoint never ran in a container\n\nThe `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`:\n\n```python\ndef execute_python(code, input_data=\"\"):\n \"\"\"Execute Python code\"\"\"\n try:\n with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:\n f.write(code)\n temp_file = f.name\n\n try:\n start_time = time.time()\n result = subprocess.run(\n ['python3', temp_file],\n input=input_data,\n text=True,\n capture_output=True,\n timeout=10, # 10 second timeout\n cwd=tempfile.gettempdir()\n )\n```\n\nThere 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`.\n\nThe 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.\n\nA sandbox escape requires a sandbox. The compiler blueprint did not have one.\n\n## The `/api/coding/execute` endpoint mounted `os.path.dirname(temp_file)`\n\nThe `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:\n\n```python\ndef execute_in_container(code, language, test_cases):\n \"\"\"Execute code in secure Docker container\"\"\"\n try:\n client = docker.from_env()\n\n containers = {\n 'python': 'python:3.9-alpine',\n 'java': 'openjdk:11-alpine',\n 'javascript': 'node:16-alpine'\n }\n\n with tempfile.NamedTemporaryFile(mode='w', suffix=f'.{get_file_extension(language)}', delete=False) as f:\n f.write(code)\n temp_file = f.name\n\n try:\n container = client.containers.run(\n containers[language],\n command=get_run_command(language, temp_file),\n volumes={os.path.dirname(temp_file): {'bind': '/app', 'mode': 'ro'}},\n working_dir='/app',\n mem_limit='128m',\n cpu_period=100000,\n cpu_quota=50000, # 50% CPU limit\n network_mode='none', # No network access\n remove=True,\n timeout=10, # 10 second timeout\n detach=False\n )\n```\n\nThe 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.\n\nThe 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.\n\nThe `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:\n\n```python\n\"code\": textwrap.dedent(\"\"\"\\\n import os, glob\n own = os.path.abspath(__file__) if '__file__' in dir() else ''\n pyfiles = [f for f in glob.glob('/app/*.py')\n if os.path.isfile(f) and os.path.abspath(f) != own]\n if pyfiles:\n print(f\"SUBMISSIONS:{len(pyfiles)}\")\n for f in sorted(pyfiles)[:10]:\n print(f\"\\\\n--- {os.path.basename(f)} ({os.path.getsize(f)}B) ---\")\n print(open(f).read()[:600])\n\"\"\")\n```\n\nBoth 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.\n\nThe \"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.\n\n## The `secure_execution_required` decorator checks a flag the caller sets\n\nThe `coding` blueprint's auth gate is twelve lines:\n\n```python\ndef secure_execution_required(f):\n @wraps(f)\n def decorated_function(*args, **kwargs):\n if not session.get('secure_coding_mode'):\n return jsonify({\"error\": \"Secure coding mode required\"}), 403\n return f(*args, **kwargs)\n return decorated_function\n```\n\nThe 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:\n\n```python\n@bp.route(\"/start-session\", methods=[\"POST\"])\ndef start_coding_session():\n \"\"\"Start a secure coding session\"\"\"\n try:\n data = request.json\n ...\n session['coding_session_id'] = session_id\n session['secure_coding_mode'] = True\n ...\n```\n\nThere 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 `POST`s 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.\n\nThe CVSS vector's `PR:L` describes this gate. The gate's privilege requirement is \"ability to call another unauthenticated endpoint first.\"\n\n## What the patch had to add\n\nCommit `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:\n\n```python\nwith tempfile.TemporaryDirectory(prefix=\"openlearnx_exec_\") as temp_dir:\n os.chmod(temp_dir, 0o755)\n code_path = os.path.join(temp_dir, config[\"file_name\"])\n ...\n container = docker_client.containers.run(\n config[\"image\"],\n command=self._build_execution_command(config),\n volumes={temp_dir: {\"bind\": \"/workspace\", \"mode\": \"rw\"}},\n working_dir=\"/workspace\",\n mem_limit=config[\"memory_limit\"],\n memswap_limit=config[\"memory_limit\"],\n cpu_period=100000,\n cpu_quota=cpu_quota,\n pids_limit=64,\n network_mode=\"none\",\n detach=True,\n stdin_open=False,\n tty=False,\n cap_drop=[\"ALL\"],\n security_opt=[\"no-new-privileges:true\"],\n read_only=True,\n user=\"65534:65534\",\n tmpfs={\n \"/tmp\": \"rw,noexec,nosuid,size=64m\",\n },\n ...\n )\n```\n\nThe 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.\n\nEach 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.\n\nThe 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.\n\n## OpenLearnX is a code-execution sandbox by occupation\n\n[the-detector-is-the-target](/patterns/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.\n\nWhat 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.\n\n[design-debt-driver](/patterns/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.\n\nThe 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.\n\nPoC: [Christbowel/CVE-2026-41900-POC](https://github.com/Christbowel/CVE-2026-41900-POC)","closing_line":"The \"Python sandbox\" the cve.org title names is not in the codebase at commit `14765d7~1`. It first appears at commit `14765d7`.","hook_md":"The OpenLearnX advisory calls CVE-2026-41900 a \"Python sandbox escape.\" The pre-patch code has two endpoints that execute caller-supplied code. One runs Python as a subprocess on the host with no container at all. The other runs Python inside a Docker container whose `/app` mount source is `os.path.dirname(temp_file)`, where `temp_file` is the result of a no-`dir`-argument `tempfile.NamedTemporaryFile()`. Python's tempfile module resolves the no-`dir` call to the system default tempdir. On Linux, that is `/tmp`. The container's `/app` is the host's `/tmp`.\n\nThe student does not escape the sandbox. The sandbox was handed the host's shared scratch directory at boot.","post_id":343,"slug":"openlearnx-mounted-tmp-into-its-sandbox","title":"CVE-2026-41900: OpenLearnX Mounted /tmp Into Its Code Sandbox","type":"initial","unreadable_sentence":"The student does not escape the sandbox. The sandbox was handed the host's shared scratch directory at boot."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCajQyyQAKCRDeZjl4jgkQ JvHQAP4+Z4xy/4IZgnQALae0EpfDbaROANIiStsAb8QA1YZ+VAD/XUGm9+s17pWB 0qZTURYjo2Uvk4fJQDUEG1AZAVkRSQw= =R6H5 -----END PGP SIGNATURE-----