f36b77
diff --git a/include/http_protocol.h b/include/http_protocol.h
f36b77
index 9ccac89..20bd202 100644
f36b77
--- a/include/http_protocol.h
f36b77
+++ b/include/http_protocol.h
f36b77
@@ -96,6 +96,13 @@ AP_DECLARE(void) ap_get_mime_headers(request_rec *r);
f36b77
 AP_DECLARE(void) ap_get_mime_headers_core(request_rec *r,
f36b77
                                           apr_bucket_brigade *bb);
f36b77
 
f36b77
+/**
f36b77
+ * Run post_read_request hook and validate.
f36b77
+ * @param r The current request
f36b77
+ * @return OK or HTTP_...
f36b77
+ */
f36b77
+AP_DECLARE(int) ap_post_read_request(request_rec *r);
f36b77
+
f36b77
 /* Finish up stuff after a request */
f36b77
 
f36b77
 /**
f36b77
diff --git a/modules/http/http_request.c b/modules/http/http_request.c
f36b77
index c9ae5af..d59cfe2 100644
f36b77
--- a/modules/http/http_request.c
f36b77
+++ b/modules/http/http_request.c
f36b77
@@ -680,7 +680,7 @@ static request_rec *internal_internal_redirect(const char *new_uri,
f36b77
      * to do their thing on internal redirects as well.  Perhaps this is a
f36b77
      * misnamed function.
f36b77
      */
f36b77
-    if ((access_status = ap_run_post_read_request(new))) {
f36b77
+    if ((access_status = ap_post_read_request(new))) {
f36b77
         ap_die(access_status, new);
f36b77
         return NULL;
f36b77
     }
f36b77
diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c
f36b77
index ee4f1fb..ff9f81d 100644
f36b77
--- a/modules/proxy/mod_proxy.c
f36b77
+++ b/modules/proxy/mod_proxy.c
f36b77
@@ -777,11 +777,12 @@ static int proxy_detect(request_rec *r)
f36b77
 
f36b77
     if (conf->req && r->parsed_uri.scheme) {
f36b77
         /* but it might be something vhosted */
f36b77
-        if (!(r->parsed_uri.hostname
f36b77
-              && !ap_cstr_casecmp(r->parsed_uri.scheme, ap_http_scheme(r))
f36b77
-              && ap_matches_request_vhost(r, r->parsed_uri.hostname,
f36b77
-                                          (apr_port_t)(r->parsed_uri.port_str ? r->parsed_uri.port
f36b77
-                                                       : ap_default_port(r))))) {
f36b77
+        if (!r->parsed_uri.hostname
f36b77
+            || ap_cstr_casecmp(r->parsed_uri.scheme, ap_http_scheme(r)) != 0
f36b77
+            || !ap_matches_request_vhost(r, r->parsed_uri.hostname,
f36b77
+                                         (apr_port_t)(r->parsed_uri.port_str
f36b77
+                                                      ? r->parsed_uri.port
f36b77
+                                                      : ap_default_port(r)))) {
f36b77
             r->proxyreq = PROXYREQ_PROXY;
f36b77
             r->uri = r->unparsed_uri;
f36b77
             r->filename = apr_pstrcat(r->pool, "proxy:", r->uri, NULL);
f36b77
@@ -2021,6 +2022,7 @@ static const char *
f36b77
     struct proxy_alias *new;
f36b77
     char *f = cmd->path;
f36b77
     char *r = NULL;
f36b77
+    const char *real;
f36b77
     char *word;
f36b77
     apr_table_t *params = apr_table_make(cmd->pool, 5);
f36b77
     const apr_array_header_t *arr;
f36b77
@@ -2107,6 +2109,10 @@ static const char *
f36b77
     if (r == NULL) {
f36b77
         return "ProxyPass|ProxyPassMatch needs a path when not defined in a location";
f36b77
     }
f36b77
+    if (!(real = ap_proxy_de_socketfy(cmd->temp_pool, r))) {
f36b77
+        return "ProxyPass|ProxyPassMatch uses an invalid \"unix:\" URL";
f36b77
+    }
f36b77
+
f36b77
 
f36b77
     /* if per directory, save away the single alias */
f36b77
     if (cmd->path) {
f36b77
@@ -2123,7 +2129,7 @@ static const char *
f36b77
     }
f36b77
 
f36b77
     new->fake = apr_pstrdup(cmd->pool, f);
f36b77
-    new->real = apr_pstrdup(cmd->pool, ap_proxy_de_socketfy(cmd->pool, r));
f36b77
+    new->real = apr_pstrdup(cmd->pool, real);
f36b77
     new->flags = flags;
f36b77
     if (worker_type & AP_PROXY_WORKER_IS_MATCH) {
f36b77
         new->regex = ap_pregcomp(cmd->pool, f, AP_REG_EXTENDED);
f36b77
@@ -2649,6 +2655,7 @@ static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg)
f36b77
     proxy_worker *worker;
f36b77
     char *path = cmd->path;
f36b77
     char *name = NULL;
f36b77
+    const char *real;
f36b77
     char *word;
f36b77
     apr_table_t *params = apr_table_make(cmd->pool, 5);
f36b77
     const apr_array_header_t *arr;
f36b77
@@ -2689,6 +2696,9 @@ static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg)
f36b77
         return "BalancerMember must define balancer name when outside <Proxy > section";
f36b77
     if (!name)
f36b77
         return "BalancerMember must define remote proxy server";
f36b77
+    if (!(real = ap_proxy_de_socketfy(cmd->temp_pool, name))) {
f36b77
+        return "BalancerMember uses an invalid \"unix:\" URL";
f36b77
+    }
f36b77
 
f36b77
     ap_str_tolower(path);   /* lowercase scheme://hostname */
f36b77
 
f36b77
@@ -2701,8 +2711,7 @@ static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg)
f36b77
     }
f36b77
 
f36b77
     /* Try to find existing worker */
f36b77
-    worker = ap_proxy_get_worker(cmd->temp_pool, balancer, conf,
f36b77
-                                 ap_proxy_de_socketfy(cmd->temp_pool, name));
f36b77
+    worker = ap_proxy_get_worker(cmd->temp_pool, balancer, conf, real);
f36b77
     if (!worker) {
f36b77
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server, APLOGNO(01147)
f36b77
                      "Defining worker '%s' for balancer '%s'",
f36b77
@@ -2799,9 +2808,14 @@ static const char *
f36b77
         }
f36b77
     }
f36b77
     else {
f36b77
+        const char *real;
f36b77
+
f36b77
+        if (!(real = ap_proxy_de_socketfy(cmd->temp_pool, name))) {
f36b77
+            return "ProxySet uses an invalid \"unix:\" URL";
f36b77
+        }
f36b77
+
f36b77
         worker = ap_proxy_get_worker_ex(cmd->temp_pool, NULL, conf,
f36b77
-                                        ap_proxy_de_socketfy(cmd->temp_pool, name),
f36b77
-                                        worker_type);
f36b77
+                                        real, worker_type);
f36b77
         if (!worker) {
f36b77
             if (in_proxy_section) {
f36b77
                 err = ap_proxy_define_worker_ex(cmd->pool, &worker, NULL,
f36b77
@@ -2944,9 +2958,14 @@ static const char *proxysection(cmd_parms *cmd, void *mconfig, const char *arg)
f36b77
             }
f36b77
         }
f36b77
         else {
f36b77
+            const char *real;
f36b77
+
f36b77
+            if (!(real = ap_proxy_de_socketfy(cmd->temp_pool, conf->p))) {
f36b77
+                return "<Proxy/ProxyMatch > uses an invalid \"unix:\" URL";
f36b77
+            }
f36b77
+
f36b77
             worker = ap_proxy_get_worker_ex(cmd->temp_pool, NULL, sconf,
f36b77
-                                            ap_proxy_de_socketfy(cmd->temp_pool, conf->p),
f36b77
-                                            worker_type);
f36b77
+                                            real, worker_type);
f36b77
             if (!worker) {
f36b77
                 err = ap_proxy_define_worker_ex(cmd->pool, &worker, NULL, sconf,
f36b77
                                                 conf->p, worker_type);
f36b77
diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h
f36b77
index 044a6c4..c21c4d8 100644
f36b77
--- a/modules/proxy/mod_proxy.h
f36b77
+++ b/modules/proxy/mod_proxy.h
f36b77
@@ -751,6 +751,7 @@ PROXY_DECLARE(int) ap_proxy_worker_can_upgrade(apr_pool_t *p,
f36b77
 #define AP_PROXY_WORKER_IS_PREFIX   (1u << 0)
f36b77
 #define AP_PROXY_WORKER_IS_MATCH    (1u << 1)
f36b77
 #define AP_PROXY_WORKER_IS_MALLOCED (1u << 2)
f36b77
+#define AP_PROXY_WORKER_NO_UDS      (1u << 3)
f36b77
 
f36b77
 /**
f36b77
  * Get the worker from proxy configuration, looking for either PREFIXED or
f36b77
diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c
f36b77
index 8225045..cbe300f 100644
f36b77
--- a/modules/proxy/proxy_util.c
f36b77
+++ b/modules/proxy/proxy_util.c
f36b77
@@ -1741,7 +1741,12 @@ PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker_ex(apr_pool_t *p,
f36b77
         return NULL;
f36b77
     }
f36b77
 
f36b77
+    if (!(mask & AP_PROXY_WORKER_NO_UDS)) {
f36b77
     url = ap_proxy_de_socketfy(p, url);
f36b77
+        if (!url) {
f36b77
+            return NULL;
f36b77
+        }
f36b77
+    }
f36b77
 
f36b77
     c = ap_strchr_c(url, ':');
f36b77
     if (c == NULL || c[1] != '/' || c[2] != '/' || c[3] == '\0') {
f36b77
@@ -2323,22 +2328,22 @@ PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
f36b77
 
f36b77
     access_status = proxy_run_pre_request(worker, balancer, r, conf, url);
f36b77
     if (access_status == DECLINED && *balancer == NULL) {
f36b77
-        *worker = ap_proxy_get_worker(r->pool, NULL, conf, *url);
f36b77
+        const int forward = (r->proxyreq == PROXYREQ_PROXY);
f36b77
+        *worker = ap_proxy_get_worker_ex(r->pool, NULL, conf, *url,
f36b77
+                                         forward ? AP_PROXY_WORKER_NO_UDS : 0);
f36b77
         if (*worker) {
f36b77
             ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
f36b77
                           "%s: found worker %s for %s",
f36b77
                           (*worker)->s->scheme, (*worker)->s->name, *url);
f36b77
-            *balancer = NULL;
f36b77
-            if (!fix_uds_filename(r, url)) {
f36b77
+            if (!forward && !fix_uds_filename(r, url)) {
f36b77
                 return HTTP_INTERNAL_SERVER_ERROR;
f36b77
             }
f36b77
             access_status = OK;
f36b77
         }
f36b77
-        else if (r->proxyreq == PROXYREQ_PROXY) {
f36b77
+        else if (forward) {
f36b77
             if (conf->forward) {
f36b77
                 ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
f36b77
                               "*: found forward proxy worker for %s", *url);
f36b77
-                *balancer = NULL;
f36b77
                 *worker = conf->forward;
f36b77
                 access_status = OK;
f36b77
                 /*
f36b77
@@ -2352,8 +2357,8 @@ PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
f36b77
         else if (r->proxyreq == PROXYREQ_REVERSE) {
f36b77
             if (conf->reverse) {
f36b77
                 ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
f36b77
-                              "*: using default reverse proxy worker for %s (no keepalive)", *url);
f36b77
-                *balancer = NULL;
f36b77
+                              "*: using default reverse proxy worker for %s "
f36b77
+                              "(no keepalive)", *url);
f36b77
                 *worker = conf->reverse;
f36b77
                 access_status = OK;
f36b77
                 /*
f36b77
diff --git a/server/protocol.c b/server/protocol.c
f36b77
index 3d74c5b..2214f72 100644
f36b77
--- a/server/protocol.c
f36b77
+++ b/server/protocol.c
f36b77
@@ -1548,7 +1548,7 @@ request_rec *ap_read_request(conn_rec *conn)
f36b77
     /* we may have switched to another server */
f36b77
     apply_server_config(r);
f36b77
 
f36b77
-    if ((access_status = ap_run_post_read_request(r))) {
f36b77
+    if ((access_status = ap_post_read_request(r))) {
f36b77
         goto die;
f36b77
     }
f36b77
 
f36b77
@@ -1603,6 +1603,27 @@ ignore:
f36b77
     return NULL;
f36b77
 }
f36b77
 
f36b77
+AP_DECLARE(int) ap_post_read_request(request_rec *r)
f36b77
+{
f36b77
+    int status;
f36b77
+
f36b77
+    if ((status = ap_run_post_read_request(r))) {
f36b77
+        return status;
f36b77
+    }
f36b77
+
f36b77
+    /* Enforce http(s) only scheme for non-forward-proxy requests */
f36b77
+    if (!r->proxyreq
f36b77
+            && r->parsed_uri.scheme
f36b77
+            && (ap_cstr_casecmpn(r->parsed_uri.scheme, "http", 4) != 0
f36b77
+                || (r->parsed_uri.scheme[4] != '\0'
f36b77
+                    && (apr_tolower(r->parsed_uri.scheme[4]) != 's'
f36b77
+                        || r->parsed_uri.scheme[5] != '\0')))) {
f36b77
+        return HTTP_BAD_REQUEST;
f36b77
+    }
f36b77
+
f36b77
+    return OK;
f36b77
+}
f36b77
+
f36b77
 /* if a request with a body creates a subrequest, remove original request's
f36b77
  * input headers which pertain to the body which has already been read.
f36b77
  * out-of-line helper function for ap_set_sub_req_protocol.