Bug 51707

Summary: ProxyPassReverse issues within <Location> (different to 38864)
Product: Apache httpd-2 Reporter: Matthew Byng-Maddick <matthew.byng-maddick>
Component: mod_proxyAssignee: Apache HTTPD Bugs Mailing List <bugs>
Severity: normal CC: minfrin
Priority: P2 Keywords: MassUpdate
Version: 2.2.19   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Matthew Byng-Maddick 2011-08-22 17:40:34 UTC
mod_proxy uses a per-dir config to store everything, including ProxyPassReverse. ProxyPassReverse, by necessity actually operates on the real domain (the right-hand side) rather than the fake (the left-hand side or <Location> path).

This means that for the use of ProxyPassReverse inside <Location> unless the request that caused the 301 or 302 comes from inside the Location, the ProxyPassReverse can never trigger.

As well as this, the ProxyPassReverse walk is first-match (proxy_util.c:
    for (i = 0; i < conf->raliases->nelts; i++) {
            if (l1 >= l2 && strncasecmp(real, url, l2) == 0) {
                u = apr_pstrcat(r->pool, ent[i].fake, &url[l2], NULL);
                return ap_construct_url(r->pool, u, r);
), and when we merge the per-dir config (mod_proxy.c:
static void *merge_proxy_dir_config(apr_pool_t *p, void *basev, void *addv)
    proxy_dir_conf *new = (proxy_dir_conf *) apr_pcalloc(p, sizeof(proxy_dir_conf));
    proxy_dir_conf *add = (proxy_dir_conf *) addv;
    proxy_dir_conf *base = (proxy_dir_conf *) basev;
    new->raliases = apr_array_append(p, base->raliases, add->raliases);
), we helpfully append the more specific ProxyPassReverses after the less specific ones, meaning that they'll never override properly.

Unfortunately I can see both sides of the argument for ProxyPassReverse to be Location-specific. (the same proxy may be used by two different things), but either way, the ordering of the append above must be wrong.

I've been wondering instead about having a single insertion-sorted list so that most-specific always comes first, but then there is the difficulty above. Perhaps you insert into both, and then if you have a per-dir thing you use that, but if you don't you fall back to the global list, which then takes both sides and has the most expected behaviour.
Comment 1 Matthew Byng-Maddick 2011-08-23 07:27:22 UTC
Obviously, the second half of the problems described below can be solved by the trivial change of:
-    new->raliases = apr_array_append(p, base->raliases, add->raliases);
+    new->raliases = apr_array_append(p, add->raliases, base->raliases);


Comment 2 William A. Rowe Jr. 2018-11-07 21:08:05 UTC
Please help us to refine our list of open and current defects; this is a mass update of old and inactive Bugzilla reports which reflect user error, already resolved defects, and still-existing defects in httpd.

As repeatedly announced, the Apache HTTP Server Project has discontinued all development and patch review of the 2.2.x series of releases. The final release 2.2.34 was published in July 2017, and no further evaluation of bug reports or security risks will be considered or published for 2.2.x releases. All reports older than 2.4.x have been updated to status RESOLVED/LATER; no further action is expected unless the report still applies to a current version of httpd.

If your report represented a question or confusion about how to use an httpd feature, an unexpected server behavior, problems building or installing httpd, or working with an external component (a third party module, browser etc.) we ask you to start by bringing your question to the User Support and Discussion mailing list, see [https://httpd.apache.org/lists.html#http-users] for details. Include a link to this Bugzilla report for completeness with your question.

If your report was clearly a defect in httpd or a feature request, we ask that you retest using a modern httpd release (2.4.33 or later) released in the past year. If it can be reproduced, please reopen this bug and change the Version field above to the httpd version you have reconfirmed with.

Your help in identifying defects or enhancements still applicable to the current httpd server software release is greatly appreciated.