Bug 52465 - mod_dir is allowed to redirect proxy requests
Summary: mod_dir is allowed to redirect proxy requests
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_rewrite (show other bugs)
Version: 2.2.21
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
Keywords: MassUpdate
Depends on:
Reported: 2012-01-13 16:53 UTC by Matthew Byng-Maddick
Modified: 2018-11-07 21:09 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Byng-Maddick 2012-01-13 16:53:00 UTC
There exists a code path where, if you have a directory <docroot>/foo (or similar aliased directory, and you do something like:

<Location /foo>
  RewriteRule ^ http://some.other.server%{REQUEST_URI} [P]

If you request /foo (no trailing slash), you go through your request phases, do URI->filename translation, lookup the file (and find it exists), so you set r->finfo up (particularly with r->finfo.filetype == APR_DIR) from the stat call, and then you get to your fixups.

mod_rewrite does its fixup, rewriting r->filename to proxy:http://some.other.server/foo, as it should, it then sets up r->handler to be proxy_server, and sets r->proxyreq to be PROXY_REVERSE, as it should.

Unfortunately, r->finfo.filetype is still set, so when mod_dir comes to do *its* fixups, it finds that the finfo.filetype is APR_DIR, it then finds that the uri doesn't have a trailing slash, so it helpfully redirects to one that does.

There are 2 possible fixes for this, and it might be worth applying both:
(1) mod_dir.c:dir_fixups(), at the beginning add something that checks for r->proxyreq, r->filename and !strncmp(r->filename, "proxy:", 6), and returns DECLINED.
(2) mod_rewrite.c:hook_fixup(), before the log line:
            rewritelog((r, 1, dconf->directory, "go-ahead with proxy request "
                        "%s [OK]", r->filename));
add: r->finfo.filetype = APR_NOFILE;

Either, on their own will sort out the problem, but there may be other ways to get to either state, so it seems sensible to belt-and-braces...
Comment 1 William A. Rowe Jr. 2018-11-07 21:09:44 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.