fix(docker): reject host mode on images that bind Caido to 0.0.0.0

A cached sandbox image built before the entrypoint honored
STRIX_CAIDO_LISTEN_ADDRESS still starts Caido on 0.0.0.0:48080 with
--allow-guests, so enabling STRIX_DOCKER_SANDBOX_NETWORK=host on it
would expose guest access on every host interface. The Dockerfile now
labels the image strix.sandbox.caido-loopback=true, and host mode
checks that label on the image before creating the container. An image
without it raises a ValueError instead of starting. The configuration
docs note the requirement.

The reserved host.docker.internal check in STRIX_DOCKER_EXTRA_HOSTS now
compares case-insensitively, since hostname lookup is case-insensitive
and a mixed-case key could otherwise add a second entry for the
reserved name. Tests cover the missing-label rejection and a mixed-case
reserved hostname.

Refs #1402
This commit is contained in:
Matt Van Horn 2026-10-20 18:46:50 -07:00
parent e17a49c0f0
commit 412c6f3a62
No known key found for this signature in database
4 changed files with 54 additions and 6 deletions

View file

@ -269,4 +269,5 @@ RUN chmod +x /usr/local/bin/docker-entrypoint.sh
USER pentester
WORKDIR /workspace
LABEL strix.sandbox.caido-loopback="true"
ENTRYPOINT ["docker-entrypoint.sh"]

View file

@ -194,6 +194,8 @@ export STRIX_DOCKER_EXTRA_HOSTS='{"app.htb":"10.10.11.42"}'
Host mode binds Caido to the fixed port `48080`, so only one host-mode scan can run on a daemon at a time. The default bridge network publishes that container port to a free localhost port for each scan.
Host mode requires image label `strix.sandbox.caido-loopback=true`. That label marks an entrypoint that honors `STRIX_CAIDO_LISTEN_ADDRESS` and binds Caido to loopback. A cached older image is rejected instead of listening on every host interface.
## Sandbox Configuration
<ParamField path="STRIX_SANDBOX_EXECUTION_TIMEOUT" default="120" type="integer">

View file

@ -67,6 +67,7 @@ _DAEMON_LOOPBACK = "127.0.0.1"
# Read by containers/docker-entrypoint.sh. Set only for host networking so the
# unauthenticated Caido listener stays on loopback instead of 0.0.0.0.
_CAIDO_LISTEN_ADDRESS_ENV = "STRIX_CAIDO_LISTEN_ADDRESS"
_CAIDO_LOOPBACK_LABEL = "strix.sandbox.caido-loopback"
def _sandbox_network() -> str | None:
@ -90,10 +91,29 @@ def _apply_host_network_listener(create_kwargs: dict[str, Any]) -> None:
create_kwargs["environment"] = environment
def _apply_sandbox_network(create_kwargs: dict[str, Any]) -> None:
def _require_host_network_image(docker_client: Any, image: str) -> None:
"""Reject host mode when a cached image may still bind Caido on 0.0.0.0."""
try:
attrs = docker_client.images.get(image).attrs
except docker_errors.ImageNotFound:
attrs = None
config = attrs.get("Config") if isinstance(attrs, dict) else None
labels = config.get("Labels") if isinstance(config, dict) else None
if isinstance(labels, dict) and labels.get(_CAIDO_LOOPBACK_LABEL) == "true":
return
raise ValueError(
f"{_SANDBOX_NETWORK_ENV}=host requires label {_CAIDO_LOOPBACK_LABEL}=true "
f"so {_CAIDO_LISTEN_ADDRESS_ENV} is honored. Cached older images bind "
"Caido to 0.0.0.0 with guest access."
)
def _apply_sandbox_network(create_kwargs: dict[str, Any], docker_client: Any, image: str) -> None:
network = _sandbox_network()
if not network:
return
if network == _HOST_NETWORK_NAME:
_require_host_network_image(docker_client, image)
create_kwargs["network"] = network
create_kwargs.pop("ports", None)
if network == _HOST_NETWORK_NAME:
@ -137,7 +157,7 @@ def _extra_hostname(name: object) -> str:
hostname = name.strip()
if not hostname:
raise ValueError(f"{_EXTRA_HOSTS_ENV} contains an empty hostname")
if hostname == _HOST_GATEWAY_HOSTNAME:
if hostname.lower() == _HOST_GATEWAY_HOSTNAME:
raise ValueError(
f"{_EXTRA_HOSTS_ENV} cannot replace the reserved {_HOST_GATEWAY_HOSTNAME} mapping"
)
@ -334,7 +354,7 @@ class StrixDockerSandboxClient(DockerSandboxClient):
cap_add.append(cap)
_apply_extra_hosts(create_kwargs)
_apply_sandbox_network(create_kwargs)
_apply_sandbox_network(create_kwargs, self.docker_client, image)
_apply_resource_limits(create_kwargs)
_apply_log_limits(create_kwargs)
_apply_run_labels(create_kwargs)

View file

@ -23,6 +23,7 @@ from strix.runtime.docker_client import StrixDockerSandboxClient, StrixDockerSan
_IMAGE = "strix-sandbox:test"
_CAIDO_PORT = 48080
_GATEWAY = {"host.docker.internal": "host-gateway"}
_CAIDO_LOOPBACK_LABEL = "strix.sandbox.caido-loopback"
def _clear_network_env(monkeypatch: pytest.MonkeyPatch) -> None:
@ -30,12 +31,18 @@ def _clear_network_env(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("STRIX_DOCKER_EXTRA_HOSTS", raising=False)
def _client() -> tuple[StrixDockerSandboxClient, MagicMock, MagicMock]:
def _client(
*, caido_loopback: bool = False
) -> tuple[StrixDockerSandboxClient, MagicMock, MagicMock]:
docker = MagicMock()
container = MagicMock()
container.id = "container-1"
container.short_id = "container-1"
docker.containers.create.return_value = container
if caido_loopback:
image = MagicMock()
image.attrs = {"Config": {"Labels": {_CAIDO_LOOPBACK_LABEL: "true"}}}
docker.images.get.return_value = image
return StrixDockerSandboxClient(docker), docker, container
@ -53,7 +60,7 @@ async def _create_session(
_clear_network_env(monkeypatch)
if network is not None:
monkeypatch.setenv("STRIX_DOCKER_SANDBOX_NETWORK", network)
client, docker, container = _client()
client, docker, container = _client(caido_loopback=network == "host")
session = await client.create(
options=DockerSandboxClientOptions(_IMAGE, (_CAIDO_PORT,)),
manifest=manifest,
@ -114,6 +121,19 @@ async def test_host_network_resolves_loopback_without_container_ip(
assert exc_info.value.context["detail"] == "container_reload_failed"
@pytest.mark.asyncio
async def test_host_network_rejects_image_without_caido_loopback_label(
monkeypatch: pytest.MonkeyPatch,
) -> None:
_clear_network_env(monkeypatch)
monkeypatch.setenv("STRIX_DOCKER_SANDBOX_NETWORK", "host")
client, docker, _container = _client()
docker.images.get.return_value.attrs = {"Config": {"Labels": None}}
with pytest.raises(ValueError, match="caido-loopback"):
await client._create_container(_IMAGE, exposed_ports=(_CAIDO_PORT,))
docker.containers.create.assert_not_called()
@pytest.mark.asyncio
async def test_named_network_resolves_ipv4_and_ipv6(monkeypatch: pytest.MonkeyPatch) -> None:
session, docker, container = await _create_session(monkeypatch, "lab")
@ -203,7 +223,7 @@ async def test_extra_hosts_merge_with_gateway(
if network is not None:
monkeypatch.setenv("STRIX_DOCKER_SANDBOX_NETWORK", network)
monkeypatch.setenv("STRIX_DOCKER_EXTRA_HOSTS", raw)
client, docker, _container = _client()
client, docker, _container = _client(caido_loopback=network == "host")
await client._create_container(_IMAGE, exposed_ports=(_CAIDO_PORT,))
@ -248,6 +268,11 @@ async def test_blank_extra_hosts_keep_gateway_mapping(
ValueError,
r"cannot replace the reserved host\.docker\.internal mapping",
),
(
'{"HOST.Docker.Internal": "10.0.0.1"}',
ValueError,
r"cannot replace the reserved host\.docker\.internal mapping",
),
],
)
@pytest.mark.asyncio