You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Stefano Mazzocchi <st...@apache.org> on 2004/01/03 19:03:36 UTC
[Bug?] absolute redirection in flow appears not to be proxy safe
I came across a very weird problem today. I had two cocoon applications
that were once running in different JVM instances, both mapped to / and
I moved them into a single Jetty instance mapped on /A and /B (for
simplicity).
Then I modified the ProxyPass settings and used the jetty web.xml trick
to change the cookie path.
Now, the interesting thing was that while /A performed just like
before, /B had a wierd problem: "redirects" were absolute to the
"webapp server", not to the "web server".
Both apps had the same exact version of cocoon (compiled this morning).
After careful examination and extensive protocol dump, I was able to
understand that while /A used
cocoon.redirectTo(../../index);
/B used
cocoon.redirectTo(/index);
and both turn up to the in the same position, but while the first
actually works (the redirect is "remapped" to the original Proxy URL,
not to the appserver one which is obviously firewalled), the second
doesn't do remapping and the web application fails because it tries to
connect to the webapp directly
[actually it's even worse, because it tries to connect to the ProxyPass
setting, which are http://localhost:8000/ in my case, so it tries to
connect to *your* machine!]
The interesting thing is that this worked perfectly in the past, when
both were mapped to /, but I can't tell what broke since I moved them
*and* change the version of cocoon at the same time.
Did anybody experience a similar behavior?
--
Stefano.
Re: [Bug?] absolute redirection in flow appears not to be proxy safe
Posted by Stefano Mazzocchi <st...@apache.org>.
On 4 Jan 2004, at 17:03, Sylvain Wallez wrote:
> Stefano Mazzocchi wrote:
>
>>
>> On 4 Jan 2004, at 10:10, Sylvain Wallez wrote:
>
>
> <snip/>
>
>>> The explanation is in the servlet spec for
>>> HttpServletResponse.sendRedirect: "If the location is relative with
>>> a leading '/' the container interprets it as relative to the servlet
>>> container root."
>>>
>>> Absolute paths don't redirect to the _webapp_ root, but the _servlet
>>> container_ root. This means that redirectTo("/index") produces a
>>> "http://localhost:8000/index" and not a
>>> "http://localhost:8000/B/index".
>>>
>>> Since the redirect location doesn't start with the ProxyPassReverse
>>> URL prefix, the httpd server sends that location verbatim to the
>>> browser.
>>>
>>> Et voilà: redirecting to the webapp root cannot be done with an
>>> absolute path.
>>
>>
>> This does not explain why redirect('/') worked before when /A was
>> mount to / instead of /A. Or I'm missing something.
>
>
> I assume your original httpd.conf was something like:
> ProxyPass /myApp http://localhost:8000/
> ProxyPassReverse /myApp http://localhost:8000/
>
> When redirecting to "/index", the "Location" header is set by Jetty to
> "http://locahost:8000/index". As it starts with
> "http://localhost:8000/", mod_proxy translates it to
> "http://www.my.com/myApp/index" and everything is fine.
>
> Now lets mount two apps on Jetty. I assume the httpd.conf looks like:
> ProxyPass /appA http://localhost:8000/A
> ProxyPassReverse /appA http://localhost:8000/A
> ProxyPass /appB http://localhost:8000/B
> ProxyPassReverse /appB http://localhost:8000/B
>
> Calling "http://www.my.com/appB" calls in turn
> "http://localhost:8000/B". When the processing of this request does a
> redirect to "/index", the "Location" header is still
> "http://localhost:8000/index", as per the servlet specification I
> quoted. This header doesn't match the ProxyPassReverse directive, and
> thus mod_proxy leaves it unchanged.
>
> The case of A is different in that the relative redirect goes back to
> the root of the _webapp_, whether it is mounted at the root of the
> servlet engine or not. This means that the "Location" header set by
> Jetty will be "http://localhost:8000/A/index". This header matches the
> ProxyPassReverse directive and therefore mod_proxy translates it to
> "http://www.my.com/appA/index".
>
> When A was mounted on "/" there was no difference between redirecting
> to the servlet container root and redirecting to the webapp root.
>
> Hope it's clearer.
It is!
Thanks a lot!
--
Stefano.
Re: [Bug?] absolute redirection in flow appears not to be proxy safe
Posted by Sylvain Wallez <sy...@apache.org>.
Stefano Mazzocchi wrote:
>
> On 4 Jan 2004, at 10:10, Sylvain Wallez wrote:
<snip/>
>> The explanation is in the servlet spec for
>> HttpServletResponse.sendRedirect: "If the location is relative with a
>> leading '/' the container interprets it as relative to the servlet
>> container root."
>>
>> Absolute paths don't redirect to the _webapp_ root, but the _servlet
>> container_ root. This means that redirectTo("/index") produces a
>> "http://localhost:8000/index" and not a "http://localhost:8000/B/index".
>>
>> Since the redirect location doesn't start with the ProxyPassReverse
>> URL prefix, the httpd server sends that location verbatim to the
>> browser.
>>
>> Et voilà: redirecting to the webapp root cannot be done with an
>> absolute path.
>
>
> This does not explain why redirect('/') worked before when /A was
> mount to / instead of /A. Or I'm missing something.
I assume your original httpd.conf was something like:
ProxyPass /myApp http://localhost:8000/
ProxyPassReverse /myApp http://localhost:8000/
When redirecting to "/index", the "Location" header is set by Jetty to
"http://locahost:8000/index". As it starts with
"http://localhost:8000/", mod_proxy translates it to
"http://www.my.com/myApp/index" and everything is fine.
Now lets mount two apps on Jetty. I assume the httpd.conf looks like:
ProxyPass /appA http://localhost:8000/A
ProxyPassReverse /appA http://localhost:8000/A
ProxyPass /appB http://localhost:8000/B
ProxyPassReverse /appB http://localhost:8000/B
Calling "http://www.my.com/appB" calls in turn
"http://localhost:8000/B". When the processing of this request does a
redirect to "/index", the "Location" header is still
"http://localhost:8000/index", as per the servlet specification I
quoted. This header doesn't match the ProxyPassReverse directive, and
thus mod_proxy leaves it unchanged.
The case of A is different in that the relative redirect goes back to
the root of the _webapp_, whether it is mounted at the root of the
servlet engine or not. This means that the "Location" header set by
Jetty will be "http://localhost:8000/A/index". This header matches the
ProxyPassReverse directive and therefore mod_proxy translates it to
"http://www.my.com/appA/index".
When A was mounted on "/" there was no difference between redirecting to
the servlet container root and redirecting to the webapp root.
Hope it's clearer.
Sylvain
--
Sylvain Wallez Anyware Technologies
http://www.apache.org/~sylvain http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance - http://www.orixo.com
Re: [Bug?] absolute redirection in flow appears not to be proxy safe
Posted by Stefano Mazzocchi <st...@apache.org>.
On 4 Jan 2004, at 10:10, Sylvain Wallez wrote:
> Stefano Mazzocchi wrote:
>
>> I came across a very weird problem today. I had two cocoon
>> applications that were once running in different JVM instances, both
>> mapped to / and I moved them into a single Jetty instance mapped on
>> /A and /B (for simplicity).
>>
>> Then I modified the ProxyPass settings and used the jetty web.xml
>> trick to change the cookie path.
>
>
> What's this "web.xml trick"?
see my last cvs commit log.
>> Now, the interesting thing was that while /A performed just like
>> before, /B had a wierd problem: "redirects" were absolute to the
>> "webapp server", not to the "web server".
>>
>> Both apps had the same exact version of cocoon (compiled this
>> morning).
>>
>> After careful examination and extensive protocol dump, I was able to
>> understand that while /A used
>>
>> cocoon.redirectTo(../../index);
>>
>> /B used
>>
>> cocoon.redirectTo(/index);
>>
>> and both turn up to the in the same position, but while the first
>> actually works (the redirect is "remapped" to the original Proxy URL,
>> not to the appserver one which is obviously firewalled), the second
>> doesn't do remapping and the web application fails because it tries
>> to connect to the webapp directly
>>
>> [actually it's even worse, because it tries to connect to the
>> ProxyPass setting, which are http://localhost:8000/ in my case, so it
>> tries to connect to *your* machine!]
>>
>> The interesting thing is that this worked perfectly in the past, when
>> both were mapped to /, but I can't tell what broke since I moved them
>> *and* change the version of cocoon at the same time.
>>
>> Did anybody experience a similar behavior?
>
>
> The explanation is in the servlet spec for
> HttpServletResponse.sendRedirect: "If the location is relative with a
> leading '/' the container interprets it as relative to the servlet
> container root."
>
> Absolute paths don't redirect to the _webapp_ root, but the _servlet
> container_ root. This means that redirectTo("/index") produces a
> "http://localhost:8000/index" and not a
> "http://localhost:8000/B/index".
>
> Since the redirect location doesn't start with the ProxyPassReverse
> URL prefix, the httpd server sends that location verbatim to the
> browser.
>
> Et voilà: redirecting to the webapp root cannot be done with an
> absolute path.
This does not explain why redirect('/') worked before when /A was mount
to / instead of /A. Or I'm missing something.
--
Stefano.
Re: [Bug?] absolute redirection in flow appears not to be proxy safe
Posted by Sylvain Wallez <sy...@apache.org>.
Stefano Mazzocchi wrote:
> I came across a very weird problem today. I had two cocoon
> applications that were once running in different JVM instances, both
> mapped to / and I moved them into a single Jetty instance mapped on /A
> and /B (for simplicity).
>
> Then I modified the ProxyPass settings and used the jetty web.xml
> trick to change the cookie path.
What's this "web.xml trick"?
> Now, the interesting thing was that while /A performed just like
> before, /B had a wierd problem: "redirects" were absolute to the
> "webapp server", not to the "web server".
>
> Both apps had the same exact version of cocoon (compiled this morning).
>
> After careful examination and extensive protocol dump, I was able to
> understand that while /A used
>
> cocoon.redirectTo(../../index);
>
> /B used
>
> cocoon.redirectTo(/index);
>
> and both turn up to the in the same position, but while the first
> actually works (the redirect is "remapped" to the original Proxy URL,
> not to the appserver one which is obviously firewalled), the second
> doesn't do remapping and the web application fails because it tries to
> connect to the webapp directly
>
> [actually it's even worse, because it tries to connect to the
> ProxyPass setting, which are http://localhost:8000/ in my case, so it
> tries to connect to *your* machine!]
>
> The interesting thing is that this worked perfectly in the past, when
> both were mapped to /, but I can't tell what broke since I moved them
> *and* change the version of cocoon at the same time.
>
> Did anybody experience a similar behavior?
The explanation is in the servlet spec for
HttpServletResponse.sendRedirect: "If the location is relative with a
leading '/' the container interprets it as relative to the servlet
container root."
Absolute paths don't redirect to the _webapp_ root, but the _servlet
container_ root. This means that redirectTo("/index") produces a
"http://localhost:8000/index" and not a "http://localhost:8000/B/index".
Since the redirect location doesn't start with the ProxyPassReverse URL
prefix, the httpd server sends that location verbatim to the browser.
Et voilà: redirecting to the webapp root cannot be done with an absolute
path.
Sylvain
--
Sylvain Wallez Anyware Technologies
http://www.apache.org/~sylvain http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance - http://www.orixo.com