692b48
diff --git a/include/http_protocol.h b/include/http_protocol.h
692b48
index e7abdd9..e1572dc 100644
692b48
--- a/include/http_protocol.h
692b48
+++ b/include/http_protocol.h
692b48
@@ -96,6 +96,13 @@ AP_DECLARE(void) ap_get_mime_headers(request_rec *r);
692b48
 AP_DECLARE(void) ap_get_mime_headers_core(request_rec *r,
692b48
                                           apr_bucket_brigade *bb);
692b48
 
692b48
+/**
692b48
+ * Run post_read_request hook and validate.
692b48
+ * @param r The current request
692b48
+ * @return OK or HTTP_...
692b48
+ */
692b48
+AP_DECLARE(int) ap_post_read_request(request_rec *r);
692b48
+
692b48
 /* Finish up stuff after a request */
692b48
 
692b48
 /**
692b48
diff --git a/modules/http/http_request.c b/modules/http/http_request.c
692b48
index 9e7c4db..e873aab 100644
692b48
--- a/modules/http/http_request.c
692b48
+++ b/modules/http/http_request.c
692b48
@@ -681,7 +681,7 @@ static request_rec *internal_internal_redirect(const char *new_uri,
692b48
      * to do their thing on internal redirects as well.  Perhaps this is a
692b48
      * misnamed function.
692b48
      */
692b48
-    if ((access_status = ap_run_post_read_request(new))) {
692b48
+    if ((access_status = ap_post_read_request(new))) {
692b48
         ap_die(access_status, new);
692b48
         return NULL;
692b48
     }
692b48
diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c
692b48
index 6a9ef55..a6df1b8 100644
692b48
--- a/modules/proxy/mod_proxy.c
692b48
+++ b/modules/proxy/mod_proxy.c
692b48
@@ -584,11 +584,12 @@ static int proxy_detect(request_rec *r)
692b48
 
692b48
     if (conf->req && r->parsed_uri.scheme) {
692b48
         /* but it might be something vhosted */
692b48
-        if (!(r->parsed_uri.hostname
692b48
-              && !strcasecmp(r->parsed_uri.scheme, ap_http_scheme(r))
692b48
-              && ap_matches_request_vhost(r, r->parsed_uri.hostname,
692b48
-                                          (apr_port_t)(r->parsed_uri.port_str ? r->parsed_uri.port
692b48
-                                                       : ap_default_port(r))))) {
692b48
+        if (!r->parsed_uri.hostname
692b48
+            || ap_cstr_casecmp(r->parsed_uri.scheme, ap_http_scheme(r)) != 0
692b48
+            || !ap_matches_request_vhost(r, r->parsed_uri.hostname,
692b48
+                                         (apr_port_t)(r->parsed_uri.port_str
692b48
+                                                      ? r->parsed_uri.port
692b48
+                                                      : ap_default_port(r)))) {
692b48
             r->proxyreq = PROXYREQ_PROXY;
692b48
             r->uri = r->unparsed_uri;
692b48
             r->filename = apr_pstrcat(r->pool, "proxy:", r->uri, NULL);
692b48
@@ -1750,6 +1751,7 @@ static const char *
692b48
     struct proxy_alias *new;
692b48
     char *f = cmd->path;
692b48
     char *r = NULL;
692b48
+    const char *real;
692b48
     char *word;
692b48
     apr_table_t *params = apr_table_make(cmd->pool, 5);
692b48
     const apr_array_header_t *arr;
692b48
@@ -1815,6 +1817,10 @@ static const char *
692b48
     if (r == NULL) {
692b48
         return "ProxyPass|ProxyPassMatch needs a path when not defined in a location";
692b48
     }
692b48
+    if (!(real = ap_proxy_de_socketfy(cmd->temp_pool, r))) {
692b48
+        return "ProxyPass|ProxyPassMatch uses an invalid \"unix:\" URL";
692b48
+    }
692b48
+
692b48
 
692b48
     /* if per directory, save away the single alias */
692b48
     if (cmd->path) {
692b48
@@ -1831,7 +1837,7 @@ static const char *
692b48
     }
692b48
 
692b48
     new->fake = apr_pstrdup(cmd->pool, f);
692b48
-    new->real = apr_pstrdup(cmd->pool, ap_proxy_de_socketfy(cmd->pool, r));
692b48
+    new->real = apr_pstrdup(cmd->pool, real);
692b48
     new->flags = flags;
692b48
     if (use_regex) {
692b48
         new->regex = ap_pregcomp(cmd->pool, f, AP_REG_EXTENDED);
692b48
@@ -2316,6 +2322,7 @@ static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg)
692b48
     proxy_worker *worker;
692b48
     char *path = cmd->path;
692b48
     char *name = NULL;
692b48
+    const char *real;
692b48
     char *word;
692b48
     apr_table_t *params = apr_table_make(cmd->pool, 5);
692b48
     const apr_array_header_t *arr;
692b48
@@ -2356,6 +2363,9 @@ static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg)
692b48
         return "BalancerMember must define balancer name when outside <Proxy > section";
692b48
     if (!name)
692b48
         return "BalancerMember must define remote proxy server";
692b48
+    if (!(real = ap_proxy_de_socketfy(cmd->temp_pool, name))) {
692b48
+        return "BalancerMember uses an invalid \"unix:\" URL";
692b48
+    }
692b48
 
692b48
     ap_str_tolower(path);   /* lowercase scheme://hostname */
692b48
 
692b48
@@ -2368,7 +2378,7 @@ static const char *add_member(cmd_parms *cmd, void *dummy, const char *arg)
692b48
     }
692b48
 
692b48
     /* Try to find existing worker */
692b48
-    worker = ap_proxy_get_worker(cmd->temp_pool, balancer, conf, ap_proxy_de_socketfy(cmd->temp_pool, name));
692b48
+    worker = ap_proxy_get_worker(cmd->temp_pool, balancer, conf, real);
692b48
     if (!worker) {
692b48
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server, APLOGNO(01147)
692b48
                      "Defining worker '%s' for balancer '%s'",
692b48
@@ -2457,7 +2467,13 @@ static const char *
692b48
         }
692b48
     }
692b48
     else {
692b48
-        worker = ap_proxy_get_worker(cmd->temp_pool, NULL, conf, ap_proxy_de_socketfy(cmd->temp_pool, name));
692b48
+        const char *real;
692b48
+
692b48
+        if (!(real = ap_proxy_de_socketfy(cmd->temp_pool, name))) {
692b48
+            return "ProxySet uses an invalid \"unix:\" URL";
692b48
+        }
692b48
+
692b48
+        worker = ap_proxy_get_worker(cmd->temp_pool, NULL, conf, real);
692b48
         if (!worker) {
692b48
             if (in_proxy_section) {
692b48
                 err = ap_proxy_define_worker(cmd->pool, &worker, NULL,
692b48
@@ -2599,8 +2615,14 @@ static const char *proxysection(cmd_parms *cmd, void *mconfig, const char *arg)
692b48
             }
692b48
         }
692b48
         else {
692b48
+            const char *real;
692b48
+
692b48
+            if (!(real = ap_proxy_de_socketfy(cmd->temp_pool, conf->p))) {
692b48
+                return "<Proxy/ProxyMatch > uses an invalid \"unix:\" URL";
692b48
+            }
692b48
+
692b48
             worker = ap_proxy_get_worker(cmd->temp_pool, NULL, sconf,
692b48
-                                         ap_proxy_de_socketfy(cmd->temp_pool, (char*)conf->p));
692b48
+                                         real);
692b48
             if (!worker) {
692b48
                 err = ap_proxy_define_worker(cmd->pool, &worker, NULL,
692b48
                                           sconf, conf->p, 0);
692b48
diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h
692b48
index fbbd508..dca6f69 100644
692b48
--- a/modules/proxy/mod_proxy.h
692b48
+++ b/modules/proxy/mod_proxy.h
692b48
@@ -713,6 +713,8 @@ typedef __declspec(dllimport) const char *
692b48
                proxy_dir_conf *, const char *);
692b48
 #endif
692b48
 
692b48
+#define AP_PROXY_WORKER_NO_UDS      (1u << 3)
692b48
+
692b48
 
692b48
 /* Connection pool API */
692b48
 /**
692b48
@@ -725,6 +727,24 @@ typedef __declspec(dllimport) const char *
692b48
 PROXY_DECLARE(char *) ap_proxy_worker_name(apr_pool_t *p,
692b48
                                            proxy_worker *worker);
692b48
 
692b48
+
692b48
+/**
692b48
+ * Get the worker from proxy configuration, looking for either PREFIXED or
692b48
+ * MATCHED or both types of workers according to given mask
692b48
+ * @param p        memory pool used for finding worker
692b48
+ * @param balancer the balancer that the worker belongs to
692b48
+ * @param conf     current proxy server configuration
692b48
+ * @param url      url to find the worker from
692b48
+ * @param mask     bitmask of AP_PROXY_WORKER_IS_*
692b48
+ * @return         proxy_worker or NULL if not found
692b48
+ */
692b48
+PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker_ex(apr_pool_t *p,
692b48
+                                                     proxy_balancer *balancer,
692b48
+                                                     proxy_server_conf *conf,
692b48
+                                                     const char *url,
692b48
+                                                     unsigned int mask);
692b48
+
692b48
+
692b48
 /**
692b48
  * Get the worker from proxy configuration
692b48
  * @param p        memory pool used for finding worker
692b48
@@ -737,6 +757,8 @@ PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
692b48
                                                   proxy_balancer *balancer,
692b48
                                                   proxy_server_conf *conf,
692b48
                                                   const char *url);
692b48
+
692b48
+
692b48
 /**
692b48
  * Define and Allocate space for the worker to proxy configuration
692b48
  * @param p         memory pool to allocate worker from
692b48
diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c
692b48
index 032e0c4..3d5b220 100644
692b48
--- a/modules/proxy/proxy_util.c
692b48
+++ b/modules/proxy/proxy_util.c
692b48
@@ -1643,10 +1643,11 @@ PROXY_DECLARE(char *) ap_proxy_worker_name(apr_pool_t *p,
692b48
     return apr_pstrcat(p, "unix:", worker->s->uds_path, "|", worker->s->name, NULL);
692b48
 }
692b48
 
692b48
-PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
692b48
-                                                  proxy_balancer *balancer,
692b48
-                                                  proxy_server_conf *conf,
692b48
-                                                  const char *url)
692b48
+PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker_ex(apr_pool_t *p,
692b48
+                                                     proxy_balancer *balancer,
692b48
+                                                     proxy_server_conf *conf,
692b48
+                                                     const char *url,
692b48
+                                                     unsigned int mask)
692b48
 {
692b48
     proxy_worker *worker;
692b48
     proxy_worker *max_worker = NULL;
692b48
@@ -1662,7 +1663,12 @@ PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
692b48
         return NULL;
692b48
     }
692b48
 
692b48
-    url = ap_proxy_de_socketfy(p, url);
692b48
+    if (!(mask & AP_PROXY_WORKER_NO_UDS)) {
692b48
+        url = ap_proxy_de_socketfy(p, url);
692b48
+        if (!url) {
692b48
+            return NULL;
692b48
+        }
692b48
+    }
692b48
 
692b48
     c = ap_strchr_c(url, ':');
692b48
     if (c == NULL || c[1] != '/' || c[2] != '/' || c[3] == '\0') {
692b48
@@ -1727,6 +1733,14 @@ PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
692b48
     return max_worker;
692b48
 }
692b48
 
692b48
+PROXY_DECLARE(proxy_worker *) ap_proxy_get_worker(apr_pool_t *p,
692b48
+                                                  proxy_balancer *balancer,
692b48
+                                                  proxy_server_conf *conf,
692b48
+                                                  const char *url)
692b48
+{
692b48
+    return ap_proxy_get_worker_ex(p, balancer, conf, url, 0);
692b48
+}
692b48
+
692b48
 /*
692b48
  * To create a worker from scratch first we define the
692b48
  * specifics of the worker; this is all local data.
692b48
@@ -2134,22 +2148,22 @@ PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
692b48
 
692b48
     access_status = proxy_run_pre_request(worker, balancer, r, conf, url);
692b48
     if (access_status == DECLINED && *balancer == NULL) {
692b48
-        *worker = ap_proxy_get_worker(r->pool, NULL, conf, *url);
692b48
+        const int forward = (r->proxyreq == PROXYREQ_PROXY);
692b48
+        *worker = ap_proxy_get_worker_ex(r->pool, NULL, conf, *url,
692b48
+                                         forward ? AP_PROXY_WORKER_NO_UDS : 0);
692b48
         if (*worker) {
692b48
             ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
692b48
                           "%s: found worker %s for %s",
692b48
                           (*worker)->s->scheme, (*worker)->s->name, *url);
692b48
-            *balancer = NULL;
692b48
-            if (!fix_uds_filename(r, url)) {
692b48
+            if (!forward && !fix_uds_filename(r, url)) {
692b48
                      return HTTP_INTERNAL_SERVER_ERROR;
692b48
             }
692b48
             access_status = OK;
692b48
         }
692b48
-        else if (r->proxyreq == PROXYREQ_PROXY) {
692b48
+        else if (forward) {
692b48
             if (conf->forward) {
692b48
                 ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
692b48
                               "*: found forward proxy worker for %s", *url);
692b48
-                *balancer = NULL;
692b48
                 *worker = conf->forward;
692b48
                 access_status = OK;
692b48
                 /*
692b48
@@ -2163,8 +2177,8 @@ PROXY_DECLARE(int) ap_proxy_pre_request(proxy_worker **worker,
692b48
         else if (r->proxyreq == PROXYREQ_REVERSE) {
692b48
             if (conf->reverse) {
692b48
                 ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
692b48
-                              "*: using default reverse proxy worker for %s (no keepalive)", *url);
692b48
-                *balancer = NULL;
692b48
+                              "*: using default reverse proxy worker for %s "
692b48
+                              "(no keepalive)", *url);
692b48
                 *worker = conf->reverse;
692b48
                 access_status = OK;
692b48
                 /*
692b48
diff --git a/server/protocol.c b/server/protocol.c
692b48
index 430d91e..a2aa081 100644
692b48
--- a/server/protocol.c
692b48
+++ b/server/protocol.c
692b48
@@ -1525,7 +1525,7 @@ request_rec *ap_read_request(conn_rec *conn)
692b48
     /* we may have switched to another server */
692b48
     apply_server_config(r);
692b48
 
692b48
-    if ((access_status = ap_run_post_read_request(r))) {
692b48
+    if ((access_status = ap_post_read_request(r))) {
692b48
         goto die;
692b48
     }
692b48
 
692b48
@@ -1582,6 +1582,27 @@ ignore:
692b48
     return NULL;
692b48
 }
692b48
 
692b48
+AP_DECLARE(int) ap_post_read_request(request_rec *r)
692b48
+{
692b48
+    int status;
692b48
+
692b48
+    if ((status = ap_run_post_read_request(r))) {
692b48
+        return status;
692b48
+    }
692b48
+
692b48
+    /* Enforce http(s) only scheme for non-forward-proxy requests */
692b48
+    if (!r->proxyreq
692b48
+            && r->parsed_uri.scheme
692b48
+            && (ap_cstr_casecmpn(r->parsed_uri.scheme, "http", 4) != 0
692b48
+                || (r->parsed_uri.scheme[4] != '\0'
692b48
+                    && (apr_tolower(r->parsed_uri.scheme[4]) != 's'
692b48
+                        || r->parsed_uri.scheme[5] != '\0')))) {
692b48
+        return HTTP_BAD_REQUEST;
692b48
+    }
692b48
+
692b48
+    return OK;
692b48
+}
692b48
+
692b48
 /* if a request with a body creates a subrequest, remove original request's
692b48
  * input headers which pertain to the body which has already been read.
692b48
  * out-of-line helper function for ap_set_sub_req_protocol.