ADD fetches a remote URL without verifying it
ID |
add_from_remote_url |
Severity |
high |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Vendor |
Docker |
Resource |
Application Security |
Tags |
ASVS50:v13.1.1, CWE:494, reachable, supply-chain |
Description
A Dockerfile ADD whose source is an http:// or https:// URL downloads a file at build time and
writes it into the image, with nothing checking that what came back is what was expected. (Docker
auto-extracts only local tar archives; a remote source is stored as-is, which is why the example
below then has to run tar itself.)
The URL is usually a moving target — latest/agent.tar.gz — so the image content depends on whoever
controls that host on the day of the build, and on nobody noticing if it changes. That is
CWE-494, download of code without an integrity check, and it is why Docker’s own guidance is to
prefer COPY for local paths and to verify anything fetched.
ADD --checksum=sha256:… is not reported: the checksum is the verification, and it is the reason
the instruction gained the flag.
Examples
Reported:
ADD https://downloads.example.io/report-agent/latest/agent.tar.gz /tmp/agent.tar.gz
RUN tar xzf /tmp/agent.tar.gz -C /opt && rm /tmp/agent.tar.gz
Not reported:
ADD --checksum=sha256:9f2b3d2a1c0e4f5a6b7c8d9e0f1a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c \
https://downloads.example.io/tool/1.2.3/tool.tar.gz /tmp/tool.tar.gz
ADD ./app /opt/app
Mitigation / Fix
State what you expect to receive. With a recent BuildKit, --checksum does it in place:
ADD --checksum=sha256:9f2b3d2a1c0e4f5a6b7c8d9e0f1a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c \
https://downloads.example.io/tool/1.2.3/tool.tar.gz /tmp/tool.tar.gz
Otherwise fetch and verify in one RUN, so a mismatch fails the build:
RUN curl -fsSL -o /tmp/tool.tar.gz https://downloads.example.io/tool/1.2.3/tool.tar.gz \
&& echo "9f2b3d2a1c0e4f5a6b7c8d9e0f1a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c /tmp/tool.tar.gz" | sha256sum -c - \
&& tar xzf /tmp/tool.tar.gz -C /opt \
&& rm /tmp/tool.tar.gz
Pin the URL to a version rather than latest, so the checksum stays meaningful. Better still, where
the artifact is yours, vendor it into the build context and COPY it.