Bug 29554 - mod_proxy mishandles escaped characters
Summary: mod_proxy mishandles escaped characters
Status: RESOLVED WONTFIX
Alias: None
Product: Apache httpd-1.3
Classification: Unclassified
Component: mod_proxy (show other bugs)
Version: 1.3.26
Hardware: Other other
: P3 normal with 7 votes (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords: PatchAvailable
: 34688 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-06-14 11:05 UTC by Faré
Modified: 2007-08-02 12:31 UTC (History)
1 user (show)



Attachments
Fix for ProxyPass with encoded : and / (2.28 KB, patch)
2004-06-16 14:41 UTC, Faré
Details | Diff
Fix ProxyPass AND not break everything else. (2.15 KB, patch)
2004-06-16 15:24 UTC, Faré
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Faré 2004-06-14 11:05:21 UTC
I'm using a backend server behind a ProxyPass and a ProxyPassReverse.

When the URL contains a %3A (encoded colon :) this %3A is passed to the backend
as : instead of being kept as %3A, which yields an invalid URL and confuses the
backend.

When the URL contains a %2F (encoded slash /), mod_proxy becomes quite confused,
and yields a 404 without even consulting the backend.
Comment 1 Faré 2004-06-14 11:11:00 UTC
Tested with apache 1.3.26-0woody3 from debian as well as with a libproxy
recompiled from the 1.3.31-1 source package from debian.

Relevant lines from httpd.conf:
ProxyPass / http://my.server.fqdn:8000/
ProxyPassReverse / http://my.server.fqdn:8000/
Comment 2 Faré 2004-06-14 13:39:06 UTC
While trying to isolate the bug, I found that the : behaviour went wrong when
apache is listening on port 80, but not when it is listening to port 8000. The
way things are handled seem quite messy -- walking to the first : in a decoded URL?

Note that the symptoms are vaguely similar to those of bug 11265, though the
internal details differ.
Comment 3 Faré 2004-06-16 09:01:44 UTC
The problem seems to be in the URL "canonicalization" happening in
proxy_http.c:ap_proxy_http_canon, as called from mod_proxy.c:proxy_fixup.
I can't fix it right now, because I don't understand the ins and outs of the
proxy protocol: particularly, the GET http://foo.bar/baz HTTP/0.9 is one thing,
and GET /baz HTTP/1.1 Host: foo.bar is another, but there are other cases.

Can anyone point me to a document that explains this part of the protocol?
Comment 4 Faré 2004-06-16 14:41:43 UTC
Created attachment 11856 [details]
Fix for ProxyPass with encoded : and /
Comment 5 Faré 2004-06-16 14:45:13 UTC
OK. There were two bugs involved.

The port 80/8000 thing might have had to do with my incorrectly tweaking
httpd.conf during testing, so let's forget it.

The problem with %3A ':' was due to a misguided URI canonicalization attempt in
function modules/proxy/mod_proxy.c:proxy_fixup(). I added a bypass to the
canonicalization in the case of PROXY_PASS. Actually I believe canonicalization
shouldn't happen in the STD_PROXY case either and the whole function should be
scrapped.

The problem with %2F '/' was due to r->proxyreq=PROXY_PASS being declared too
late, only in modules/proxy/mod_proxy.c:proxy_trans(), so that
main/http_request.c:process_request_internal() messed up with the URL, not
realizing there is a proxy request going on. Consequently, I moved the stuff
from modules/proxy/mod_proxy.c:proxy_trans() into
modules/proxy/mod_proxy.c:proxy_detect().

PS: note that so as to compile mod_proxy from apache 1.3.31 on my old apache
1.3.26, I had to add this to mod_proxy.h:
#define ap_psocket_ex(p,q,r,s,t) (t==1?ap_psocket(p,q,r,s):-1)

THE HORROR! THE HORROR!
Comment 6 Faré 2004-06-16 15:22:22 UTC
Oops. A stupid bug in my previous patch (forgot to return DECLINED; in
proxy_trans()) broke everything outside of the proxy. Fixed in the following
patch...
Comment 7 Faré 2004-06-16 15:24:18 UTC
Created attachment 11858 [details]
Fix ProxyPass AND not break everything else.
Comment 8 Faré 2004-06-16 17:42:47 UTC
Looking at the sources for apache 2.0.49, I can see that the same bug is there, too.
Comment 9 Faré 2004-06-16 17:49:08 UTC
Final notes:

My debugging tool was to have LogLevel debug in the proper VirtualHost, and to
add the following macro to mod_proxy.h
#define DEBUGMSG(FMT...) \
        ap_log_rerror(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO,r,FMT)

In Apache 2, the bug is the same at the same places, modulo the change in names:
see server/request.c instead of main/http_request.c, etc. The algorithm and its
bug are the very same.

Comment 10 Faré 2004-06-24 12:44:58 UTC
Since I'm asked about a test case, try the following URL through a proxypass:
http://cliki.tunes.org/CP%2FM
http://cliki.tunes.org/Word%20Processors%3A%20Stupid%20and%20Inefficient

For instance add this line to a test virtual host:
        ProxyPass /cto/ http://cliki.tunes.org/
And then access /cto/CP%2FM

Log the result with ap_log_rerror as above...
Comment 11 Emmanuel DECAEN 2004-07-29 11:43:44 UTC
This is not exactly the same problem, but it can be related.

I've setup the following conf :
  ProxyPass /info/ http://internal:8888/info.asp?

The problem is that "?" is replaced by a "%3F", like in this example :
"http://website.com/info/param" --> "http://internal:8888/info.asp%3Fparam" 


If I replace the previous conf, with the following one, I get the correct 
request.
  RewriteRule ^/info/(.*) http://internal:8888/info.asp?$1 [P]

"http://website.com/info/param" -> "http://internal:8888/info.asp?param"

Is this a normal behaviour ?
Comment 12 Emmanuel DECAEN 2004-07-30 09:52:37 UTC
Ok, the problem I had, is more similar to 13577 bugid.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13577

Sorry for the Duplicate.
Comment 13 Mike Brown 2004-08-25 05:52:04 UTC
The mishandled escapes occur even with a regular proxy under Apache 1.3.31, 
not just with a ProxyPass proxy.

In my httpd.conf I have 

    <Directory proxy:*>
        Order deny,allow
        Deny from all
        Allow from .my.trusted.domain
        Allow from .other.trusted.domain
    </Directory>

<VirtualHost *:15151>
    ProxyRequests On
    ProxyVia On
    NoCache *
</VirtualHost>

When I send a request to this proxy for http://myserver/something-with-%2B, 
the proxy asks myserver for /something-with-+, where the %2B was mistakenly 
decoded. This situation is like the one reported in #13577, but that one is 
marked as fixed and applies to Apache 2.0 only, and this bug (29554) mentions 
ProxyPass only. If the problem is more general, then it should be fixed more 
generally, not just for the ProxyPass situation.
Comment 14 Mike Brown 2004-08-25 05:55:10 UTC
I just noticed that Faré wrote:

"Actually I believe canonicalization shouldn't happen in the STD_PROXY case 
either and the whole function should be scrapped."

So please regard my previous comment as a "me too".
Comment 15 Tril 2004-09-28 17:52:55 UTC
Changing bug summary to indicate bug is for proxy in general and for escapes in
general, not just ProxyPass for / and :
Comment 16 Tril 2004-09-28 17:56:44 UTC
Can someone please create a patch that makes the suggested change, removing the
offending function, so it can be tested?
Comment 17 Balz Schreier 2005-02-21 17:31:32 UTC
i use mod_proxy on apache 2.0.50
can somebody tell me when an official patch or bugfix or next apache release
will be available?
there have been no posts since 2004-Sep-18
thanks
Comment 18 Graham Leggett 2005-02-22 14:00:57 UTC
Does anybody have a patch for either v2.0.x or trunk?
Comment 19 Oliver Crow 2005-05-18 01:21:39 UTC
Have you tried this (much simpler) patch for the "misguided canonicalization"
problem?

http://issues.apache.org/bugzilla/show_bug.cgi?id=34688
Comment 20 Joe Orton 2005-08-05 16:00:30 UTC
Fixed for 2.0.55: http://svn.apache.org/viewcvs.cgi?rev=227435&view=rev
Comment 21 Joe Orton 2005-08-05 16:01:29 UTC
Heh.  Now I screwed up the bug reference too.  This bug is not fixed in 1.3 yet.
Comment 22 Joe Orton 2005-08-05 16:02:10 UTC
*** Bug 34688 has been marked as a duplicate of this bug. ***