feat(shared-httpd): mod_whp_proxy_guard - request-time proxy allow list
A tenant's NESTED <If> in .htaccess is merged after every section a vhost or the server-scope drop-in can use, so it overrides any config-only SCRIPT_FILENAME / DOCUMENT_ROOT / PHP_VALUE pin. Measured on httpd 2.4.63-13.el10_2.8: `<If "true"><If "true"> ProxyFCGISetEnvIf "true" SCRIPT_FILENAME "/home/<victim>/..." </If></If>` plus `RewriteRule ... fcgi://<victim>-01:9000/... [P]` ran the other tenant's script as its uid (also <If><If><If>, <Files><If><If> SetHandler "proxy:fcgi://", a nested <ElseIf>, a nested PATH_TRANSLATED, the victim's IP); [P] to http/ws/ajp reached any host (SSRF); a nested <If> `SetHandler balancer-manager` served the balancer manager. New loadable module (stock Alma httpd, built against httpd-devel like mod_whp_symlink in #60, separate source so the two can merge independently): - mod_proxy scheme_handler hook (APR_HOOK_REALLY_FIRST): after all config merging, mod_rewrite and balancer member selection, the connection target (UDS path or scheme://host:port) must be on the vhost's WHPProxyAllow list, else 403 before a byte is sent. Every proxy scheme is covered. - WHPHtaccessProxyFCGI Deny: ProxyFCGISetEnvIf / ProxyFCGIBackendType in .htaccess (any nesting) is a config error, so the vhost's own rules stay the last word in mod_proxy_fcgi's fix_cgivars. - WHPProxyScrubEnv: tenant-set PHP_VALUE / PHP_ADMIN_VALUE / PATH_TRANSLATED removed before the backend params are built. - WHPDenyHandler: 403 for balancer-manager, server-status, server-info, lua-script, cgi-script (+ their MIME aliases) whatever selected them. Image defaults (configs/whp-proxy-guard.conf): Deny, scrub, default allow list fcgi://*:9000 (every WHP-rendered PHP handler), deny list. WHP renders a per-vhost exact list inside <IfModule whp_proxy_guard_module>. scripts/tests/whp-proxy-guard-module.test.sh: 36 assertions, PASS on the built image, 24 FAIL on the current shared-httpd:latest. DRAFT - DO NOT MERGE (merging publishes the image). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
This commit is contained in:
1 parent
d4ec8b526c
commit
ba3fb70d3c
4 files changed
+654
No files matched your search
@@ -3,6 +3,22 @@
|
||||
# so the pkg-cache registry mirror can only serve content-addressed blobs.
|
||||
# Local builds use the tag. docs/pkg-cache.md "Base-image digest pinning".
|
||||
ARG BASE_IMAGE=almalinux/10-base
|
||||
|
||||
# Build stage for mod_whp_proxy_guard (src/mod_whp_proxy_guard/): compiled
|
||||
# against the distribution httpd-devel, so the runtime keeps the stock
|
||||
# AlmaLinux httpd RPMs and their security updates. Only the .so (and the httpd
|
||||
# version it was built against) reaches the image.
|
||||
FROM ${BASE_IMAGE} AS modbuild-proxyguard
|
||||
ARG PKG_CACHE=
|
||||
COPY ./scripts/pkg-cache-repos.sh /usr/local/sbin/pkg-cache-repos.sh
|
||||
COPY ./keys/pkg-cache/ /usr/local/share/pkg-cache/
|
||||
COPY ./src/mod_whp_proxy_guard/mod_whp_proxy_guard.c /src/mod_whp_proxy_guard.c
|
||||
RUN /usr/local/sbin/pkg-cache-repos.sh rpm && \
|
||||
dnf update -y && \
|
||||
dnf install -y httpd-devel gcc redhat-rpm-config && \
|
||||
/usr/local/sbin/pkg-cache-repos.sh restore && \
|
||||
cd /src && apxs -Wc,-Wall -Wc,-Werror -c mod_whp_proxy_guard.c && \
|
||||
rpm -q --qf '%{VERSION}-%{RELEASE}' httpd-devel > /src/built-against
|
||||
FROM ${BASE_IMAGE}
|
||||
|
||||
# OPTIONAL internal package cache, e.g. --build-arg PKG_CACHE=https://192.168.1.40
|
||||
@@ -44,6 +60,18 @@ RUN openssl req -newkey rsa:2048 -nodes \
|
||||
COPY ./configs/remote_ip.conf /etc/httpd/conf.d/
|
||||
COPY ./configs/default-index.conf /etc/httpd/conf.d/
|
||||
|
||||
# mod_whp_proxy_guard: request-time proxy allow list, .htaccess
|
||||
# ProxyFCGISetEnvIf refusal, FastCGI env scrub and handler deny list
|
||||
# (configs/whp-proxy-guard.conf). Loaded after mod_proxy (99-), which its
|
||||
# scheme_handler hook needs. The build fails if the runtime httpd differs from
|
||||
# the httpd-devel it was compiled against, or if the module does not load.
|
||||
COPY --from=modbuild-proxyguard /src/.libs/mod_whp_proxy_guard.so /usr/lib64/httpd/modules/mod_whp_proxy_guard.so
|
||||
COPY --from=modbuild-proxyguard /src/built-against /usr/lib64/httpd/modules/mod_whp_proxy_guard.built-against
|
||||
COPY ./configs/whp-proxy-guard.conf /etc/httpd/conf.d/whp-proxy-guard.conf
|
||||
RUN echo 'LoadModule whp_proxy_guard_module modules/mod_whp_proxy_guard.so' > /etc/httpd/conf.modules.d/99-whp-proxy-guard.conf && \
|
||||
test "$(rpm -q --qf '%{VERSION}-%{RELEASE}' httpd)" = "$(cat /usr/lib64/httpd/modules/mod_whp_proxy_guard.built-against)" && \
|
||||
httpd -t && httpd -M 2>/dev/null | grep -q ' whp_proxy_guard_module '
|
||||
|
||||
# Create vhosts directory (will be volume-mounted from host)
|
||||
RUN mkdir -p /etc/httpd/conf.d/vhosts
|
||||
|
||||
|
||||
Reference in new issue
Block a user