Skip to content

fix(security): block dangerous host paths in volume mounts and build contexts#49

Open
taranveer-tengurchittoo wants to merge 1 commit intockreiling:mainfrom
taranveer-tengurchittoo:fix/block-dangerous-volume-mounts
Open

fix(security): block dangerous host paths in volume mounts and build contexts#49
taranveer-tengurchittoo wants to merge 1 commit intockreiling:mainfrom
taranveer-tengurchittoo:fix/block-dangerous-volume-mounts

Conversation

@taranveer-tengurchittoo
Copy link
Copy Markdown

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.sock into 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

  • Added BLOCKED_MOUNT_SOURCES constant with known dangerous paths
  • Added Pydantic field validator on CreateContainerInput.volumes that resolves symlinks and rejects blocked sources (covers both dict and list volume formats)
  • Added Pydantic field validator on BuildImageInput.path to prevent sensitive directories from being sent as Docker build context
  • Added 35 tests covering blocked paths, subpath matching, symlink resolution, and safe path passthrough

Test plan

  • All 35 new tests pass (python -m pytest tests/test_mount_validation.py -v)
  • Safe volume mounts (e.g. /tmp/data:/data:rw) still work
  • None volumes (no mounts) still work
  • Dict and list volume formats both validated
  • Subpaths of blocked paths are also blocked (e.g. /proc/1/root)

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant