From 36421909e7ebda78906a9e29aeec8ab133d73316 Mon Sep 17 00:00:00 2001 From: Michael Aguiar Date: Wed, 21 Oct 2026 07:58:36 -0700 Subject: [PATCH 1/2] Patch PHP for CVE-2026-109618/109619 and bump FrankenPHP to 1.13.1 PHP 8.5.12, 8.4.27, 8.3.36 and 8.2.35 fix two unauthenticated RCEs (CVSS 9.2) affecting every SAPI that serves web requests, FrankenPHP included. Neither php:*-zts-alpine nor dunglas/frankenphp ships them yet, so each frankenphp Dockerfile gains a php-patched stage that rebuilds PHP from the php.net tarball (sha256-pinned) with the upstream image's own configure flags and copies the result over the base. FrankenPHP links libphp.so dynamically and patch releases keep the same API numbers, so the swap needs no FrankenPHP rebuild. The patched tarball also replaces /usr/src/php.tar.xz so core extensions installed later (intl, gd, mysqli, ...) build from fixed source. The build fails if php doesn't report the patched version. 8.2 also needs php-src#18743 (as docker-library applies) for its JIT to assemble on Alpine 3.24. FROM pins move from 1.9 / 1.11.1 / 1.12.4 to 1.13.1 across the board, which also picks up FrankenPHP's own 2026-10-04 security fixes. Drop the php-patched stage once the FROM image ships the patched PHP. --- php/8.2/frankenphp/Dockerfile | 84 ++++++++++++++++++++++++++++++++++- php/8.3/frankenphp/Dockerfile | 75 ++++++++++++++++++++++++++++++- php/8.4/frankenphp/Dockerfile | 75 ++++++++++++++++++++++++++++++- php/8.5/frankenphp/Dockerfile | 75 ++++++++++++++++++++++++++++++- 4 files changed, 301 insertions(+), 8 deletions(-) diff --git a/php/8.2/frankenphp/Dockerfile b/php/8.2/frankenphp/Dockerfile index cf40e2c..c5bb601 100644 --- a/php/8.2/frankenphp/Dockerfile +++ b/php/8.2/frankenphp/Dockerfile @@ -1,9 +1,84 @@ -ARG FRANKENPHP_VERSION=1.9 +ARG FRANKENPHP_VERSION=1.13.1 ARG PHP_VERSION=8.2 +# PHP security release to rebuild over the upstream image's PHP, for when +# upstream (php:*-zts-alpine -> dunglas/frankenphp) lags a php.net release. +# Hash from https://www.php.net/releases/index.php?json&version=8.2. +# Remove the php-patched stage and its COPY once the FROM image ships this +# version or newer. +ARG PHP_PATCH_VERSION=8.2.35 +ARG PHP_PATCH_SHA256=5737b98601fe5ab1b8c5db0c82ed3158acb9283ed3081ffe2faffb9ac81455e6 + +# Rebuilds PHP from the patched tarball using the upstream image's own +# configure flags (read back from php-config) and the docker-library build +# recipe, then stages `make install` into /php-install. FrankenPHP links +# libphp.so dynamically and a patch release keeps the same API numbers, so +# swapping libphp.so, the binaries and the shared extensions is enough. +FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine AS php-patched +ARG PHP_PATCH_VERSION +ARG PHP_PATCH_SHA256 +RUN set -eux; \ + configure_opts="$(php-config --configure-options | sed 's/ PHP_UNAME=.*//')"; \ + apk add --no-cache --virtual .build-deps \ + $PHPIZE_DEPS \ + argon2-dev \ + coreutils \ + curl-dev \ + gnu-libiconv-dev \ + libsodium-dev \ + libxml2-dev \ + linux-headers \ + oniguruma-dev \ + openssl-dev \ + patch \ + patchutils \ + readline-dev \ + sqlite-dev; \ + # make sure musl's iconv doesn't get used (matches docker-library) + rm -vf /usr/include/iconv.h; \ + \ + mkdir -p /php-install/usr/src "/php-install$PHP_INI_DIR"; \ + curl -fsSL -o /php-install/usr/src/php.tar.xz "https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz"; \ + curl -fsSL -o /php-install/usr/src/php.tar.xz.asc "https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz.asc"; \ + echo "${PHP_PATCH_SHA256} */php-install/usr/src/php.tar.xz" | sha256sum -c -; \ + mkdir /usr/src/php; \ + tar -Jxf /php-install/usr/src/php.tar.xz -C /usr/src/php --strip-components=1; \ + cd /usr/src/php; \ + # 8.2's JIT fails to assemble on Alpine 3.22+ binutils without this + # (same patch docker-library applies to its 8.2 alpine images): + # https://github.com/php/php-src/issues/18743 + curl -fL 'https://github.com/php/php-src/commit/b3c8afe272a6919248986c703c2e1defc73ff707.patch?full_index=1' -o 18743.patch; \ + echo 'b334f73434c9732a4b27a42eb5d417e10df842e854c02a3e753b2479f8978bf5 *18743.patch' | sha256sum -c -; \ + filterdiff -x '*/NEWS' 18743.patch | patch -p1; \ + rm 18743.patch; \ + \ + export \ + CFLAGS="$PHP_CFLAGS" \ + CPPFLAGS="$PHP_CPPFLAGS" \ + LDFLAGS="$PHP_LDFLAGS" \ + PHP_BUILD_PROVIDER='https://github.com/docker-library/php'; \ + # word splitting of configure_opts is intended + ./configure $configure_opts PHP_UNAME='Linux - Docker'; \ + make -j "$(nproc)"; \ + find -type f -name '*.a' -delete; \ + make install INSTALL_ROOT=/php-install; \ + find /php-install/usr/local -type f -perm '/0111' \ + -exec sh -euxc 'strip --strip-all "$@" || :' -- '{}' +; \ + cp -v php.ini-* "/php-install$PHP_INI_DIR/"; \ + \ + test "$(/php-install/usr/local/bin/php -n -r 'echo PHP_VERSION;')" = "$PHP_PATCH_VERSION" + FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine LABEL maintainer="Michael Aguiar " +ARG PHP_PATCH_VERSION +ARG PHP_PATCH_SHA256 +COPY --from=php-patched /php-install/ / +ENV PHP_VERSION=${PHP_PATCH_VERSION} \ + PHP_URL=https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz \ + PHP_ASC_URL=https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz.asc \ + PHP_SHA256=${PHP_PATCH_SHA256} + # Runtime UID. Keep this DIFFERENT from the UID that owns the bind-mounted # source on the host: if they match, PHP owns every file it serves and any # code-execution bug becomes persistent code modification. Downstream images @@ -39,7 +114,12 @@ ENV PHP_MEMORY_LIMIT=256M \ MSMTP_RELAY_SERVER_TLS=off \ MSMTP_RELAY_SERVER_FROM=no-reply@localhost -RUN sed -i 's/{$SERVER_NAME:localhost}/:{$PORT:80}/' /etc/caddy/Caddyfile && \ + # Fail the build rather than ship the vulnerable PHP if the patched + # libphp/binaries didn't land over the upstream ones. +RUN test "$(php -r 'echo PHP_VERSION;')" = "$PHP_VERSION" || \ + (echo "ERROR: php reports $(php -r 'echo PHP_VERSION;'), expected $PHP_VERSION" >&2 && exit 1) && \ + \ + sed -i 's/{$SERVER_NAME:localhost}/:{$PORT:80}/' /etc/caddy/Caddyfile && \ sed -i '/CADDY_GLOBAL_OPTIONS/a http_port {$PORT:80}' /etc/caddy/Caddyfile && \ sed -i '/http_port/a servers :{$PORT:80} {\nprotocols h1 h2 h2c h3\n}' /etc/caddy/Caddyfile && \ \ diff --git a/php/8.3/frankenphp/Dockerfile b/php/8.3/frankenphp/Dockerfile index c763fe2..e6f901d 100644 --- a/php/8.3/frankenphp/Dockerfile +++ b/php/8.3/frankenphp/Dockerfile @@ -1,9 +1,75 @@ -ARG FRANKENPHP_VERSION=1.11.1 +ARG FRANKENPHP_VERSION=1.13.1 ARG PHP_VERSION=8.3 +# PHP security release to rebuild over the upstream image's PHP, for when +# upstream (php:*-zts-alpine -> dunglas/frankenphp) lags a php.net release. +# Hash from https://www.php.net/releases/index.php?json&version=8.3. +# Remove the php-patched stage and its COPY once the FROM image ships this +# version or newer. +ARG PHP_PATCH_VERSION=8.3.36 +ARG PHP_PATCH_SHA256=dd54693aa334c5c4d72e9aee96b082c2473750a18a6c1d105789c93a3b1692fd + +# Rebuilds PHP from the patched tarball using the upstream image's own +# configure flags (read back from php-config) and the docker-library build +# recipe, then stages `make install` into /php-install. FrankenPHP links +# libphp.so dynamically and a patch release keeps the same API numbers, so +# swapping libphp.so, the binaries and the shared extensions is enough. +FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine AS php-patched +ARG PHP_PATCH_VERSION +ARG PHP_PATCH_SHA256 +RUN set -eux; \ + configure_opts="$(php-config --configure-options | sed 's/ PHP_UNAME=.*//')"; \ + apk add --no-cache --virtual .build-deps \ + $PHPIZE_DEPS \ + argon2-dev \ + coreutils \ + curl-dev \ + gnu-libiconv-dev \ + libsodium-dev \ + libxml2-dev \ + linux-headers \ + oniguruma-dev \ + openssl-dev \ + readline-dev \ + sqlite-dev; \ + # make sure musl's iconv doesn't get used (matches docker-library) + rm -vf /usr/include/iconv.h; \ + \ + mkdir -p /php-install/usr/src "/php-install$PHP_INI_DIR"; \ + curl -fsSL -o /php-install/usr/src/php.tar.xz "https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz"; \ + curl -fsSL -o /php-install/usr/src/php.tar.xz.asc "https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz.asc"; \ + echo "${PHP_PATCH_SHA256} */php-install/usr/src/php.tar.xz" | sha256sum -c -; \ + mkdir /usr/src/php; \ + tar -Jxf /php-install/usr/src/php.tar.xz -C /usr/src/php --strip-components=1; \ + cd /usr/src/php; \ + \ + export \ + CFLAGS="$PHP_CFLAGS" \ + CPPFLAGS="$PHP_CPPFLAGS" \ + LDFLAGS="$PHP_LDFLAGS" \ + PHP_BUILD_PROVIDER='https://github.com/docker-library/php'; \ + # word splitting of configure_opts is intended + ./configure $configure_opts PHP_UNAME='Linux - Docker'; \ + make -j "$(nproc)"; \ + find -type f -name '*.a' -delete; \ + make install INSTALL_ROOT=/php-install; \ + find /php-install/usr/local -type f -perm '/0111' \ + -exec sh -euxc 'strip --strip-all "$@" || :' -- '{}' +; \ + cp -v php.ini-* "/php-install$PHP_INI_DIR/"; \ + \ + test "$(/php-install/usr/local/bin/php -n -r 'echo PHP_VERSION;')" = "$PHP_PATCH_VERSION" + FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine LABEL maintainer="Michael Aguiar " +ARG PHP_PATCH_VERSION +ARG PHP_PATCH_SHA256 +COPY --from=php-patched /php-install/ / +ENV PHP_VERSION=${PHP_PATCH_VERSION} \ + PHP_URL=https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz \ + PHP_ASC_URL=https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz.asc \ + PHP_SHA256=${PHP_PATCH_SHA256} + # Runtime UID. Keep this DIFFERENT from the UID that owns the bind-mounted # source on the host: if they match, PHP owns every file it serves and any # code-execution bug becomes persistent code modification. Downstream images @@ -39,7 +105,12 @@ ENV PHP_MEMORY_LIMIT=256M \ MSMTP_RELAY_SERVER_TLS=off \ MSMTP_RELAY_SERVER_FROM=no-reply@localhost -RUN sed -i 's/{$SERVER_NAME:localhost}/:{$PORT:80}/' /etc/caddy/Caddyfile && \ + # Fail the build rather than ship the vulnerable PHP if the patched + # libphp/binaries didn't land over the upstream ones. +RUN test "$(php -r 'echo PHP_VERSION;')" = "$PHP_VERSION" || \ + (echo "ERROR: php reports $(php -r 'echo PHP_VERSION;'), expected $PHP_VERSION" >&2 && exit 1) && \ + \ + sed -i 's/{$SERVER_NAME:localhost}/:{$PORT:80}/' /etc/caddy/Caddyfile && \ sed -i '/CADDY_GLOBAL_OPTIONS/a http_port {$PORT:80}' /etc/caddy/Caddyfile && \ sed -i '/http_port/a servers :{$PORT:80} {\nprotocols h1 h2 h2c h3\n}' /etc/caddy/Caddyfile && \ \ diff --git a/php/8.4/frankenphp/Dockerfile b/php/8.4/frankenphp/Dockerfile index 449f774..7057c20 100644 --- a/php/8.4/frankenphp/Dockerfile +++ b/php/8.4/frankenphp/Dockerfile @@ -1,9 +1,75 @@ -ARG FRANKENPHP_VERSION=1.12.4 +ARG FRANKENPHP_VERSION=1.13.1 ARG PHP_VERSION=8.4 +# PHP security release to rebuild over the upstream image's PHP, for when +# upstream (php:*-zts-alpine -> dunglas/frankenphp) lags a php.net release. +# Hash from https://www.php.net/releases/index.php?json&version=8.4. +# Remove the php-patched stage and its COPY once the FROM image ships this +# version or newer. +ARG PHP_PATCH_VERSION=8.4.27 +ARG PHP_PATCH_SHA256=dcf93923b0e38e0d5252b25b796520b5a47761a08b3488b6d0b5d1115764d3f0 + +# Rebuilds PHP from the patched tarball using the upstream image's own +# configure flags (read back from php-config) and the docker-library build +# recipe, then stages `make install` into /php-install. FrankenPHP links +# libphp.so dynamically and a patch release keeps the same API numbers, so +# swapping libphp.so, the binaries and the shared extensions is enough. +FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine AS php-patched +ARG PHP_PATCH_VERSION +ARG PHP_PATCH_SHA256 +RUN set -eux; \ + configure_opts="$(php-config --configure-options | sed 's/ PHP_UNAME=.*//')"; \ + apk add --no-cache --virtual .build-deps \ + $PHPIZE_DEPS \ + argon2-dev \ + coreutils \ + curl-dev \ + gnu-libiconv-dev \ + libsodium-dev \ + libxml2-dev \ + linux-headers \ + oniguruma-dev \ + openssl-dev \ + readline-dev \ + sqlite-dev; \ + # make sure musl's iconv doesn't get used (matches docker-library) + rm -vf /usr/include/iconv.h; \ + \ + mkdir -p /php-install/usr/src "/php-install$PHP_INI_DIR"; \ + curl -fsSL -o /php-install/usr/src/php.tar.xz "https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz"; \ + curl -fsSL -o /php-install/usr/src/php.tar.xz.asc "https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz.asc"; \ + echo "${PHP_PATCH_SHA256} */php-install/usr/src/php.tar.xz" | sha256sum -c -; \ + mkdir /usr/src/php; \ + tar -Jxf /php-install/usr/src/php.tar.xz -C /usr/src/php --strip-components=1; \ + cd /usr/src/php; \ + \ + export \ + CFLAGS="$PHP_CFLAGS" \ + CPPFLAGS="$PHP_CPPFLAGS" \ + LDFLAGS="$PHP_LDFLAGS" \ + PHP_BUILD_PROVIDER='https://github.com/docker-library/php'; \ + # word splitting of configure_opts is intended + ./configure $configure_opts PHP_UNAME='Linux - Docker'; \ + make -j "$(nproc)"; \ + find -type f -name '*.a' -delete; \ + make install INSTALL_ROOT=/php-install; \ + find /php-install/usr/local -type f -perm '/0111' \ + -exec sh -euxc 'strip --strip-all "$@" || :' -- '{}' +; \ + cp -v php.ini-* "/php-install$PHP_INI_DIR/"; \ + \ + test "$(/php-install/usr/local/bin/php -n -r 'echo PHP_VERSION;')" = "$PHP_PATCH_VERSION" + FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine LABEL maintainer="Michael Aguiar " +ARG PHP_PATCH_VERSION +ARG PHP_PATCH_SHA256 +COPY --from=php-patched /php-install/ / +ENV PHP_VERSION=${PHP_PATCH_VERSION} \ + PHP_URL=https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz \ + PHP_ASC_URL=https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz.asc \ + PHP_SHA256=${PHP_PATCH_SHA256} + # Runtime UID. Keep this DIFFERENT from the UID that owns the bind-mounted # source on the host: if they match, PHP owns every file it serves and any # code-execution bug becomes persistent code modification. Downstream images @@ -39,7 +105,12 @@ ENV PHP_MEMORY_LIMIT=256M \ MSMTP_RELAY_SERVER_TLS=off \ MSMTP_RELAY_SERVER_FROM=no-reply@localhost -RUN sed -i 's/{$SERVER_NAME:localhost}/:{$PORT:80}/' /etc/caddy/Caddyfile && \ + # Fail the build rather than ship the vulnerable PHP if the patched + # libphp/binaries didn't land over the upstream ones. +RUN test "$(php -r 'echo PHP_VERSION;')" = "$PHP_VERSION" || \ + (echo "ERROR: php reports $(php -r 'echo PHP_VERSION;'), expected $PHP_VERSION" >&2 && exit 1) && \ + \ + sed -i 's/{$SERVER_NAME:localhost}/:{$PORT:80}/' /etc/caddy/Caddyfile && \ sed -i '/CADDY_GLOBAL_OPTIONS/a http_port {$PORT:80}' /etc/caddy/Caddyfile && \ sed -i '/http_port/a servers :{$PORT:80} {\nprotocols h1 h2 h2c h3\n}' /etc/caddy/Caddyfile && \ \ diff --git a/php/8.5/frankenphp/Dockerfile b/php/8.5/frankenphp/Dockerfile index 4f38cfa..8ae32be 100644 --- a/php/8.5/frankenphp/Dockerfile +++ b/php/8.5/frankenphp/Dockerfile @@ -1,9 +1,75 @@ -ARG FRANKENPHP_VERSION=1.11.1 +ARG FRANKENPHP_VERSION=1.13.1 ARG PHP_VERSION=8.5 +# PHP security release to rebuild over the upstream image's PHP, for when +# upstream (php:*-zts-alpine -> dunglas/frankenphp) lags a php.net release. +# Hash from https://www.php.net/releases/index.php?json&version=8.5. +# Remove the php-patched stage and its COPY once the FROM image ships this +# version or newer. +ARG PHP_PATCH_VERSION=8.5.12 +ARG PHP_PATCH_SHA256=08bc2eba2a588654ade1357174aa646b761556c862dda0678345ee29ed481209 + +# Rebuilds PHP from the patched tarball using the upstream image's own +# configure flags (read back from php-config) and the docker-library build +# recipe, then stages `make install` into /php-install. FrankenPHP links +# libphp.so dynamically and a patch release keeps the same API numbers, so +# swapping libphp.so, the binaries and the shared extensions is enough. +FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine AS php-patched +ARG PHP_PATCH_VERSION +ARG PHP_PATCH_SHA256 +RUN set -eux; \ + configure_opts="$(php-config --configure-options | sed 's/ PHP_UNAME=.*//')"; \ + apk add --no-cache --virtual .build-deps \ + $PHPIZE_DEPS \ + argon2-dev \ + coreutils \ + curl-dev \ + gnu-libiconv-dev \ + libsodium-dev \ + libxml2-dev \ + linux-headers \ + oniguruma-dev \ + openssl-dev \ + readline-dev \ + sqlite-dev; \ + # make sure musl's iconv doesn't get used (matches docker-library) + rm -vf /usr/include/iconv.h; \ + \ + mkdir -p /php-install/usr/src "/php-install$PHP_INI_DIR"; \ + curl -fsSL -o /php-install/usr/src/php.tar.xz "https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz"; \ + curl -fsSL -o /php-install/usr/src/php.tar.xz.asc "https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz.asc"; \ + echo "${PHP_PATCH_SHA256} */php-install/usr/src/php.tar.xz" | sha256sum -c -; \ + mkdir /usr/src/php; \ + tar -Jxf /php-install/usr/src/php.tar.xz -C /usr/src/php --strip-components=1; \ + cd /usr/src/php; \ + \ + export \ + CFLAGS="$PHP_CFLAGS" \ + CPPFLAGS="$PHP_CPPFLAGS" \ + LDFLAGS="$PHP_LDFLAGS" \ + PHP_BUILD_PROVIDER='https://github.com/docker-library/php'; \ + # word splitting of configure_opts is intended + ./configure $configure_opts PHP_UNAME='Linux - Docker'; \ + make -j "$(nproc)"; \ + find -type f -name '*.a' -delete; \ + make install INSTALL_ROOT=/php-install; \ + find /php-install/usr/local -type f -perm '/0111' \ + -exec sh -euxc 'strip --strip-all "$@" || :' -- '{}' +; \ + cp -v php.ini-* "/php-install$PHP_INI_DIR/"; \ + \ + test "$(/php-install/usr/local/bin/php -n -r 'echo PHP_VERSION;')" = "$PHP_PATCH_VERSION" + FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine LABEL maintainer="Michael Aguiar " +ARG PHP_PATCH_VERSION +ARG PHP_PATCH_SHA256 +COPY --from=php-patched /php-install/ / +ENV PHP_VERSION=${PHP_PATCH_VERSION} \ + PHP_URL=https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz \ + PHP_ASC_URL=https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz.asc \ + PHP_SHA256=${PHP_PATCH_SHA256} + # Runtime UID. Keep this DIFFERENT from the UID that owns the bind-mounted # source on the host: if they match, PHP owns every file it serves and any # code-execution bug becomes persistent code modification. Downstream images @@ -39,7 +105,12 @@ ENV PHP_MEMORY_LIMIT=256M \ MSMTP_RELAY_SERVER_TLS=off \ MSMTP_RELAY_SERVER_FROM=no-reply@localhost -RUN sed -i 's/{$SERVER_NAME:localhost}/:{$PORT:80}/' /etc/caddy/Caddyfile && \ + # Fail the build rather than ship the vulnerable PHP if the patched + # libphp/binaries didn't land over the upstream ones. +RUN test "$(php -r 'echo PHP_VERSION;')" = "$PHP_VERSION" || \ + (echo "ERROR: php reports $(php -r 'echo PHP_VERSION;'), expected $PHP_VERSION" >&2 && exit 1) && \ + \ + sed -i 's/{$SERVER_NAME:localhost}/:{$PORT:80}/' /etc/caddy/Caddyfile && \ sed -i '/CADDY_GLOBAL_OPTIONS/a http_port {$PORT:80}' /etc/caddy/Caddyfile && \ sed -i '/http_port/a servers :{$PORT:80} {\nprotocols h1 h2 h2c h3\n}' /etc/caddy/Caddyfile && \ \ From c0a05a43a4afdc2d8213ee82ff274ce9196a24e3 Mon Sep 17 00:00:00 2001 From: Michael Aguiar Date: Wed, 21 Oct 2026 08:13:21 -0700 Subject: [PATCH 2/2] Harden the PHP patch stage per review - Fail the php-patched stage when the base already ships PHP at or above PHP_PATCH_VERSION; copying over it would silently downgrade. - Version guard now also checks `frankenphp php-cli`, which runs the libphp.so the server embeds; the `php` CLI is a separate binary and could report the patched version while web requests run the old lib. - Strip only the exact `PHP_UNAME=Linux - Docker` token from the reused configure options and fail on any other PHP_UNAME, instead of dropping everything after it. - Copy only /php-install/usr/: PEAR's installer also writes registry dotfiles (.channels, .registry, ...) at INSTALL_ROOT, which were landing in the image's /. - Removal note lists everything to delete once upstream catches up. --- php/8.2/frankenphp/Dockerfile | 29 ++++++++++++++++++++++------- php/8.3/frankenphp/Dockerfile | 29 ++++++++++++++++++++++------- php/8.4/frankenphp/Dockerfile | 29 ++++++++++++++++++++++------- php/8.5/frankenphp/Dockerfile | 29 ++++++++++++++++++++++------- 4 files changed, 88 insertions(+), 28 deletions(-) diff --git a/php/8.2/frankenphp/Dockerfile b/php/8.2/frankenphp/Dockerfile index c5bb601..0a6ef4f 100644 --- a/php/8.2/frankenphp/Dockerfile +++ b/php/8.2/frankenphp/Dockerfile @@ -3,8 +3,9 @@ ARG PHP_VERSION=8.2 # PHP security release to rebuild over the upstream image's PHP, for when # upstream (php:*-zts-alpine -> dunglas/frankenphp) lags a php.net release. # Hash from https://www.php.net/releases/index.php?json&version=8.2. -# Remove the php-patched stage and its COPY once the FROM image ships this -# version or newer. +# Once the FROM image ships this version or newer (the php-patched stage +# then fails the build), remove the php-patched stage, these PHP_PATCH_* +# ARGs, and the ARG/COPY/ENV block after LABEL in the final stage. ARG PHP_PATCH_VERSION=8.2.35 ARG PHP_PATCH_SHA256=5737b98601fe5ab1b8c5db0c82ed3158acb9283ed3081ffe2faffb9ac81455e6 @@ -17,7 +18,17 @@ FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine AS php-pa ARG PHP_PATCH_VERSION ARG PHP_PATCH_SHA256 RUN set -eux; \ - configure_opts="$(php-config --configure-options | sed 's/ PHP_UNAME=.*//')"; \ + # Copying this build over a base that already has the same or a newer + # PHP would silently downgrade it. + php -r 'exit(version_compare(PHP_VERSION, getenv("PHP_PATCH_VERSION"), "<") ? 0 : 1);' || \ + { echo "ERROR: base already ships PHP $(php -r 'echo PHP_VERSION;'); remove the php-patched stage" >&2; exit 1; }; \ + \ + # 8.4+ record PHP_UNAME='Linux - Docker' unquoted; drop it so the word + # split at ./configure doesn't break it apart (it's re-added there). + configure_opts="$(php-config --configure-options | sed 's/ PHP_UNAME=Linux - Docker//')"; \ + case "$configure_opts" in *PHP_UNAME=*) \ + echo "ERROR: unexpected PHP_UNAME in configure options: $configure_opts" >&2; exit 1;; \ + esac; \ apk add --no-cache --virtual .build-deps \ $PHPIZE_DEPS \ argon2-dev \ @@ -73,7 +84,8 @@ LABEL maintainer="Michael Aguiar " ARG PHP_PATCH_VERSION ARG PHP_PATCH_SHA256 -COPY --from=php-patched /php-install/ / +# Only usr/: PEAR's installer also drops registry dotfiles at INSTALL_ROOT. +COPY --from=php-patched /php-install/usr/ /usr/ ENV PHP_VERSION=${PHP_PATCH_VERSION} \ PHP_URL=https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz \ PHP_ASC_URL=https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz.asc \ @@ -115,9 +127,12 @@ ENV PHP_MEMORY_LIMIT=256M \ MSMTP_RELAY_SERVER_FROM=no-reply@localhost # Fail the build rather than ship the vulnerable PHP if the patched - # libphp/binaries didn't land over the upstream ones. -RUN test "$(php -r 'echo PHP_VERSION;')" = "$PHP_VERSION" || \ - (echo "ERROR: php reports $(php -r 'echo PHP_VERSION;'), expected $PHP_VERSION" >&2 && exit 1) && \ + # libphp/binaries didn't land over the upstream ones. `frankenphp + # php-cli` runs the libphp.so the server embeds; `php` is its own binary. +RUN for bin in "frankenphp php-cli" php; do \ + v="$($bin -r 'echo PHP_VERSION;')"; \ + test "$v" = "$PHP_VERSION" || { echo "ERROR: $bin reports $v, expected $PHP_VERSION" >&2; exit 1; }; \ + done && \ \ sed -i 's/{$SERVER_NAME:localhost}/:{$PORT:80}/' /etc/caddy/Caddyfile && \ sed -i '/CADDY_GLOBAL_OPTIONS/a http_port {$PORT:80}' /etc/caddy/Caddyfile && \ diff --git a/php/8.3/frankenphp/Dockerfile b/php/8.3/frankenphp/Dockerfile index e6f901d..77d10f6 100644 --- a/php/8.3/frankenphp/Dockerfile +++ b/php/8.3/frankenphp/Dockerfile @@ -3,8 +3,9 @@ ARG PHP_VERSION=8.3 # PHP security release to rebuild over the upstream image's PHP, for when # upstream (php:*-zts-alpine -> dunglas/frankenphp) lags a php.net release. # Hash from https://www.php.net/releases/index.php?json&version=8.3. -# Remove the php-patched stage and its COPY once the FROM image ships this -# version or newer. +# Once the FROM image ships this version or newer (the php-patched stage +# then fails the build), remove the php-patched stage, these PHP_PATCH_* +# ARGs, and the ARG/COPY/ENV block after LABEL in the final stage. ARG PHP_PATCH_VERSION=8.3.36 ARG PHP_PATCH_SHA256=dd54693aa334c5c4d72e9aee96b082c2473750a18a6c1d105789c93a3b1692fd @@ -17,7 +18,17 @@ FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine AS php-pa ARG PHP_PATCH_VERSION ARG PHP_PATCH_SHA256 RUN set -eux; \ - configure_opts="$(php-config --configure-options | sed 's/ PHP_UNAME=.*//')"; \ + # Copying this build over a base that already has the same or a newer + # PHP would silently downgrade it. + php -r 'exit(version_compare(PHP_VERSION, getenv("PHP_PATCH_VERSION"), "<") ? 0 : 1);' || \ + { echo "ERROR: base already ships PHP $(php -r 'echo PHP_VERSION;'); remove the php-patched stage" >&2; exit 1; }; \ + \ + # 8.4+ record PHP_UNAME='Linux - Docker' unquoted; drop it so the word + # split at ./configure doesn't break it apart (it's re-added there). + configure_opts="$(php-config --configure-options | sed 's/ PHP_UNAME=Linux - Docker//')"; \ + case "$configure_opts" in *PHP_UNAME=*) \ + echo "ERROR: unexpected PHP_UNAME in configure options: $configure_opts" >&2; exit 1;; \ + esac; \ apk add --no-cache --virtual .build-deps \ $PHPIZE_DEPS \ argon2-dev \ @@ -64,7 +75,8 @@ LABEL maintainer="Michael Aguiar " ARG PHP_PATCH_VERSION ARG PHP_PATCH_SHA256 -COPY --from=php-patched /php-install/ / +# Only usr/: PEAR's installer also drops registry dotfiles at INSTALL_ROOT. +COPY --from=php-patched /php-install/usr/ /usr/ ENV PHP_VERSION=${PHP_PATCH_VERSION} \ PHP_URL=https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz \ PHP_ASC_URL=https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz.asc \ @@ -106,9 +118,12 @@ ENV PHP_MEMORY_LIMIT=256M \ MSMTP_RELAY_SERVER_FROM=no-reply@localhost # Fail the build rather than ship the vulnerable PHP if the patched - # libphp/binaries didn't land over the upstream ones. -RUN test "$(php -r 'echo PHP_VERSION;')" = "$PHP_VERSION" || \ - (echo "ERROR: php reports $(php -r 'echo PHP_VERSION;'), expected $PHP_VERSION" >&2 && exit 1) && \ + # libphp/binaries didn't land over the upstream ones. `frankenphp + # php-cli` runs the libphp.so the server embeds; `php` is its own binary. +RUN for bin in "frankenphp php-cli" php; do \ + v="$($bin -r 'echo PHP_VERSION;')"; \ + test "$v" = "$PHP_VERSION" || { echo "ERROR: $bin reports $v, expected $PHP_VERSION" >&2; exit 1; }; \ + done && \ \ sed -i 's/{$SERVER_NAME:localhost}/:{$PORT:80}/' /etc/caddy/Caddyfile && \ sed -i '/CADDY_GLOBAL_OPTIONS/a http_port {$PORT:80}' /etc/caddy/Caddyfile && \ diff --git a/php/8.4/frankenphp/Dockerfile b/php/8.4/frankenphp/Dockerfile index 7057c20..dc60407 100644 --- a/php/8.4/frankenphp/Dockerfile +++ b/php/8.4/frankenphp/Dockerfile @@ -3,8 +3,9 @@ ARG PHP_VERSION=8.4 # PHP security release to rebuild over the upstream image's PHP, for when # upstream (php:*-zts-alpine -> dunglas/frankenphp) lags a php.net release. # Hash from https://www.php.net/releases/index.php?json&version=8.4. -# Remove the php-patched stage and its COPY once the FROM image ships this -# version or newer. +# Once the FROM image ships this version or newer (the php-patched stage +# then fails the build), remove the php-patched stage, these PHP_PATCH_* +# ARGs, and the ARG/COPY/ENV block after LABEL in the final stage. ARG PHP_PATCH_VERSION=8.4.27 ARG PHP_PATCH_SHA256=dcf93923b0e38e0d5252b25b796520b5a47761a08b3488b6d0b5d1115764d3f0 @@ -17,7 +18,17 @@ FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine AS php-pa ARG PHP_PATCH_VERSION ARG PHP_PATCH_SHA256 RUN set -eux; \ - configure_opts="$(php-config --configure-options | sed 's/ PHP_UNAME=.*//')"; \ + # Copying this build over a base that already has the same or a newer + # PHP would silently downgrade it. + php -r 'exit(version_compare(PHP_VERSION, getenv("PHP_PATCH_VERSION"), "<") ? 0 : 1);' || \ + { echo "ERROR: base already ships PHP $(php -r 'echo PHP_VERSION;'); remove the php-patched stage" >&2; exit 1; }; \ + \ + # 8.4+ record PHP_UNAME='Linux - Docker' unquoted; drop it so the word + # split at ./configure doesn't break it apart (it's re-added there). + configure_opts="$(php-config --configure-options | sed 's/ PHP_UNAME=Linux - Docker//')"; \ + case "$configure_opts" in *PHP_UNAME=*) \ + echo "ERROR: unexpected PHP_UNAME in configure options: $configure_opts" >&2; exit 1;; \ + esac; \ apk add --no-cache --virtual .build-deps \ $PHPIZE_DEPS \ argon2-dev \ @@ -64,7 +75,8 @@ LABEL maintainer="Michael Aguiar " ARG PHP_PATCH_VERSION ARG PHP_PATCH_SHA256 -COPY --from=php-patched /php-install/ / +# Only usr/: PEAR's installer also drops registry dotfiles at INSTALL_ROOT. +COPY --from=php-patched /php-install/usr/ /usr/ ENV PHP_VERSION=${PHP_PATCH_VERSION} \ PHP_URL=https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz \ PHP_ASC_URL=https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz.asc \ @@ -106,9 +118,12 @@ ENV PHP_MEMORY_LIMIT=256M \ MSMTP_RELAY_SERVER_FROM=no-reply@localhost # Fail the build rather than ship the vulnerable PHP if the patched - # libphp/binaries didn't land over the upstream ones. -RUN test "$(php -r 'echo PHP_VERSION;')" = "$PHP_VERSION" || \ - (echo "ERROR: php reports $(php -r 'echo PHP_VERSION;'), expected $PHP_VERSION" >&2 && exit 1) && \ + # libphp/binaries didn't land over the upstream ones. `frankenphp + # php-cli` runs the libphp.so the server embeds; `php` is its own binary. +RUN for bin in "frankenphp php-cli" php; do \ + v="$($bin -r 'echo PHP_VERSION;')"; \ + test "$v" = "$PHP_VERSION" || { echo "ERROR: $bin reports $v, expected $PHP_VERSION" >&2; exit 1; }; \ + done && \ \ sed -i 's/{$SERVER_NAME:localhost}/:{$PORT:80}/' /etc/caddy/Caddyfile && \ sed -i '/CADDY_GLOBAL_OPTIONS/a http_port {$PORT:80}' /etc/caddy/Caddyfile && \ diff --git a/php/8.5/frankenphp/Dockerfile b/php/8.5/frankenphp/Dockerfile index 8ae32be..4dc80ac 100644 --- a/php/8.5/frankenphp/Dockerfile +++ b/php/8.5/frankenphp/Dockerfile @@ -3,8 +3,9 @@ ARG PHP_VERSION=8.5 # PHP security release to rebuild over the upstream image's PHP, for when # upstream (php:*-zts-alpine -> dunglas/frankenphp) lags a php.net release. # Hash from https://www.php.net/releases/index.php?json&version=8.5. -# Remove the php-patched stage and its COPY once the FROM image ships this -# version or newer. +# Once the FROM image ships this version or newer (the php-patched stage +# then fails the build), remove the php-patched stage, these PHP_PATCH_* +# ARGs, and the ARG/COPY/ENV block after LABEL in the final stage. ARG PHP_PATCH_VERSION=8.5.12 ARG PHP_PATCH_SHA256=08bc2eba2a588654ade1357174aa646b761556c862dda0678345ee29ed481209 @@ -17,7 +18,17 @@ FROM dunglas/frankenphp:${FRANKENPHP_VERSION}-php${PHP_VERSION}-alpine AS php-pa ARG PHP_PATCH_VERSION ARG PHP_PATCH_SHA256 RUN set -eux; \ - configure_opts="$(php-config --configure-options | sed 's/ PHP_UNAME=.*//')"; \ + # Copying this build over a base that already has the same or a newer + # PHP would silently downgrade it. + php -r 'exit(version_compare(PHP_VERSION, getenv("PHP_PATCH_VERSION"), "<") ? 0 : 1);' || \ + { echo "ERROR: base already ships PHP $(php -r 'echo PHP_VERSION;'); remove the php-patched stage" >&2; exit 1; }; \ + \ + # 8.4+ record PHP_UNAME='Linux - Docker' unquoted; drop it so the word + # split at ./configure doesn't break it apart (it's re-added there). + configure_opts="$(php-config --configure-options | sed 's/ PHP_UNAME=Linux - Docker//')"; \ + case "$configure_opts" in *PHP_UNAME=*) \ + echo "ERROR: unexpected PHP_UNAME in configure options: $configure_opts" >&2; exit 1;; \ + esac; \ apk add --no-cache --virtual .build-deps \ $PHPIZE_DEPS \ argon2-dev \ @@ -64,7 +75,8 @@ LABEL maintainer="Michael Aguiar " ARG PHP_PATCH_VERSION ARG PHP_PATCH_SHA256 -COPY --from=php-patched /php-install/ / +# Only usr/: PEAR's installer also drops registry dotfiles at INSTALL_ROOT. +COPY --from=php-patched /php-install/usr/ /usr/ ENV PHP_VERSION=${PHP_PATCH_VERSION} \ PHP_URL=https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz \ PHP_ASC_URL=https://www.php.net/distributions/php-${PHP_PATCH_VERSION}.tar.xz.asc \ @@ -106,9 +118,12 @@ ENV PHP_MEMORY_LIMIT=256M \ MSMTP_RELAY_SERVER_FROM=no-reply@localhost # Fail the build rather than ship the vulnerable PHP if the patched - # libphp/binaries didn't land over the upstream ones. -RUN test "$(php -r 'echo PHP_VERSION;')" = "$PHP_VERSION" || \ - (echo "ERROR: php reports $(php -r 'echo PHP_VERSION;'), expected $PHP_VERSION" >&2 && exit 1) && \ + # libphp/binaries didn't land over the upstream ones. `frankenphp + # php-cli` runs the libphp.so the server embeds; `php` is its own binary. +RUN for bin in "frankenphp php-cli" php; do \ + v="$($bin -r 'echo PHP_VERSION;')"; \ + test "$v" = "$PHP_VERSION" || { echo "ERROR: $bin reports $v, expected $PHP_VERSION" >&2; exit 1; }; \ + done && \ \ sed -i 's/{$SERVER_NAME:localhost}/:{$PORT:80}/' /etc/caddy/Caddyfile && \ sed -i '/CADDY_GLOBAL_OPTIONS/a http_port {$PORT:80}' /etc/caddy/Caddyfile && \