fix(security): block dangerous host paths in volume mounts and build contexts#49
Open
taranveer-tengurchittoo wants to merge 1 commit intockreiling:mainfrom
Conversation
…contexts Container runtime sockets (/var/run/docker.sock, containerd, crio), /proc, /sys, and /dev are now rejected as volume mount sources and build context paths. Symlinks are resolved before checking to prevent bypass via aliased paths. Without this, an LLM (or an attacker via prompt injection through container logs or image metadata) can mount the Docker socket into a container and achieve full host takeover. This is the standard Docker container escape technique. Includes 35 tests covering both dict and list volume formats, blocked path subpaths, symlink resolution, and safe path passthrough.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Volume mount sources and build context paths are now validated against a blocklist of dangerous host paths before being passed to the Docker SDK. This prevents container escape attacks via runtime socket mounts and sensitive host resource exposure.
Blocked paths: container runtime sockets (
/var/run/docker.sock,/run/docker.sock, containerd, crio),/proc,/sys,/dev.Attack vector: without this fix, an LLM tool call (or an attacker exploiting prompt injection via container logs, image metadata, or other MCP resource content) can request a volume mount of
/var/run/docker.sockinto a new container, then use the Docker API from inside that container to create a privileged container with full host access. This is the standard Docker socket escape technique, and MCP servers are particularly exposed because tool call arguments originate from model output that can be influenced by untrusted data.Changes
BLOCKED_MOUNT_SOURCESconstant with known dangerous pathsCreateContainerInput.volumesthat resolves symlinks and rejects blocked sources (covers both dict and list volume formats)BuildImageInput.pathto prevent sensitive directories from being sent as Docker build contextTest plan
python -m pytest tests/test_mount_validation.py -v)/tmp/data:/data:rw) still workNonevolumes (no mounts) still work/proc/1/root)