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.…