security(shared-httpd): also remove status, info and every unused proxy/suexec/dbd/cache module

A tenant `RewriteRule ^ - [H=server-status|server-info]` binds the handler
after any config section could pin it, and `RewriteRule ... http://x [P]`
proxies to internal addresses (SSRF). Config cannot close those; removing
the modules does. WHP renders only SetHandler proxy:fcgi, <Proxy balancer://>
+ BalancerMember fcgi:// + ProxySet lbmethod=byrequests and
ProxyFCGISetEnvIf, so only proxy, proxy_fcgi, proxy_balancer,
lbmethod_byrequests and slotmem_shm stay.

Removed in addition to the earlier set: status, info, proxy_http, proxy_ajp,
proxy_ftp, proxy_connect, proxy_scgi, proxy_uwsgi, proxy_wstunnel,
proxy_fdpass, proxy_express, proxy_hcheck, lbmethod_bybusyness,
lbmethod_bytraffic, lbmethod_heartbeat (+ mod_heartbeat/heartmonitor .so),
suexec, dbd, authn_dbd, authz_dbd, cache, cache_disk, cache_socache,
socache_dbm, socache_memcache, socache_redis. socache_shmcb stays (SSL).

The gate derives its banned-module regex from one list. Tests: 26 gate
cases (banned status/info/proxy_*/cache back, leftover .so, required
lbmethod_byrequests/balancer missing) and a new live probe script
(scripts/tests/httpd-exec-surface-probes.test.sh) that renders the real WHP
template + drop-in and tries [H=lua-script|server-status|server-info],
nested <If> CGI and [P] http/ws/ajp/ftp/scgi/uwsgi.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
This commit is contained in:
claude committed 2026-11-22 22:46:19 -08:00
1 parent 0f8407c239
commit 990b3792bc
5 files changed
+195 -15

No files matched your search

+37 -11
View File
@@ -3,12 +3,16 @@
# One Apache serves every tenant's docroot there, and everything it executes runs
# as the shared `apache` user, which can read every tenant's world-readable files.
# Nothing in WHP uses these modules (fleet survey 2026-11-22: 0 of 45 sites use
# ExecCGI/Includes/Lua/SSI includes), so they are removed from the image and this
# gate fails the build if they ever come back.
# ExecCGI/Includes/Lua/SSI includes; no RewriteRule [P]/[H=] anywhere), so they are
# removed from the image and this gate fails the build if they ever come back.
#
# mod_lua cannot be neutralised from WHP's side: it ignores `Options`, and a tenant
# `RewriteRule ^ - [H=lua-script]` binds the handler in the fixup phase, after any
# config section could pin it. Only an image without the module closes that.
# Why modules and not config: a tenant `RewriteRule ^ - [H=<handler>]` binds a
# handler in the fixup phase, after any config section could pin it, and mod_lua
# ignores `Options`. So every module that ships a handler a tenant can name
# (lua-script, cgi-script, server-status, server-info) or a [P] scheme
# (http, ajp, ftp, connect, scgi, uwsgi, ws) must be absent from the image.
# What stays is what WHP renders: proxy + proxy_fcgi (+ proxy_balancer with
# lbmethod_byrequests and slotmem_shm for multi-FPM sites).
#
# httpd-exec-surface-gate.sh remove uninstall / disable the modules, drop the
# global INCLUDES filter, the cgi-bin
@@ -24,15 +28,38 @@
# (tests only).
set -euo pipefail
BAD_MODULES='cgid_module|cgi_module|lua_module|include_module|actions_module|dav_module|dav_fs_module|dav_lock_module|userdir_module'
# Banned modules (name without the _module suffix == mod_<name>.so), by reason:
# exec: cgid cgi include actions lua (code as the shared apache user)
# files: dav dav_fs dav_lock userdir
# status: status info (server-status / server-info reach
# every tenant's requests via [H=])
# proxy: proxy_http proxy_ajp proxy_ftp proxy_connect proxy_scgi proxy_uwsgi
# proxy_wstunnel proxy_fdpass proxy_express proxy_hcheck
# lbmethod_bybusyness lbmethod_bytraffic lbmethod_heartbeat
# heartbeat heartmonitor ([P] SSRF to internal addresses and
# the heartbeat family)
# unused: suexec dbd authn_dbd authz_dbd cache cache_disk cache_socache
# socache_dbm socache_memcache socache_redis
# (no WHP directive uses them; CacheEnable/CacheDisable and
# SuexecUserGroup already answer 500 from a tenant .htaccess.
# socache_shmcb stays: mod_ssl's SSLSessionCache)
CORE_SO='cgid cgi include actions dav dav_fs dav_lock userdir lua
status info
proxy_http proxy_ajp proxy_ftp proxy_connect proxy_scgi proxy_uwsgi proxy_wstunnel
proxy_fdpass proxy_express proxy_hcheck lbmethod_bybusyness lbmethod_bytraffic
lbmethod_heartbeat heartbeat heartmonitor
suexec dbd authn_dbd authz_dbd cache cache_disk cache_socache
socache_dbm socache_memcache socache_redis'
MOD_PKGS='mod_lua'
CORE_SO='cgid cgi include actions dav dav_fs dav_lock userdir lua'
# Alternation of module identifiers, built from CORE_SO (single source of truth).
BAD_MODULES=$(printf '%s' "$CORE_SO" | tr -s ' \n' '\n' | sed 's/$/_module/' | paste -sd'|')
HTTPD_CONF=${HTTPD_ROOT_CONF:-/etc/httpd/conf/httpd.conf}
CONFD=${HTTPD_CONFD:-/etc/httpd/conf.d}
MODDIR=${HTTPD_MODDIR:-/etc/httpd/conf.modules.d}
SODIR=${HTTPD_SO_DIR:-/usr/lib64/httpd/modules}
# Positive control: modules the WHP platform relies on. Derived from
# Positive control: modules the WHP platform relies on (none is in the banned
# list above: `remove` then `check` passing proves the two lists are disjoint). Derived from
# web-files/configs/shared-vhost-template.tpl + panel/internal/vhost/httpdtpl
# (rewrite, proxy_fcgi via SetHandler proxy:fcgi + ProxyFCGISetEnvIf, and for a
# site with more than one FPM backend <Proxy balancer://> + BalancerMember +
@@ -70,8 +97,7 @@ cmd_remove() {
rm -f "$SODIR/mod_${m}.so"
done
rm -f "$MODDIR/00-lua.conf" "$MODDIR/01-cgi.conf" "$MODDIR/00-dav.conf" "$CONFD/userdir.conf"
sed -i -E '/^[[:space:]]*LoadModule[[:space:]]+(actions|include|userdir|cgid|cgi|lua|dav|dav_fs|dav_lock)_module[[:space:]]/d' \
"$MODDIR"/*.conf
sed -i -E '/^[[:space:]]*LoadModule[[:space:]]+('"${BAD_MODULES}"')[[:space:]]/d' "$MODDIR"/*.conf
# Global SSI filter, cgi-bin ScriptAlias (+ its <Directory>), and the cgi-bin dir.
sed -i -E '/^[[:space:]]*AddOutputFilter[[:space:]]+INCLUDES[[:space:]]/d;
/^[[:space:]]*ScriptAlias[[:space:]]+\/cgi-bin\//d;
@@ -108,7 +134,7 @@ cmd_check() {
done
[ "$fail" -eq 0 ] || exit 1
httpd -t
echo "gate OK: no cgid/cgi/lua/include/actions/dav/userdir; no INCLUDES filter / ScriptAlias; all required modules loaded; httpd -t passes"
echo "gate OK: no cgid/cgi/lua/include/actions/dav/userdir/status/info/unused proxy_*/suexec/dbd/cache; no INCLUDES filter / ScriptAlias; all required modules loaded; httpd -t passes"
}
case "${1:-}" in