.git, secrets baked into layers instead of injected per run, workers that still hold Linux capabilities, and base images whose package repos silently die. Each has a one-line-or-less fix; together they are the difference between a sandbox and a suggestion.1. Symlink and parent-path escapes during extraction and mounting
Symptom. A submitted archive contained a symlink assets -> /etc followed by a regular file assets/cron.d/pwn. The validation pass walked the archive entries (all paths looked in-bounds), the extraction pass followed the symlink, and the "contained" workload wrote outside the workdir.
Failure shape. Any pipeline that validates path strings, then hands extraction to a library that resolves symlinks or accepts .. segments, has a time-of-check-to-time-of-use gap measured in milliseconds.
Fix. Validate on normalized, resolved paths at the moment of write; extract with symlink dereferencing disabled; mount scratch as tmpfs so even a successful escape lands in memory that dies with the container:
import os, tarfile
def safe_extract(member, dest_root, workdir):
# normalize + lexical cleanup BEFORE any filesystem touch
target = os.path.realpath(os.path.join(dest_root, member.name))
if os.path.commonpath([target, workdir]) != os.path.realpath(workdir):
raise EscapeError(member.name)
if member.issym() or member.islnk():
# materialize symlinks only inside the workdir, never across it
link = os.path.realpath(os.path.join(os.path.dirname(target), member.linkname))
if os.path.commonpath([link, workdir]) != os.path.realpath(workdir):
raise EscapeError(member.linkname)
return target
Runtime side: docker run --read-only --tmpfs /work:rw,size=64m,exec. A read-only root filesystem converts most escape attempts into loud EROFS failures.
2. .git history and build-cache context leaks
Symptom. A harness image built from a repo directory shipped the full .git database, including objects from a branch where a live credential had briefly been committed and rotated. Anyone with image pull access (or docker history on a shared runner) had the history.
Failure shape. Build context is the whole directory unless excluded; multi-stage builds help only if the sensitive tree is never COPYed, and BuildKit --mount=type=cache directories persist across builds of unrelated PRs on the same runner.
Fix. Three lines, in order of leverage:
# .dockerignore, the cheapest security control you will write today
.git
.env
**/__pycache__
node_modules
- Scope cache mounts per branch when they touch anything secret-adjacent:
--mount=type=cache,id=pip-${PR_NUMBER}, or accept cold caches for those stages. - Audit finished images with
diveordocker history --no-truncin CI; the check "no layer contains a.gitpath" is a five-line assertion that catches regressions.
3. Static .env secrets versus dynamic flag injection
Symptom. A scoring harness embedded its verification secret in the image as a static ENV FLAG=.... Two failure modes followed: the secret was recoverable from the image manifest by any process inside the sandbox (breaking the integrity of what was being measured), and because it was static, a leaked value stayed valid across every subsequent run.
Fix. Treat harness secrets as per-run capabilities, not configuration:
Static .env in image | Dynamic per-run injection | |
|---|---|---|
| Lifetime | Forever, until image rebuilt | One container start |
| Recoverable from layers | Yes (docker inspect, manifest) | No, never enters a layer |
| Cross-run replay | Valid in all runs | Useless after the run exits |
| Audit signal | None | Per-run id in logs ties usage to one execution |
FLAG="FLAG{$(uuidgen)}" # generated by the orchestrator, per run
docker run --rm --env FLAG --read-only ... patch-verify-sandbox
unset FLAG # orchestrator forgets it immediately after start
Anything that must persist (scores, verdicts) is written by the harness to a mounted output directory, data flows out, capabilities never flow in.
4. --cap-drop=ALL and the non-root worker
Symptom. A workload escaped its workdir (see pitfall 1) and, from inside the container, attached to neighboring processes with ptrace to read another test's memory. The container was "isolated" by namespace, but the worker still held CAP_SYS_PTRACE and ran as root.
Fix. One canonical runtime line, plus build-time ownership:
docker run --rm \
--cap-drop=ALL \ # no ptrace, no mknod, no net-admin, nothing
--security-opt no-new-privileges:true \
--pids-limit 64 --memory 1g --cpus 1 \
--user 65532:65532 \ # non-root uid/gid; chown at build time
--read-only --tmpfs /work:rw,size=64m,exec \
--network none \ # offline means offline
patch-verify-sandbox
no-new-privilegescloses the setuid-re-escalation path that cap-dropping alone leaves open.- Build-time
RUN chown -R 65532:65532 /app(orCOPY --chown) so the dropped-privilege worker can actually read its code. --pids-limitmatters as much as memory limits: fork bombs are an availability attack on shared runners.
5. EOL base-image repository rot
Symptom. A harness that had built cleanly for four months failed overnight: apt-get update returned 404s for every package mirror. The Debian release had hit end-of-life; the mirrors moved to archive.debian.org with no warning inside the build.
Failure shape. Reproducibility decays silently. Security harnesses are the worst place for this, because a rebuild six months later, exactly when you need to re-verify an old finding, is when the rot bites.
Fix. Pin by digest, not tag; if you must stay on an EOL release, pin its archive explicitly and accept the stale-package risk in writing:
# digest pin: the only reference that cannot silently change
FROM debian@sha256:4b0e3c2fb5b1f1e5c3a2d6...
# if pinned to an EOL release, freeze its world:
RUN printf 'deb [check-valid-until=no] https://archive.debian.org/debian buster main\n' \
> /etc/apt/sources.list \
&& apt-get -o Acquire::Check-Valid-Until=false update
- Store the digest in the repo (a committed
base-image.lock), so the rebuild you run next quarter is the rebuild you ran today. - Schedule a quarterly controlled rebuild-and-diff: rebuild from lock, run the harness's own invariant suite, and promote a new digest only when the diff is intentional.
The checklist that fell out
| Control | Catches | Cost |
|---|---|---|
.dockerignore with .git, .env | Pitfalls 2, 3 | Minutes |
| Digest-pinned base + lock file | Pitfall 5 | Minutes, quarterly |
| Per-run secret injection | Pitfall 3 | Small orchestrator change |
--cap-drop=ALL --user 65532 --read-only --network none | Pitfalls 1, 4 (blast radius) | One flag set |
| Realpath validation at extraction + tmpfs scratch | Pitfall 1 | ~40 lines |
Image audit (dive/docker history) in CI | Regressions of 2 and 3 | One CI step |
All of the above ships as the default profile of Silvauren/patch-verify-sandbox. If your harness runs other people's code, or your own, which during an incident is the same trust level, start from this list before writing a single test.