Bug 31232 - response.encodeURL() not encoding URL when mix of cookies and URL rewriting
Summary: response.encodeURL() not encoding URL when mix of cookies and URL rewriting
Status: RESOLVED WONTFIX
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 5.0.28
Hardware: All All
: P3 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-15 01:16 UTC by Trevor Baker
Modified: 2005-02-16 10:01 UTC (History)
0 users



Attachments
example tomcat instance of this issue. (12.14 KB, application/octet-stream)
2004-09-15 01:17 UTC, Trevor Baker
Details
Patch for issue (431 bytes, patch)
2005-02-16 02:24 UTC, Trevor Baker
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Trevor Baker 2004-09-15 01:16:16 UTC
Setup:
~~~~~~
I have two contexts. The root context allows cookies and the sub context does 
URL rewriting. ie:

<Context path="" docBase="sub" reloadable="true" privileged="false"/>
<Context path="/sub" docBase="sub" cookies="false" reloadable="true" 
privileged="false"/>

In the docBase is only an index.jsp which justs print out the session and 
cookie info and does encodeURL() for the link to the sub context.

If I do:
1) goto http://localhost:8080/index.jsp (uses cookies)
2) goto http://localhost:8080/sub/index.jsp (uses URL rewrite)
3) click on the link which is response.encodeURL("/sub/index.jsp")

Issue:
~~~~~~
I find that the root context's cookie is passed onto the sub context. Because 
of this the encodeURL() doesn't encode the URL for rewriting in the sub 
context. Each time I click on the response.encodeURL("/sub/index.jsp") link a 
new session id is generated each time.

Example:
~~~~~~~~
Request URI = /sub/index.jsp
Session ID = 80A6E1BEC167333A8E05E3588EA0C3A8
Is New = true
Is Valid = false
From Cookie = true
From URL = false

Cookie[0] (from /index.jsp)
getComment() = null
getDomain() = null
getMaxAge() = -1
getName() = JSESSIONID
getPath() = null
getSecure() = false
getValue() = F436A1045778EC9E794449A0192BD406
getVersion() = 0

-------------------------
Because request.isRequestedSessionIdFromCookie() returns true (since the root's 
cookie is passed to the sub context) the URL is not encoded with the sub 
context's session id. 

I've tried this on Windows & Linux, and with IE & Firefox...all produced the 
same results.

I've attached example of this issue.
Comment 1 Trevor Baker 2004-09-15 01:17:00 UTC
Created attachment 12736 [details]
example tomcat instance of this issue.
Comment 2 Yoav Shapira 2004-09-20 18:11:25 UTC
This seems contrived... What's the use-case for it?  I'm just curious, not 
closing this issue at this point.
Comment 3 Trevor Baker 2004-09-20 21:02:38 UTC
Our use case is that our system is half web-based and half applet based. The 
applets communicate with our servlets, setup sessions, redirect users to 
various web pages. All this has to be done through URL rewriting because the 
cookie caches aren't shared between broswer and the applet. This is in the /sub 
context.

Now we have a members section that is cookie based on the root context. We 
tried linking some features of the members section into the applet so it's 
accessible in the applet. But whenever the user goes to the member section all 
access to the /sub is "screwed up" like how I mentioned before: the URL 
rewriting in the sub context doesn't take because of the cookie at the root 
context.

Lets see workaround for us...
1) rewrite our site to use URL rewriting instead of cookies.
2) move members ares to a separate /sub2 context. Can't do that because they 
still access pages from /

--------------------
But use case aside, it just seems like a bug: I specify that the /sub context 
is not to use cookies (force URL rewriting) and it's not using the session ID 
given on the URL because the root context uses cookies. I would it expect it 
use URL rewriting instead of not being able to use anything.

I don't know if there is a spec covering URL-rewriting so I can't refer to 
anything other than it being vendor specific.
Comment 4 Trevor Baker 2004-09-20 21:26:46 UTC
forgot to mention that for the workaround of forcing users to use URL rewriting 
for the members section that this goes back to the usual debate of URL 
rewriting vs. cookies where if the user navigates away from the site and comes 
back then the URL rewritten session is gone.
Comment 5 Yoav Shapira 2004-09-21 19:18:17 UTC
I knew we never should have added the option to disable cookies ;)  The Servlet 
Spec doesn't require containers to provide this option, and it seems to be it 
just leads to bad stuff ;)  But now that we provide it, we have to maintain it 
I suppose.  <sigh />
Comment 6 Yoav Shapira 2004-11-03 17:16:59 UTC
If you want this fixed, submit a patch for it.  I'll be glad to evaluate and 
commit it as needed.  As evidenced by the length of time (nearly 2 months) 
since you submitted this issue, no committers care about it enough to spend 
time investigating/resolving it.
Comment 7 Yoav Shapira 2004-11-17 18:21:01 UTC
Hmm, two weeks since patch request, two months since initial issue.  Please 
reopen this if/when you have a patch ready.  I'll be glad to evaluate and 
commit it then.  Thanks.
Comment 8 Olivier Vit 2005-01-20 14:54:33 UTC
(In reply to comment #6)
> If you want this fixed, submit a patch for it.  I'll be glad to evaluate and 
> commit it as needed.  As evidenced by the length of time (nearly 2 months) 
> since you submitted this issue, no committers care about it enough to spend 
> time investigating/resolving it.

I don't see how commiters are the one that decide in which direction the code
evolves, where it is being fixed or not
It should be driven by someone, or a group of people, acting as 'drivers', based
on how critical are bugs and users requests
This is the only way for the apache group to keep users confidence !
Comment 9 Trevor Baker 2005-02-16 02:24:04 UTC
Created attachment 14294 [details]
Patch for issue

Hey Yoav,

I've got a patch for this. Finally got some time to track it down.

Currently the cookie session ID always overrides the URL session ID, regardless
if the context enables cookies or not.

This patch will check to see if the context enables cookies first. If it does
then the cookie session ID overrides the session ID from the URL. If it does
not then the parseSessionCookieId is skipped completely.
Comment 10 Remy Maucherat 2005-02-16 10:09:28 UTC
I do not agree with this patch in the general case. If a cookie is submitted,
we'll use it.
Comment 11 Trevor Baker 2005-02-16 19:01:55 UTC
(In reply to comment #10)
> I do not agree with this patch in the general case. If a cookie is submitted,
> we'll use it.

I agree with that with one exception. This is not a general case, it's a use
case where the (sub) context disables cookies and is expecting to use URL
rewriting. The presence of the (ROOT) cookie forces a new session on each
request since the URL rewriting is always overriden by the cookie, thus making
the (sub) context unusable.

Mixing cookies and URL rewriting is okay when the ROOT context doesn't use
cookies (ie: /subA uses cookies, and /subB uses URL rewrite). Thought it would
be easier to make the patch since this use case seems like a bug. See my comment
#3 for additional reference.

More workarounds that I thought of are:
* create a host listening on a separate port. However this port may get blocked
by firewalls since it's not port 80.
* setting up a separate domain and use URL rewriting just in that domain.
* don't use cookies at all. Not my favorite.

I just don't want other people to experience the trouble that I had.

If the decision is still a WONTFIX, then please add a note in the docs for the
cookies attribute for Context that URL rewriting won't work for sub contexts if
the ROOT context uses cookies.

thanks.