mod_whp_proxy_guard: fail-closed switches (WHPProxyRequireTLS, WHPProxyRequireVhostList)
Review of WHP #362: the per-site :80 vhost redirected only its PRIMARY name, so an alias host on :80 (reachable from the shared docker network; the edge uses :443 only) was served with the tenant .htaccess and none of the :443 FastCGI pins. Measured on the current image: plain, <If> and nested ProxyFCGISetEnvIf + [P] to another tenant's backend all ran its script there, and with only the inherited fcgi://*:9000 default a [P] still ran the other tenant's index.php. - WHPProxyRequireTLS On (image default): no proxying for a request that did not arrive over TLS (ap_ssl_conn_is_ssl). Closes :80 for vhosts rendered before WHP's unconditional redirect. - WHPProxyRequireVhostList On|Off (image default Off): a vhost without its OWN WHPProxyAllow may not proxy; an inherited list does not count. Off in the image because hosts carry pre-#362 renders; WHP turns it on once every vhost renders its own list. - `WHPProxyAllow None` now resets the list; clearer refusal log lines. - In-repo test: 40 assertions (plain-HTTP refusal, RequireVhostList with and without an own list). DRAFT - DO NOT MERGE. 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
ba3fb70d3c
commit
5f8597363e
3 files changed
+94
-9
No files matched your search
@@ -74,6 +74,15 @@
|
||||
* the handler is chosen after every section a server-scope pin can live
|
||||
* in. Compared case-insensitively.
|
||||
*
|
||||
* 5. Fail-closed switches (server config only)
|
||||
* WHPProxyRequireTLS On: a request that did not arrive over TLS may not
|
||||
* proxy at all. On the shared tier the edge reaches Apache on :443 only
|
||||
* and the per-site :80 vhosts only redirect, so a plain-HTTP proxy is
|
||||
* never legitimate (it was reachable from the shared docker network).
|
||||
* WHPProxyRequireVhostList On: a virtual host whose WHPProxyAllow was not
|
||||
* set inside its own <VirtualHost> (inherited lists do not count) may not
|
||||
* proxy at all. For once every vhost renders its own list.
|
||||
*
|
||||
* Nothing here changes a request whose virtual host has none of these
|
||||
* directives in effect.
|
||||
*/
|
||||
@@ -85,6 +94,7 @@
|
||||
#include "http_request.h"
|
||||
#include "apr_strings.h"
|
||||
#include "apr_uri.h"
|
||||
#include "http_ssl.h"
|
||||
#include "mod_proxy.h"
|
||||
|
||||
module AP_MODULE_DECLARE_DATA whp_proxy_guard_module;
|
||||
@@ -107,6 +117,9 @@ typedef struct {
|
||||
apr_array_header_t *scrub; /* const char *, NULL = not set here */
|
||||
apr_array_header_t *deny_handler;/* const char *, NULL = not set here */
|
||||
int htaccess_fcgi; /* MODE_UNSET / MODE_OFF (allow) / MODE_ON (deny) */
|
||||
int allow_own; /* the list was set in THIS <VirtualHost> */
|
||||
int require_vhost_list; /* MODE_UNSET / OFF / ON */
|
||||
int require_tls; /* MODE_UNSET / OFF / ON */
|
||||
} guard_srv;
|
||||
|
||||
static void *create_srv(apr_pool_t *p, server_rec *s)
|
||||
@@ -114,6 +127,8 @@ static void *create_srv(apr_pool_t *p, server_rec *s)
|
||||
guard_srv *c = apr_pcalloc(p, sizeof(*c));
|
||||
c->mode = MODE_UNSET;
|
||||
c->htaccess_fcgi = MODE_UNSET;
|
||||
c->require_vhost_list = MODE_UNSET;
|
||||
c->require_tls = MODE_UNSET;
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -124,6 +139,11 @@ static void *merge_srv(apr_pool_t *p, void *b_, void *a_)
|
||||
c->allow = a->allow ? a->allow : b->allow;
|
||||
c->scrub = a->scrub ? a->scrub : b->scrub;
|
||||
c->deny_handler = a->deny_handler ? a->deny_handler : b->deny_handler;
|
||||
c->allow_own = a->allow_own; /* never inherited */
|
||||
c->require_vhost_list = a->require_vhost_list != MODE_UNSET
|
||||
? a->require_vhost_list : b->require_vhost_list;
|
||||
c->require_tls = a->require_tls != MODE_UNSET ? a->require_tls
|
||||
: b->require_tls;
|
||||
c->htaccess_fcgi = a->htaccess_fcgi != MODE_UNSET ? a->htaccess_fcgi
|
||||
: b->htaccess_fcgi;
|
||||
return c;
|
||||
@@ -133,8 +153,10 @@ static int effective_mode(const guard_srv *c)
|
||||
{
|
||||
if (c->mode != MODE_UNSET)
|
||||
return c->mode;
|
||||
/* A list that is set (even `WHPProxyAllow None`, i.e. empty) enforces. */
|
||||
return c->allow ? MODE_ON : MODE_OFF;
|
||||
/* A list that is set (even `WHPProxyAllow None`, i.e. empty), or either
|
||||
* fail-closed switch, enforces. */
|
||||
return (c->allow || c->require_vhost_list == MODE_ON
|
||||
|| c->require_tls == MODE_ON) ? MODE_ON : MODE_OFF;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
@@ -164,8 +186,12 @@ static const char *cmd_allow(cmd_parms *cmd, void *d, const char *arg)
|
||||
|
||||
if (!c->allow)
|
||||
c->allow = apr_array_make(cmd->pool, 4, sizeof(allow_entry));
|
||||
if (!strcasecmp(arg, "none")) /* explicit empty list: deny every target */
|
||||
if (cmd->server->is_virtual)
|
||||
c->allow_own = 1;
|
||||
if (!strcasecmp(arg, "none")) { /* explicit empty list: deny every target */
|
||||
apr_array_clear(c->allow);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
e = apr_array_push(c->allow);
|
||||
memset(e, 0, sizeof(*e));
|
||||
@@ -245,6 +271,15 @@ static const char *cmd_deny_handler(cmd_parms *cmd, void *d, const char *arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *cmd_flag(cmd_parms *cmd, void *d, int on)
|
||||
{
|
||||
guard_srv *c = ap_get_module_config(cmd->server->module_config,
|
||||
&whp_proxy_guard_module);
|
||||
int *f = cmd->info == (void *)1 ? &c->require_vhost_list : &c->require_tls;
|
||||
*f = on ? MODE_ON : MODE_OFF;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *cmd_htaccess_fcgi(cmd_parms *cmd, void *d, const char *arg)
|
||||
{
|
||||
guard_srv *c = ap_get_module_config(cmd->server->module_config,
|
||||
@@ -331,6 +366,7 @@ static int guard_scheme_handler(request_rec *r, proxy_worker *worker,
|
||||
guard_srv *c = ap_get_module_config(r->server->module_config,
|
||||
&whp_proxy_guard_module);
|
||||
const char *desc = NULL;
|
||||
const char *why = "not in the allow list";
|
||||
int mode;
|
||||
|
||||
if (c->scrub) {
|
||||
@@ -343,14 +379,23 @@ static int guard_scheme_handler(request_rec *r, proxy_worker *worker,
|
||||
mode = effective_mode(c);
|
||||
if (mode == MODE_OFF)
|
||||
return DECLINED;
|
||||
if (target_allowed(r, c, worker, url, &desc))
|
||||
if (c->require_tls == MODE_ON && !ap_ssl_conn_is_ssl(r->connection)) {
|
||||
target_allowed(r, c, worker, url, &desc);
|
||||
why = "the request did not arrive over TLS (WHPProxyRequireTLS)";
|
||||
}
|
||||
else if (c->require_vhost_list == MODE_ON && !c->allow_own) {
|
||||
target_allowed(r, c, worker, url, &desc);
|
||||
why = "the virtual host has no WHPProxyAllow of its own "
|
||||
"(WHPProxyRequireVhostList)";
|
||||
}
|
||||
else if (target_allowed(r, c, worker, url, &desc))
|
||||
return DECLINED;
|
||||
|
||||
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
|
||||
"whp_proxy_guard: proxy target %s is not in the allow list "
|
||||
"of virtual host %s (uri %s)%s", desc,
|
||||
"whp_proxy_guard: proxy target %s, virtual host "
|
||||
"%s (uri %s): %s%s", desc,
|
||||
r->server->server_hostname ? r->server->server_hostname : "-",
|
||||
r->uri, mode == MODE_ON ? " (refused)" : " (log only)");
|
||||
r->uri, why, mode == MODE_ON ? " (refused)" : " (log only)");
|
||||
return mode == MODE_ON ? HTTP_FORBIDDEN : DECLINED;
|
||||
}
|
||||
|
||||
@@ -387,6 +432,11 @@ static const command_rec cmds[] = {
|
||||
"environment variables removed before any proxy scheme handler runs"),
|
||||
AP_INIT_ITERATE("WHPDenyHandler", cmd_deny_handler, NULL, RSRC_CONF,
|
||||
"handler names answered 403 in this virtual host"),
|
||||
AP_INIT_FLAG("WHPProxyRequireVhostList", cmd_flag, (void *)1, RSRC_CONF,
|
||||
"On: a virtual host without its OWN WHPProxyAllow may not proxy "
|
||||
"at all (an inherited list does not count)"),
|
||||
AP_INIT_FLAG("WHPProxyRequireTLS", cmd_flag, (void *)2, RSRC_CONF,
|
||||
"On: no proxying for requests that did not arrive over TLS"),
|
||||
AP_INIT_TAKE1("WHPHtaccessProxyFCGI", cmd_htaccess_fcgi, NULL, RSRC_CONF,
|
||||
"Allow | Deny: ProxyFCGISetEnvIf / ProxyFCGIBackendType in .htaccess"),
|
||||
/* Same names and override class as mod_proxy_fcgi; invoked first. */
|
||||
|
||||
Reference in new issue
Block a user