You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Brian McBride <bw...@googlemail.com> on 2010/09/14 11:40:51 UTC
HtttServletRequest.getSession()
The javadoc states this call returns the "session associated with the
request". I'm trying to figure out what "the session associated with
the request" actually means.
Specifically, if I have the same client sending https and http requests
intermixed in time, will there be two sessions objects, one for the
secure requests and one for the insecure ones, or just one.
And, if there are two is this documented anywhere?
Brian
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: HtttServletRequest.getSession()
Posted by Brian McBride <bw...@googlemail.com>.
Hi Christopher,
On 14/09/2010 16:02, Christopher Schultz wrote:
[...]
> I'm not sure what you're asking. "The session" refers to an HttpSession
> object, which should be obvious from the spec and the API itself. "The
> request" should also be obvious, since we're talking about HTTP and a
> HttpServletRequest object. The only question is what "associated" means.
Yup.
> This is pretty much entirely up to the client:
Finally, the penny drops. Of course it is.
Thanks
Brian
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: HtttServletRequest.getSession()
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Brian,
On 9/14/2010 9:51 AM, Brian McBride wrote:
> https request: get session returns ?
Heh. I should have read your question before I posted my own.
> i.e. will the newly created session B replace session A, or will A
> continue to be returned for https requests? I suspect it will return B,
> on the assumption the client does not store separate JSESSIONIDs for
> secure and insecure channels, but I'm not sure.
The client may differentiate between secure and non-secure cookies.
(I'll have to double-check that with the spec).
> I just had another extensive search and failed to find what I'm looking
> for. One might think that section SRV.7.2 Creating a Session might
> cover it, but it doesn't and nor does any of SRV.7, the section on
> Sessions, that I have found. The APIs define the result of the
> getSession() to be the "session associated with" this request. A text
> search for "session associated with" finds nothing useful.
I'm not sure what you're asking. "The session" refers to an HttpSession
object, which should be obvious from the spec and the API itself. "The
request" should also be obvious, since we're talking about HTTP and a
HttpServletRequest object. The only question is what "associated" means.
This is pretty much entirely up to the client: either the client
provides a JSESSIONID cookie, provides a jsessionid URL parameter, or
provides nothing. In the first two cases, the session id is used to
associate the request with an HttpSession. In the latter case, there is
no session associated with the request. It's also possible that the
provided session id is not valid, in which case there is also no session
associated with the request.
If you call HttpServletRequest.getSession(true) and a session must be
created, then that newly-created HttpSession object becomes the session
associated with the request.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkyPjpYACgkQ9CaO5/Lv0PBGHgCeIcRPMgctGxEfeN+dY/ObIylI
qMAAn1heka97qvTzM+47U68zD/YmHyLZ
=B9aZ
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: HtttServletRequest.getSession()
Posted by Brian McBride <bw...@googlemail.com>.
Hi Mark,
Thanks for this. I didn't quite fully grock your reply. Given:
https request: get session returns session A.
https request: get session returns session A.
http request: get session (no create) returns null
http request: get session(create) returns session B != A.
https request: get session returns ?
i.e. will the newly created session B replace session A, or will A
continue to be returned for https requests? I suspect it will return B,
on the assumption the client does not store separate JSESSIONIDs for
secure and insecure channels, but I'm not sure.
And yes I have read the servlet specs - it is frustrating that I can't
seem to find what I'm looking for in them. I'm not blaming the specs
for that - I'm responsible.
I just had another extensive search and failed to find what I'm looking
for. One might think that section SRV.7.2 Creating a Session might
cover it, but it doesn't and nor does any of SRV.7, the section on
Sessions, that I have found. The APIs define the result of the
getSession() to be the "session associated with" this request. A text
search for "session associated with" finds nothing useful.
If you or anyone can narrow down where I should look for the
specification of the behaviour you describe, I'd be most grateful.
Brian
On 14/09/2010 12:55, Mark Thomas wrote:
> On 14/09/2010 10:40, Brian McBride wrote:
>> The javadoc states this call returns the "session associated with the
>> request". I'm trying to figure out what "the session associated with
>> the request" actually means.
>>
>> Specifically, if I have the same client sending https and http requests
>> intermixed in time, will there be two sessions objects, one for the
>> secure requests and one for the insecure ones, or just one.
> It depends where the session is created. Sessions created under http
> should transition to https (and back) without a problem. If you create
> the session under https then the session will not transition to http.
> The next http request will trigger a new session to be created.
>
>> And, if there are two is this documented anywhere?
> Have you read the Servlet specs?
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: HtttServletRequest.getSession()
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
André,
Thanks for further investigation. Comments, as always, are below.
On 9/14/2010 6:17 PM, André Warnier wrote:
> 3.3.3 Cookie Management If a user agent receives a Set-Cookie2
> response header whose NAME is the same as that of a cookie it has
> previously stored, the new cookie supersedes the old when: the old
> and new Domain attribute values compare equal, using a case-
> insensitive string-compare; and, the old and new Path attribute
> values string-compare equal (case-sensitive).
This was the business I was looking for.
> Personal interpretation, inasmuch as necessary :
>
> Neither the "Port" nor the "Secure" attributes are "identifiers" of the
> cookie; 2 cookies which have the same name and domain and path, but
> different "Port" and/or "Secure" attributes, are the same cookie, and
> one overwrites the other.
Exactly.
> So a browser should never return 2 cookies with the same name and path,
> with a request to the same host.
Well, the browser doesn't have to report the path to the server when
sending a request. It is still (definitely!) possible to get more than
one cookie with the same name yet different values sent to the server.
Believe me, I've seen it happen and had to fix my nested web application
paths to prevent that (self-inflicted) stupidity from interfering with
my webapp's operation.
> 2. If the attribute is present but has no value (e.g., Port), the
> cookie MUST only be sent to the request-port it was received
> from.
That's interesting: "use the current port" without being explicit.
> An interesting question is still this :
> if a server sends 2 cookies to a browser, with the same name and path,
> but a diffrent domain : cookie 1 has a domain "myhost.mycompany.com",
> and cookie 2 a domain of ".company.com".
>
> According to what I understand, the browser should cache both cookie
> separately, as they differ by the domain attribute.
> But should the browser return both cookies with the next request to the
> same host ?
Yup!
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkyQ2WMACgkQ9CaO5/Lv0PCmXACdG6D9F4jA56CO/rvm+Tvkw0Aq
nd4AoL34edqdOzOZktdM4YGXez0JkiNQ
=VByq
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: HttttServletRequest.getSession()
Posted by Pid <pi...@pidster.com>.
On 17/09/2010 18:02, Christopher Schultz wrote:
> Brian,
>
> On 9/17/2010 7:00 AM, Brian McBride wrote:
>> My interpretation is still that 2109 defines the
>> behaviour of Set-Cookie and 2965 that of Set-Cookie2 and that the intent
>> was that Set-Cookie2 should obsolete Set-Cookie, i.e. 2109 still defines
>> the behaviour of Set-Cookie.
>
> +1
>
> That's the beauty of backward-compatibility, market inertia, and and the
> never-ending string of RFCs you have to read to figure out just what the
> hell is really going on.
>
>> I presume the behaviour of
>> Set-Cookie2 is not backwards compatible with that of Set-Cookie and
>> hence the introduction of a new header.
+1
p
(I just wanted to add another 't' really)
Re: HtttServletRequest.getSession()
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Brian,
On 9/17/2010 7:00 AM, Brian McBride wrote:
> My interpretation is still that 2109 defines the
> behaviour of Set-Cookie and 2965 that of Set-Cookie2 and that the intent
> was that Set-Cookie2 should obsolete Set-Cookie, i.e. 2109 still defines
> the behaviour of Set-Cookie.
+1
That's the beauty of backward-compatibility, market inertia, and and the
never-ending string of RFCs you have to read to figure out just what the
hell is really going on.
> I presume the behaviour of
> Set-Cookie2 is not backwards compatible with that of Set-Cookie and
> hence the introduction of a new header.
Exactly.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkyTnycACgkQ9CaO5/Lv0PA3+ACfXRVr0xsEiXUMRE0UAH1j6dEy
FlwAn1pQMNHfGkI9NKJKQH/uUgmXkacB
=XI/U
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: HtttServletRequest.getSession()
Posted by Brian McBride <bw...@googlemail.com>.
On 16/09/2010 15:50, André Warnier wrote:
[...]
>> RFC 2965 does not say that it overrides the older RFC 2109.
>
> It does, at the end of the Abstract :
>
> This document reflects implementation experience with RFC 2109 and
> obsoletes it.
I missed that. My interpretation is still that 2109 defines the
behaviour of Set-Cookie and 2965 that of Set-Cookie2 and that the intent
was that Set-Cookie2 should obsolete Set-Cookie, i.e. 2109 still defines
the behaviour of Set-Cookie. However, I am inexperienced in these
matters and may reading that wrong. I presume the behaviour of
Set-Cookie2 is not backwards compatible with that of Set-Cookie and
hence the introduction of a new header.
[...]
>> So I guess, strictly speaking, no user agent sending secure cookies
>> over an insecure channel is actually in violation of the RFC :(
>>
> Strictly speaking, probably not. But I would say that it violates the
> spirit of RFC 2965.
And 2109. I would guess the extra text was added to 2965 because such
violations occurred.
>
>> Is there a way to persuade Tomcat to use Set-Cookie2 headers?
>
> That last, I don't know (except from adding the header yourself of
> course).
>
> Generically, RFCs are written by the people most competent in the
> domain they are talking about, and reviewed by other competent
> people. They tend to make sense.
> That does not mean that there is not from time to time an omission or
> a contradiction.
> But in any case, RFCs are the best we have in terms of "standards of
> interoperability" on the Internet.
> And a general - but often unwritten - principle is : be strict in what
> you emit, and tolerant in what you receive.
Just so.
[...]
> About the behaviour you are seeing with httpunit, in view of the
> cumulative interpretation of RFC 2109 and 2695, my view would be that
> this is sloppy behaviour of httpunit (but maybe that is the point,
> since it is a testing tool ?).
I'm not blaming httpunit yet. My client library will use URLConnection
straight. It's possible, but unlikely, that this behaviour is in the
underlying java.net code. I should find out later today.
> But then also, you did not say if the cookie sent over HTTPS was
> marked "secure" (inasmuch as this attribute exists for a Set-Cookie
> header; I have not checked).
> If it was, and httpunit sends it back over a non-secure connection,
> then I definitely think it's sloppy. If it wasn't, then my reading is
> that the server should know that if it does not mark the cookie as
> "secure", a user agent is entitled to consider that the cookie
> contains no sensitive information, and to do with it what it wants.
>
> Now one more thing :
> "> I'm using httpunit for testing. I observe it receiving a new
> JSESSIONID
> > cookie over SSL and immediately sending it back over on open
> connection.
> >
> "
> Which means that you have a Tomcat-based application of which part
> happens under HTTPS, and part over normal HTTP.
Yes.
> I personally find this iffy. If you are going through the burden of
> setting up HTTPS, then why not run the entire session under HTTPS ?
> If your login data is sensitive, then surely it is because what you
> are going to exchange as data afterward is sensitive also, no ?
Yes and no. Some of my resources are sensitive and some are public, and
which is which can vary over time. I could still give access to public
data over https, but I was trying to avoid that:
1) I publish URLs and don't want them to be https URLs; if its a secured
resource I redirect to the https url.
2) I wanted to try to avoid the processing overhead of SSL for public
resources.
The system has the potential to get quite big, so I don't want to build
in unnecessary overheads. If we are successful, then public data will
be a large part of the traffic.
> And if you relying on the fact that a JSESSIONID cookie received by
> the browser under a HTTPS connection, will be resent by the browser on
> a non-HTTPS connection,
I'm not. At present I don't need any session state for unsecured
access. If I end up needing such session state, I'll set up an
unsecured JSESSIONID cookie. I am not relying on the JSESSIONID being
secret. I am associating an authenticated data with an SSL session not
with the tomcat session. Only requests over an authenticated SSL
session are considered authenticated. This may not work - depends on
how long SSL sessions stay around. I think I'm OK, but I need to build
it to find out - unless someone who has already tried it tells me it
doesn't work.
I really appreciate your taking the time to share your thoughts and advice.
Brian
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: HtttServletRequest.getSession()
Posted by André Warnier <aw...@ice-sa.com>.
Brian McBride wrote:
> On 14/09/2010 23:17, André Warnier wrote:
> [...]
>
>> Personal interpretation : if the browser receives a cookie marked
>> "secure", it should only send it back with requests happening over an
>> HTTPS connection.
>> (No matter if it was received over HTTP or HTTPS).
> I'm using httpunit for testing. I observe it receiving a new JSESSIONID
> cookie over SSL and immediately sending it back over on open connection.
>
See generic comment at end.
...
>
> RFC 2965 does not say that it overrides the older RFC 2109.
It does, at the end of the Abstract :
This document reflects implementation experience with RFC 2109 and
obsoletes it.
And, both RFCs are written by the same authors.
My
> interpretation is that a user agent can follow RFC 2109 for Set-Cookie
> headers, and possibly should. My Tomcat is sending Set-Cookie headers,
> not Set-Cookie2 headers.
>
> The text in RFC 2109 for the secure attibute is different to that in RFC
> 2965:
>
...
>
> Note that the text about not sending a cookie received over a channel
> back over a less secure one is omitted.
Considering that the authors seem to want to obsolete RFC 2109 with RFC 2965, I would thus
say that the previous omission in RFC 2109 has been corrected in RFC 2965, and not the
other way around.
>
> So I guess, strictly speaking, no user agent sending secure cookies
> over an insecure channel is actually in violation of the RFC :(
>
Strictly speaking, probably not. But I would say that it violates the spirit of RFC 2965.
> Is there a way to persuade Tomcat to use Set-Cookie2 headers?
That last, I don't know (except from adding the header yourself of course).
Generically, RFCs are written by the people most competent in the domain they are talking
about, and reviewed by other competent people. They tend to make sense.
That does not mean that there is not from time to time an omission or a contradiction.
But in any case, RFCs are the best we have in terms of "standards of interoperability" on
the Internet.
And a general - but often unwritten - principle is : be strict in what you emit, and
tolerant in what you receive.
So my personal tendency, when I develop something Internet-wise, is to do it according to
the strictest (personal) interpretation of the latest version of an RFC. In other words,
to follow the MUST's and SHOULD's. Then on a second pass, I would look at the MAY's, to
make the code, possibly, tolerant of the other side's interpretation of the RFC.
And then I will test this in the real world, and try to find out all the kinks that happen
with various IE versions (always a good test of server code tolerance), and see if that
can be compensated for in a way that makes sense.
Of course that never catches everything that users may and will throw at you, so it is a
recursive process.
And, let's face it : since 95% of corporate users still use one or the other version of
IE, as developers we have not much choice but to accept what it throws at us and code
around it. (On the positive side, it is also a very convenient scapegoat when you make a
booboo and have to explain it to a customer; nobody ever questions the existence of bugs
in IE anymore).
About the behaviour you are seeing with httpunit, in view of the cumulative interpretation
of RFC 2109 and 2695, my view would be that this is sloppy behaviour of httpunit (but
maybe that is the point, since it is a testing tool ?).
But then also, you did not say if the cookie sent over HTTPS was marked "secure" (inasmuch
as this attribute exists for a Set-Cookie header; I have not checked).
If it was, and httpunit sends it back over a non-secure connection, then I definitely
think it's sloppy. If it wasn't, then my reading is that the server should know that if
it does not mark the cookie as "secure", a user agent is entitled to consider that the
cookie contains no sensitive information, and to do with it what it wants.
Now one more thing :
"> I'm using httpunit for testing. I observe it receiving a new JSESSIONID
> cookie over SSL and immediately sending it back over on open connection.
>
"
Which means that you have a Tomcat-based application of which part happens under HTTPS,
and part over normal HTTP. I personally find this iffy. If you are going through the
burden of setting up HTTPS, then why not run the entire session under HTTPS ?
If your login data is sensitive, then surely it is because what you are going to exchange
as data afterward is sensitive also, no ?
And if you relying on the fact that a JSESSIONID cookie received by the browser under a
HTTPS connection, will be resent by the browser on a non-HTTPS connection, then in my view
you are exposing yourself to some next browser version which will have a stricter
interpretation of these RFCs, and not send it anymore.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: HtttServletRequest.getSession()
Posted by Mark Thomas <ma...@apache.org>.
On 16/09/2010 14:46, Joseph Morgan wrote:
> Mark... on that thought, Java 1.5+ has the java.net.CookieHandler class... is there a way to insert a CookieHandler into Tomcat???
Not without writing some custom code to replace some of Tomcat's internals.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: HtttServletRequest.getSession()
Posted by Joseph Morgan <jo...@ignitesales.com>.
Mark... on that thought, Java 1.5+ has the java.net.CookieHandler class... is there a way to insert a CookieHandler into Tomcat???
-----Original Message-----
From: Mark Thomas [mailto:markt@apache.org]
Sent: Thursday, September 16, 2010 8:26 AM
To: Tomcat Users List
Subject: Re: HtttServletRequest.getSession()
On 16/09/2010 13:49, Brian McBride wrote:
> Is there a way to persuade Tomcat to use Set-Cookie2 headers?
Not though the Servlet API. The servlet spec references v0 and v1
cookies but not the v2 spec.
Given the IE doesn't even fully implement the v1 cookie spec, I would
estimate the chances of it being spec compliant with v2 cookies
somewhere rather close to zero. IE's user base may be declining but it
is still a very large percentage.
It may be possible to implement some form of custom extension but doing
that without touching any of the javax.servlet classes would be tricky
at best (and we can't touch them since that would break the spec).
Your best bet may be to just set the cookie header manually. That won't
help with session cookies since Tomcat creates those.
Lobbying the Servlet EG has been known to get the spec changed if a
strong argument is presented (eg httpOnly support in cookies).
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: HtttServletRequest.getSession()
Posted by Mark Thomas <ma...@apache.org>.
On 16/09/2010 13:49, Brian McBride wrote:
> Is there a way to persuade Tomcat to use Set-Cookie2 headers?
Not though the Servlet API. The servlet spec references v0 and v1
cookies but not the v2 spec.
Given the IE doesn't even fully implement the v1 cookie spec, I would
estimate the chances of it being spec compliant with v2 cookies
somewhere rather close to zero. IE's user base may be declining but it
is still a very large percentage.
It may be possible to implement some form of custom extension but doing
that without touching any of the javax.servlet classes would be tricky
at best (and we can't touch them since that would break the spec).
Your best bet may be to just set the cookie header manually. That won't
help with session cookies since Tomcat creates those.
Lobbying the Servlet EG has been known to get the spec changed if a
strong argument is presented (eg httpOnly support in cookies).
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: HtttServletRequest.getSession()
Posted by Brian McBride <bw...@googlemail.com>.
On 14/09/2010 23:17, André Warnier wrote:
[...]
> Personal interpretation : if the browser receives a cookie marked
> "secure", it should only send it back with requests happening over an
> HTTPS connection.
> (No matter if it was received over HTTP or HTTPS).
I'm using httpunit for testing. I observe it receiving a new JSESSIONID
cookie over SSL and immediately sending it back over on open connection.
The text you quote is from RFC 2965. My inexpert reading is that it
specifies the behaviour for Set-Cookie2 headers. It includes:
[[
Older user agents that do not understand this specification, but that do
understand Netscape's original specification, will not recognize the
Set-Cookie2 response header and will receive and send cookies according
to the older specification.
]]
RFC 2965 does not say that it overrides the older RFC 2109. My
interpretation is that a user agent can follow RFC 2109 for Set-Cookie
headers, and possibly should. My Tomcat is sending Set-Cookie headers,
not Set-Cookie2 headers.
The text in RFC 2109 for the secure attibute is different to that in RFC
2965:
[[
Optional. The Secure attribute (with no value) directs the user
agent to use only (unspecified) secure means to contact the origin
server whenever it sends back this cookie.
The user agent (possibly under the user's control) may determine
what level of security it considers appropriate for "secure"
cookies. The Secure attribute should be considered security
advice from the server to the user agent, indicating that it is in
the session's interest to protect the cookie contents.
]]
Note that the text about not sending a cookie received over a channel
back over a less secure one is omitted.
So I guess, strictly speaking, no user agent sending secure cookies
over an insecure channel is actually in violation of the RFC :(
Is there a way to persuade Tomcat to use Set-Cookie2 headers?
Brian
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: HtttServletRequest.getSession()
Posted by André Warnier <aw...@ice-sa.com>.
Mark Thomas wrote:
> On 14/09/2010 15:16, Christopher Schultz wrote:
>
> I'm in the middle of some major re-factoring so I don;t have time to
> actually test this...
>
>> 0. [Browser has two JSESSIONID cookies: one secure=true and one
>> secure=false]
>
> This I doubt. When testing load-balancing on a single machine, I have
> seen browsers send the same cookie to two Tomcat instances that only
> differ by port number. I suspect https and http will be treated the same
> way and one cookie will just overwrite the other. You should test that
> to be sure though.
>
>> 1. Browser makes an HTTPS connection to the server and sends both cookies
>> 2. Application code calls request.getSession()
>
> Assuming browsers behave the way I think they will, this should be a
> non-issue. If they don't it will get 'interesting'. Either way you'll
> need to experiment to be sure.
>
RFC 2965 HTTP State Management Mechanism October 2000
...
Secure
OPTIONAL. The Secure attribute (with no value) directs the user
agent to use only (unspecified) secure means to contact the origin
server whenever it sends back this cookie, to protect the
confidentially and authenticity of the information in the cookie.
The user agent (possibly with user interaction) MAY determine what
level of security it considers appropriate for "secure" cookies.
The Secure attribute should be considered security advice from the
server to the user agent, indicating that it is in the session's
interest to protect the cookie contents. When it sends a "secure"
cookie back to a server, the user agent SHOULD use no less than
the same level of security as was used when it received the cookie
from the server.
Personal interpretation : if the browser receives a cookie marked "secure", it should only
send it back with requests happening over an HTTPS connection.
(No matter if it was received over HTTP or HTTPS).
Page 8 :
...
Port The default behavior is that a cookie MAY be returned to any
request-port.
Personal interpretation : if the "Port" attribute is not specified, the browser may return
this cookie on any port; if the port attribute is specified, then it may only return this
cookie with requests made over a connection to one of the listed ports.
on page 9 :
3.3.3 Cookie Management If a user agent receives a Set-Cookie2
response header whose NAME is the same as that of a cookie it has
previously stored, the new cookie supersedes the old when: the old
and new Domain attribute values compare equal, using a case-
insensitive string-compare; and, the old and new Path attribute
values string-compare equal (case-sensitive).
Personal interpretation, inasmuch as necessary :
Neither the "Port" nor the "Secure" attributes are "identifiers" of the cookie; 2 cookies
which have the same name and domain and path, but different "Port" and/or "Secure"
attributes, are the same cookie, and one overwrites the other.
So a browser should never return 2 cookies with the same name and path, with a request to
the same host.
It is even clearer on page 11 :
The user agent applies the following rules to choose applicable
cookie-values to send in Cookie request headers from among all the
cookies it has received.
Domain Selection
The origin server's effective host name MUST domain-match the
Domain attribute of the cookie.
Port Selection
There are three possible behaviors, depending on the Port
attribute in the Set-Cookie2 response header:
1. By default (no Port attribute), the cookie MAY be sent to any
port.
2. If the attribute is present but has no value (e.g., Port), the
cookie MUST only be sent to the request-port it was received
from.
3. If the attribute has a port-list, the cookie MUST only be
returned if the new request-port is one of those listed in
port-list.
Path Selection
The request-URI MUST path-match the Path attribute of the cookie.
An interesting question is still this :
if a server sends 2 cookies to a browser, with the same name and path, but a diffrent
domain : cookie 1 has a domain "myhost.mycompany.com", and cookie 2 a domain of
".company.com".
According to what I understand, the browser should cache both cookie separately, as they
differ by the domain attribute.
But should the browser return both cookies with the next request to the same host ?
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: HttpServletRequest.getSession()
Posted by Mark Thomas <ma...@apache.org>.
On 14/09/2010 21:54, Christopher Schultz wrote:
> I encourage others to test other browsers. This was exhausting. :)
To add to the 'fun', recent Tomcat versions will change the session ID
(but not the session object) on authentication to prevent session
fixation attacks.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: HttpServletRequest.getSession()
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Mark,
On 9/14/2010 12:30 PM, Mark Thomas wrote:
> On 14/09/2010 15:16, Christopher Schultz wrote:
>
> I'm in the middle of some major re-factoring so I don;t have time to
> actually test this...
>
>> 0. [Browser has two JSESSIONID cookies: one secure=true and one
>> secure=false]
>
> This I doubt. When testing load-balancing on a single machine, I have
> seen browsers send the same cookie to two Tomcat instances that only
> differ by port number. I suspect https and http will be treated the same
> way and one cookie will just overwrite the other. You should test that
> to be sure though.
Okay, I'll check. I believe that "version 0" cookies should overwrite
each other when the port numbers are different, but that "version 1"
cookies allow a port specification that should allow two cookies with
the same name and path, but different numbers, to exist side-by-side
with no interference.
I just checked, and RFC 2109 ("version 0" cookies) does seem to indicate
that the port number adds to the unique-ness of the hostname, therefore
my statement above appears to be incorrect. It's possible that web
browser were (at some point) lazy and I am remembering a bad cookie
implementation.
The Set-Cookie2 definitely has a "port" parameter that can be explicitly
added to the cookie's settings.
Regarding the "Secure" flag, this is all the RFC has to say about it:
"
Secure If absent, the user agent MAY send the cookie over an
insecure channel.
"
That indicates to me that non-secure cookies should be sent as well as
secure cookies, but doesn't say if they overwrite each other. I didn't
read every word of the RFC, but from what I did read, this appears to be
a gray area where the browser would be left to either support separate
secure/non-secure cookies or clobber one with the other.
References
http://www.ietf.org/rfc/rfc2109.txt
and
http://www.ietf.org/rfc/rfc2965.txt
(This information was mostly for the edification of other readers, not a
lesson in HTTP RFCs for markt ;)
Here's what I observe in Tomcat 6.0.26 with Mozilla Firefox 3.6.9/win32:
[non-secure]
1. Attempt to access protected page, request includes JSESSIONID cookie
(old value, no valid session)
2. Server responds with 302 redirect to login page, Set-Cookie for
JSESSIONID, path=/mywebapp
3. Submit authentication information, including JSESSIONID from step 2
4. Server accepts credentials, issues 302 response, no Set-Cookie header
5. Client follows redirect, including JSESSIONID from step 2
[secure, immediately after steps 1-5 above]
6. Attempt to access protected page, request includes JSESSIONID from step 2
7. Access is granted, page is displayed
8. Request "logout", request includes JSESSIONID from step 2
9. Server terminates HttpSession, no Set-Cookie header in response
10. Attempt to access protected page, request includes JSESSIONID from
step 2
11. Session is invalid, server responds with 302 redirect to login page,
Set-Cookie header with new JSESSIONID cookie value AND SECURE FLAG SET
12. Client follows redirect, includes JSESSIONID from step 11
13. Submit authentication information, including JSESSIONID from step 11
14. Server accepts credentials, issues 302 response, no Set-Cookie header
15. Client follow redirect, including JSESSIONID from step 11
[non-secure, immediately after steps 6-15 above]
16. Attempt to access protected resource, request does not include
JSESSIONID cookie at all
17. Server responds with 302 redirect to login page, Set-Cookie for
JSESSIONID, path=/mywebapp
18. Submit authentication information, includes JSESSIONID FROM step 17
19. Server accepts credentials, issues 302 redirect
20. Client follows redirect, including JSESSIONID from step 17
[secure, immediately after steps 6-15 above]
21. Attempt to access protected resource, request includes JSESSIONID
cookie from step 17
So, it appears that the non-secure cookie trumps the secure cookie and
the client (Firefox, at least) will clobber secure with non-secure.
I encourage others to test other browsers. This was exhausting. :)
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkyP4QcACgkQ9CaO5/Lv0PBS3wCeLHzEbJew0T2/I/VFTonga84m
5VQAoJx4RQhmPDmr74E79ocGvnJPVZ2N
=aOIa
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: HtttServletRequest.getSession()
Posted by Mark Thomas <ma...@apache.org>.
On 14/09/2010 15:16, Christopher Schultz wrote:
I'm in the middle of some major re-factoring so I don;t have time to
actually test this...
> 0. [Browser has two JSESSIONID cookies: one secure=true and one
> secure=false]
This I doubt. When testing load-balancing on a single machine, I have
seen browsers send the same cookie to two Tomcat instances that only
differ by port number. I suspect https and http will be treated the same
way and one cookie will just overwrite the other. You should test that
to be sure though.
> 1. Browser makes an HTTPS connection to the server and sends both cookies
> 2. Application code calls request.getSession()
Assuming browsers behave the way I think they will, this should be a
non-issue. If they don't it will get 'interesting'. Either way you'll
need to experiment to be sure.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: HtttServletRequest.getSession()
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Mark,
On 9/14/2010 7:55 AM, Mark Thomas wrote:
> On 14/09/2010 10:40, Brian McBride wrote:
>> The javadoc states this call returns the "session associated with the
>> request". I'm trying to figure out what "the session associated with
>> the request" actually means.
>>
>> Specifically, if I have the same client sending https and http requests
>> intermixed in time, will there be two sessions objects, one for the
>> secure requests and one for the insecure ones, or just one.
>
> It depends where the session is created. Sessions created under http
> should transition to https (and back) without a problem. If you create
> the session under https then the session will not transition to http.
> The next http request will trigger a new session to be created.
Just for my own edification, consider the above scenario, and then
follow these steps:
0. [Browser has two JSESSIONID cookies: one secure=true and one
secure=false]
1. Browser makes an HTTPS connection to the server and sends both cookies
2. Application code calls request.getSession()
Which cookie does Tomcat end up using? My experience with Tomcat and
foolish JSESSIONID cookie handling (a big mistake in the past with
nested URL spaces and proxied session ids) taught me that Tomcat will
take the JSESSIONID cookies from the request and try them all: the first
one that is valid wins.
Does this mean that the session chosen during step #2 above is entirely
dependent upon the order in which the client sends the JSESSIONID
cookies? Or, does Tomcat prefer the HTTPS one when in HTTPS mode?
I'd read the code, but I have forgotten where that code was when I read
it long ago. (*ducks*)
Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkyPg6QACgkQ9CaO5/Lv0PCzTgCeNzvKvdaLw6wGDcE+NXYMd5XM
b/sAnitcE4twHuaC41qfgV0R6xazv3rB
=ponm
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: HtttServletRequest.getSession()
Posted by Mark Thomas <ma...@apache.org>.
On 14/09/2010 10:40, Brian McBride wrote:
> The javadoc states this call returns the "session associated with the
> request". I'm trying to figure out what "the session associated with
> the request" actually means.
>
> Specifically, if I have the same client sending https and http requests
> intermixed in time, will there be two sessions objects, one for the
> secure requests and one for the insecure ones, or just one.
It depends where the session is created. Sessions created under http
should transition to https (and back) without a problem. If you create
the session under https then the session will not transition to http.
The next http request will trigger a new session to be created.
> And, if there are two is this documented anywhere?
Have you read the Servlet specs?
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org