New issue
Advanced search Search tips

Issue 749833 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Jul 2017
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment

http session not passed to websocket ws when before using wss

Reported by michael....@googlemail.com, Jul 27 2017

Issue description

UserAgent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36

Steps to reproduce the problem:
1. Setup a webserver which serves https and http
2. Setup a test case as attached (see README.txt inside)
3. Open Chrome, request the https resource, afterwards request the http resource. Watch the tomcat console, httpSession is reported to be null! 
4. If you first request http, then https and again http, it works fine (then http has http-session not null).

What is the expected behavior?
The httpSession object in case of http should be not null.
But every reload of the http case, the http session is null. Only if you close and open the browser, then navigate to http, it is ok (not null).

What went wrong?
I assume that the http session object is not passed correctly to the websocket in case first https, then http.

Did this work before? N/A 

Does this work in other browsers? N/A

Chrome version: 60.0.3112.78  Channel: stable
OS Version: 6.1 (Windows 7, Windows Server 2008 R2)
Flash Version: 

Does this feature work correctly in other browsers?
- It works correctly in MSIE 11.
- In Firefox same problem as in Chrome.
 
https2http.zip
7.9 KB Download
Labels: Needs-Triage-M60
Components: Internals>Network>HTTP
Labels: TE-NeedsTriageHelp

Comment 3 by mmenke@chromium.org, Jul 28 2017

Components: -Internals>Network>HTTP Blink>Network>WebSockets
Nothing to do with HTTP...At least I assume "httpSession" is a websocket concept.

Comment 4 by ricea@chromium.org, Jul 28 2017

I assume that httpSession is a variable inside Tomcat? The fact that it also doesn't work in Firefox implies that there something wrong with Tomcat rather than something wrong with Chrome.

If you capture a Netlog dump as described in https://dev.chromium.org/for-testers/providing-network-details I will take a look at it. Actually, it would be better to capture two separate logs, https -> http and then http -> https in a fresh browser session. However, it is highly likely that whatever is happening is internal to Tomcat and the log won't contain anything unusual.
httpSession is the variable in my testcase.
I retrieve the javax.servlet.http.HttpSession from the
javax.websocket.server.HandshakeRequest.

For sure I will give it a try with jetty instead of tomcat and report here.
Unfortunately jetty does not pass the httpsession in the
javax.websocket.server.HandshakeRequest object (in jsr356 implementation).
Can you point me to another container which I could use for this test?

So I have created (for tomcat as container) Netlog dumps as requested, see attached 3 files.
chrome-net-export-log-http-ok.json
104 KB View Download
chrome-net-export-log-https-ok.json
124 KB View Download
chrome-net-export-log-http-notok.json
135 KB View Download
I reported this now as Tomcat Bug (#61360) with reference to here.
Let's see if Tomcat developer are able to locate the problem.
Here the answer from Tomcat developer Mark Thomas <markt@apache.org>:

This is as a result of user agent behaviour.

Tomcat marks the session cookie for sessions created under https as secure.
This ensures that user agents do not send session IDs for secure sessions over
http.

In the http->https case
- The first request creates a session and sets a non-secure session cookie
- The browser sends this session cookie with the ws request
- The second request continues to use the session cookie because sending a
non-secure cookie over https is allowed
- The wss request uses the non-secure session cookie for the same reason

In the https->http case
- The first request creates a session and sets a secure session cookie
- The browser sends this session cookie with the wss request (since secure
cookies can be sent with https requests)
- The second request continues does not use the session cookie because sending
a secure cookie over http is not allowed. Tomcat creates a new session and
sends the user agent a non-secure cookie for that session
- The user agent ignores this cookie (I'm guessing so that it doesn't
over-write the secure one in case of a switch back to https)
- The ws request is also sent without a session cookie. Hence the WebSocket
handshake does not see a session.

Comment 9 by ricea@chromium.org, Jul 31 2017

Status: WontFix (was: Unconfirmed)
> - The user agent ignores this cookie (I'm guessing so that it doesn't
over-write the secure one in case of a switch back to https)

This is correct. If insecure cookies could overwrite secure ones it would be a security hole, so it is prevented. I had forgotten about this aspect.

Sorry, but Chrome is working as intended here. My advice would be to always use wss:. If you can't do that, then try to use a different name for the cookie depending on whether it is a secure or insecure connection.

Sign in to add a comment