Description
A URL can serve different bytes on the next build. HTTPS protects the connection, while a trusted checksum or signature identifies the expected download.
Potential impact
An unexpected executable or configuration file can be built into the image.
Remediation
Obtain the expected digest or signature through a trusted channel. Use ADD --checksum for a supported HTTP(S) download, or verify the file after curl or wget. Stop the build on a mismatch.
Examples
Set JAVA_BUILD_IMAGE to a supported Linux Java image with tar. Replace the example URL and SHA-256 digest with the real values.
Before
ARG JAVA_BUILD_IMAGE
FROM ${JAVA_BUILD_IMAGE}
ADD https://example.com/app.tar.gz /opt/app/
After
ARG JAVA_BUILD_IMAGE
FROM ${JAVA_BUILD_IMAGE}
ADD --checksum=sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef \
https://example.com/app.tar.gz /tmp/app.tar.gz
RUN mkdir -p /opt/app \
&& tar -xzf /tmp/app.tar.gz -C /opt/app \
&& rm /tmp/app.tar.gz
The first ADD leaves the downloaded archive compressed. The revision verifies it before extracting it and removing the temporary file. The downloaded file is part of an earlier image layer.