Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session ID is not unique anymore #526

Closed
haizz opened this issue Mar 13, 2018 · 13 comments
Closed

Session ID is not unique anymore #526

haizz opened this issue Mar 13, 2018 · 13 comments
Labels
Milestone

Comments

@haizz
Copy link

haizz commented Mar 13, 2018

All opened tabs in the browser share the same session id because of the change in #505
This breaks all the code which differentiates connections by their ids.
This is extremely critical.

@haizz
Copy link
Author

haizz commented Mar 13, 2018

I had to revert to 1.7.13 because 1.7.14 is basically broken.

@mrniko
Copy link
Owner

mrniko commented Mar 13, 2018

Could you suggest a change?

@haizz
Copy link
Author

haizz commented Mar 13, 2018

Yes, please restore the old behavior.

@haizz
Copy link
Author

haizz commented Mar 13, 2018

This breaks even internal netty-socketio code, like joinRoom functionality which is supposed to be isolated for each connection:

@mrniko mrniko added this to the 1.7.15 milestone Mar 13, 2018
@AlexMl
Copy link
Contributor

AlexMl commented Mar 17, 2018

Now I know why our web connections are so messed up.

@moocat
Copy link

moocat commented May 5, 2018

The rooms functionality is completely broken due to this.

Java 10 also does a " An illegal reflective access operation has occurred" for previous versions, so I would love to be able to use the up-to-date versions without rooms being broken like this.

@Crimscent
Copy link

Crimscent commented May 8, 2018

@mrniko, please restore the old behavior, it just breaks everything:

  • multiple tabs share the same session and PONG messages go randomly to only one tab resulting in reconnect;
  • messages from server are delivered only to one tab randomly;
  • etc.

As a result we can't use this server implementation in our projects.

Reference code from latest 1.x nodejs engine.io 1.8.4 (which is used by socket.io 1.7.4):

Server.prototype.handshake = function (transportName, req) {
  var id = this.generateId(req);
  ...
  if (false !== this.cookie) {
    transport.on('headers', function (headers) {
      headers['Set-Cookie'] = cookieMod.serialize(self.cookie, id,
        {
          path: self.cookiePath,
          httpOnly: self.cookiePath ? self.cookieHttpOnly : false
        });
    });
  }
  ...
};

Server.prototype.generateId = function (req) {
  return base64id.generateId();
};

Suggested change:

public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Disconnectable {
    ...
    private boolean authorize(ChannelHandlerContext ctx, Channel channel, String origin, Map<String, List<String>> params, FullHttpRequest req)
            throws IOException {
        ...
        // remove next line
        // UUID sessionId = this.generateOrGetSessionIdFromRequest(req.headers());
        // replace with next line
        UUID sessionId = UUID.randomUUID();
        ...
    }
    ...
}

@mrniko
Copy link
Owner

mrniko commented May 8, 2018

@Crimscent Actually the problem is in this change 057014f. Could you combine both variants - previous code and current into single one and suggest a PR?

@Crimscent
Copy link

@mrniko, hmm, I think the old code is not that correct as well, netty-socketio fetches 'io' header on handshake, which is not needed (it's not done by reference 1.x nodejs implementation). Can do PR after clarification.

@mrniko
Copy link
Owner

mrniko commented May 8, 2018

@Crimscent OK. I'll do it by myself

@mrniko
Copy link
Owner

mrniko commented May 15, 2018

Fixed

@oliverhausler
Copy link

@Crimscent This apparently should be fixed, but it's not working for me. Is this fixed for you? If you want, please let's discuss.

The approach of using a single io cookie will not always work. It will work as long as all requests coming from different tabs are meant to be for the same session. If that's not the case, a cookie won't work. [For example, we make requests from frames embedded into different websites. The socket.io request is made from within the frame, so all sessions are bundled when on the same browser. A huge mess.]

@RICH0423
Copy link

RICH0423 commented Mar 4, 2019

You can set randomSession to true (from version 1.7.17)

Configuration config = new Configuration();
config.setHostname(socketIOConfig.getHost());
config.setPort(socketIOConfig.getPort());
config.setRandomSession(true);  //default is false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants