Ticket #1600 (new defect)

Opened 2 months ago

Last modified 1 month ago

proxy-core.rewrite-request never works (error in mod_proxy_core.c)

Reported by: chernousov Assigned to: jan
Priority: highest Milestone: 1.5.0
Component: mod_proxy_core Version: 1.5.x-svn
Severity: critical Keywords: proxy_get_request_header mod_proxy_core.c proxy-core.rewrite-request
Cc: Blocking:
Need Feedback: 0

Description

There is an error in mod_proxy_core.c, function proxy_get_request_header(). Function ends with code

if (i == p->conf.request_rewrites->used) {
	buffer_copy_string_buffer(sess->request_uri, con->request.uri);
}

This condition is always true because there is a loop before it:

for (i = 0; i < p->conf.request_rewrites->used; i++) {

Rewrites will be done in loop, but then sess->request_uri will be restored back from con->request.uri. No rewrites will work in result.

Attachments

lighttpd-1.5-fix-request-uri-rewrite.patch (0.9 kB) - added by hoffie on 03/27/2008 02:29:18 PM.

Change History

03/20/2008 06:16:18 PM changed by bb@codepoet.de

  • priority changed from high to highest.

see this error also in my setup... should be fixed asap i think, cause i need to have mod_proxy_core with ajp and rewriting (frontend for a tomcat installation) and there seems to be no possibility atm...

(in reply to: ↑ description ) 03/26/2008 02:01:03 PM changed by osmaker+lighttpd@gmail.com

Replying to chernousov:

Rewrites will be done in loop, but then sess->request_uri will be restored back from con->request.uri. No rewrites will work in result.

This is incorrect. The rewrites of _scriptname and the like are taken care of here:

proxy_encode_request_headers(srv, sess, con->recv);

However, I traced this through with gdb and realized the problem: you must handle _pathinfo before _scriptname because otherwise con->uri.path will be overwritten with whatever value you have set for _scriptname as can be seen here:

} else if (buffer_is_equal_string(rw->header, CONST_STR_LEN("_scriptname"))) {
        int ret;

        if ((ret = pcre_replace(rw->regex, rw->replace, con->uri.path, p->replace_buf)) < 0) {
                switch (ret) {
                case PCRE_ERROR_NOMATCH:
                /* hmm, ok. no problem */
                break;
                default:
                TRACE("oops, pcre_replace failed with: %d", ret);
                break;
                }
        } else {
                /* we matched, cool. */
                buffer_copy_string_buffer(con->uri.path, p->replace_buf);
        }
}

For now, the following should work around this bug (use appropriate regex of course):

proxy-core.rewrite-request = (
  "_pathinfo" => ( "(.*)" => "$1"),
  "_scriptname" => ( ".*" => "/")
)

03/26/2008 02:02:03 PM changed by anonymous

  • pending set to 1.

03/26/2008 02:05:53 PM changed by chernousov

  • pending deleted.

I'm talking about rewriting of _uri.

03/27/2008 02:28:56 PM changed by hoffie

Everything except _uri worked fine for me. I'm not able to see how the code is supposed to work, I'm attaching a patch which makes _uri work for me, but I fear it might break something else. Any testing/review appreciated. :)

03/27/2008 02:29:18 PM changed by hoffie

  • attachment lighttpd-1.5-fix-request-uri-rewrite.patch added.

04/15/2008 06:54:39 PM changed by hoffie

This one can be closed imo, as the patch was committed in [2146]. Patch works still fine for me and did not break any other rewrite stuff. There were also some success reports in #lighttpd.


Add/Change #1600 (proxy-core.rewrite-request never works (error in mod_proxy_core.c))




Change Properties