From 363d77ad7ee3be2538a48643620b3e4e97f55538 Mon Sep 17 00:00:00 2001 From: Eliot Robson Date: Wed, 18 Nov 2026 15:32:16 -0500 Subject: [PATCH] Stop student code from reading the test files Co-Authored-By: Claude Opus 5.5 --- docker/run.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docker/run.sh b/docker/run.sh index 68e17b2..f937a48 100644 --- a/docker/run.sh +++ b/docker/run.sh @@ -37,7 +37,17 @@ mv $MERGE_DIR/test_student/test_student.py $MERGE_DIR/test_student.py # Student code runs as ag, whose uid may match the owner of files mounted from the host. Stop it from # changing the tests and the submission, since tests read them after student code has run (for # example, a data file the tests_dir fixture reads to compute expected values). -if ! { chown -R root:root "$MERGE_DIR" && chmod -R go-w "$MERGE_DIR"; }; then +# Also stop it from reading the test files, which can hold expected values and reference code. It can +# only pass through the folders to reach student/, which workspace mode imports from. The grader reads +# leading code, setup code, helper modules and data files, and hands them to the sandbox. +protect_grading_files() { + chown -R root:root "$MERGE_DIR" || return 1 + chmod -R go-rwx "$MERGE_DIR" || return 1 + chmod go+x "$MERGE_DIR" "$MERGE_DIR/test_student" || return 1 + chmod -R go+rX "$MERGE_DIR/test_student/student" +} + +if ! protect_grading_files; then echo '{"succeeded": false, "score": 0.0, "message": "The autograder could not protect its grading files. Please contact course staff and have them check the logs for this submission."}' > "$OUT_DIR/results.json" echo "ERROR: could not protect $MERGE_DIR" exit 1