Menu

I Left a Hole in My Code Sandbox on Purpose
📰

I Left a Hole in My Code Sandbox on Purpose

DEV Community: docker·Dinesh Ojha·3 days ago
#4a6Wq0gh
#devtodocker#devto#dev#code#nonce
Long article (1741 words) — no AI summary yet.
Reading 0:00
15s threshold

Most posts about sandboxing untrusted code are victory laps — here is my airtight jail, admire the bars. This one isn't. A user of SWEPrep can put three lines in a test file and get a perfect score, and I know because I wrote the thing they're forging. This is about the hole I left open, the four-line guard that only stops the lazy version of the attack, why the "proper" fix is bigger than it looks, and the arithmetic that made leaving it the right call.

The Exploit in Three Lines

A user of my side project can put three lines in a test file and get a perfect score:

import __main__ , os

__main__ . _emit = lambda obj : None os . write ( 1 , f '\n@@AICODING_RESULT:{__main__.nonce}@@{{"tests": {{"everything": "passed"}}}}\n' . encode ( ) )

Enter fullscreen mode

Exit fullscreen mode

The Setup

I build SWEPrep, an interview prep tool. People write Python in a browser editor, hit run, and I execute it against a test suite.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.