diff --git a/.gitea/workflows/build-push.yaml b/.gitea/workflows/build-push.yaml index d5fedd1..c850c8e 100644 --- a/.gitea/workflows/build-push.yaml +++ b/.gitea/workflows/build-push.yaml @@ -91,6 +91,7 @@ jobs: scripts/tests/index-platforms.test.sh \ scripts/tests/lsphp-abi-gate.test.sh \ scripts/tests/lsphp-src-upload-progress.test.sh \ + scripts/tests/whp-proxy-guard-module.test.sh \ .gitea/scripts/resolve-base-image.sh \ .gitea/scripts/plan-legs.sh @@ -960,6 +961,20 @@ jobs: PKG_CACHE=${{ steps.pkgcache.outputs.url }} outputs: type=image,name=repo.anhonesthost.net/cloud-hosting-platform/shared-httpd,push-by-digest=true,name-canonical=true,push=true + # Publish gate for mod_whp_proxy_guard: the live probe test against the + # amd64 image that was just pushed (pulled by digest). Fatal and before the + # arm64 build and the tag-assembly step, so a failed assertion (or a missing + # docker/image: WHP_PGTEST_REQUIRE=1 turns the local SKIP into a FAIL) + # publishes no tag. Only the untagged by-digest blob exists at that point. + - name: Probe test (mod_whp_proxy_guard, amd64 image by digest) + env: + AMD64_DIGEST: ${{ steps.amd64.outputs.digest }} + run: | + set -euo pipefail + ref="repo.anhonesthost.net/cloud-hosting-platform/shared-httpd@${AMD64_DIGEST}" + docker pull "$ref" + WHP_PGTEST_REQUIRE=1 ./scripts/tests/whp-proxy-guard-module.test.sh "$ref" + # arm64: best effort, built under QEMU on this same trusted x86 runner (no # secret ever leaves it). Same Dockerfile, same build-args (incl. the php.net # EXPECT_PHP_MIN gate, which runs `php -r` on the arm64 binary). Must never diff --git a/scripts/tests/whp-proxy-guard-module.test.sh b/scripts/tests/whp-proxy-guard-module.test.sh index 1de5e20..c6e264c 100755 --- a/scripts/tests/whp-proxy-guard-module.test.sh +++ b/scripts/tests/whp-proxy-guard-module.test.sh @@ -6,7 +6,8 @@ # Env: WHP_FPM_IMAGE a cac-fpm image for the FastCGI environment section # (default repo.anhonesthost.net/cloud-hosting-platform/cac-fpm:php83; # that section is SKIPPED, not failed, when it is absent) -# SKIPs (exit 0) without docker or without the image. +# SKIPs (exit 0) without docker or without the image; with WHP_PGTEST_REQUIRE=1 +# (the CI publish gate) those are failures instead. # # Tenant vhosts a.test / b.test / l.test on a private docker network, an HTTP # "target" (this image's httpd, counted in its access log) and, with @@ -18,7 +19,9 @@ ID="whp-pg-$$"; NET="$ID-net"; H="$ID-httpd"; TG="$ID-tgt"; FP="$ID-fpm" pass=0; fail=0 ok() { pass=$((pass + 1)); printf ' ok %s\n' "$*"; } bad() { fail=$((fail + 1)); printf ' FAIL %s\n' "$*"; } -skip() { printf 'SKIP whp-proxy-guard-module: %s\n' "$*"; exit 0; } +skip() { # WHP_PGTEST_REQUIRE=1 (CI publish gate): a missing prerequisite FAILS + if [ "${WHP_PGTEST_REQUIRE:-0}" = 1 ]; then printf 'FAIL whp-proxy-guard-module: %s (WHP_PGTEST_REQUIRE=1)\n' "$*"; exit 1; fi + printf 'SKIP whp-proxy-guard-module: %s\n' "$*"; exit 0; } command -v docker >/dev/null 2>&1 || skip "no docker" docker image inspect "$IMAGE" >/dev/null 2>&1 || skip "image $IMAGE not available" T="$(mktemp -d)" @@ -157,7 +160,10 @@ code "[P] http:// SSRF" a.test /t4/go 403 code "[P] ws:// SSRF" a.test /t5/go 403 code "[P] ajp:// SSRF" a.test /t6/go 403 code "[P] backend by IP address" a.test /t7/go 403 -code " SetHandler proxy:http://" a.test /t8/f.txt 403 +# 403 from the guard; on an image without mod_proxy_http (cac #59) mod_proxy +# cannot canonicalise http:// and the static file is served instead. Both are +# fine as long as the target sees nothing (checked right below). +r="$(get a.test /t8/f.txt)"; case "$r" in 403*|"200 F"*) ok " SetHandler proxy:http:// -> ${r:0:3} (refused or not proxied)" ;; *) bad " SetHandler proxy:http:// -> ${r:0:40}" ;; esac [ "$(hits)" = "$h0" ] && ok "the SSRF target saw no request" || bad "the SSRF target was reached" r="$(get a.test /t9/f.txt)"; case "$r" in 403*|"200 F"*) ok "SetHandler proxy:unix: -> ${r:0:3} (refused or not proxied)" ;; *) bad "proxy:unix: -> ${r:0:40}" ;; esac code "vhost without a list inherits the image default: [P] http://" b.test /t4/go 404 # no /t4 under /srv/b diff --git a/src/mod_whp_proxy_guard/mod_whp_proxy_guard.c b/src/mod_whp_proxy_guard/mod_whp_proxy_guard.c index 87a10a0..5304233 100644 --- a/src/mod_whp_proxy_guard/mod_whp_proxy_guard.c +++ b/src/mod_whp_proxy_guard/mod_whp_proxy_guard.c @@ -255,7 +255,11 @@ static const char *cmd_scrub(cmd_parms *cmd, void *d, const char *arg) &whp_proxy_guard_module); if (!c->scrub) c->scrub = apr_array_make(cmd->pool, 4, sizeof(const char *)); - if (strcasecmp(arg, "none")) + /* `None` empties the list set so far in this context (same as + * WHPProxyAllow None), so a later file can switch the image default off. */ + if (!strcasecmp(arg, "none")) + apr_array_clear(c->scrub); + else *(const char **)apr_array_push(c->scrub) = arg; return NULL; } @@ -266,7 +270,9 @@ static const char *cmd_deny_handler(cmd_parms *cmd, void *d, const char *arg) &whp_proxy_guard_module); if (!c->deny_handler) c->deny_handler = apr_array_make(cmd->pool, 8, sizeof(const char *)); - if (strcasecmp(arg, "none")) + if (!strcasecmp(arg, "none")) /* see cmd_scrub */ + apr_array_clear(c->deny_handler); + else *(const char **)apr_array_push(c->deny_handler) = arg; return NULL; }