Interactive Playground
Experiment with the vulnerable code and security rule below. Edit the code to see how the rule detects different vulnerability patterns.
pathfinder scan --ruleset docker/DOCKER-SEC-006 --project .About This Rule
Understanding the vulnerability and how it is detected
This rule detects VOLUME instructions that mount the Docker socket into a container. Mounting the Docker socket (/var/run/docker.sock or /run/docker.sock) gives a container full control over the host's Docker daemon, which is equivalent to unrestricted root access on the host machine.
Security Implications
Potential attack scenarios if this vulnerability is exploited
Container Escape
Create privileged containers that mount the host filesystem: ```bash docker run -v /:/host --privileged alpine chroot /host /bin/sh ``` This gives the attacker a root shell on the host.
Privilege Escalation
Start containers with any user ID, including UID 0 (root), and mount any host directory as a volume.
Persistence
Deploy malicious containers that persist across reboots by modifying host systemd services or cron jobs.
Data Exfiltration
Access all volumes, images, and containers on the host, including those containing sensitive data from other applications.
Resource Hijacking
Deploy cryptocurrency miners or consume all host resources to cause denial of service.
Lateral Movement
Access other containers' filesystems and networks, potentially compromising the entire infrastructure. Real-world attack chain: ```bash # Attacker gains shell in container with Docker socket mounted # Step 1: List all containers docker ps -a # Step 2: Create privileged container mounting host root docker run -it -v /:/host --privileged alpine /bin/sh # Step 3: Chroot into host filesystem chroot /host /bin/bash # Step 4: Now has root access to host - install backdoor echo "* * * * * root /tmp/backdoor.sh" >> /etc/crontab ```
How to Fix
Recommended remediation steps
- 1Never mount the Docker socket into application containers
- 2Use the Docker API over TLS with client certificates if remote access is needed
- 3Consider rootless Docker or Podman to reduce socket exposure risk
References
External resources and documentation
Similar Rules
Explore related security rules for Docker
Sudo Usage in Dockerfile
Dockerfile uses sudo in RUN instructions. This is unnecessary during build (already root) and increases security risk if sudo remains in the final image. Use USER instruction for privilege changes instead.
Container Running as Root - Missing USER
Dockerfile does not specify USER instruction. Container will run as root by default, which increases the attack surface if the container is compromised.
Secret in Build Argument
Build argument name suggests it contains a secret. ARG values are visible in image history via 'docker history'.
Frequently Asked Questions
Common questions about Docker Socket Mounted as Volume
New feature
Get these findings posted directly on your GitHub pull requests
The Docker Socket Mounted as Volume rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.