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

Invalid namespace for socket v2 connecting to server v3 #3791

Closed
RonnieRocket147 opened this issue Feb 3, 2021 · 1 comment
Closed

Invalid namespace for socket v2 connecting to server v3 #3791

RonnieRocket147 opened this issue Feb 3, 2021 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@RonnieRocket147
Copy link

RonnieRocket147 commented Feb 3, 2021

Describe the bug
After upgrading the server to v3.1.0 and using the allowEIO3: true option the client socket v2.2.0 cannot connect to the indicated namespace anymore.

  socket.io:server creating engine.io instance with opts {"allowEIO3":true,"cors":{"credentials":true,"methods":["GET","POST"],"origin":["https://localhost:4200","http://10.0.2.2:4200"],"transports":["websocket","polling"]},"path":"/socket.io"} +0ms
  socket.io:server initializing namespace /frontend +0ms
  socket.io:client connecting to namespace / +0ms
  engine:ws received "40/frontend?sessionId=2053f60c072e0749d141112ddc851e00942785d7&revision=develop," +1ms
  socket.io-parser decoded 0/frontend?sessionId=2053f60c072e0749d141112ddc851e00942785d7&revision=develop, as {"type":0,"nsp":"/frontend?sessionId=2053f60c072e0749d141112ddc851e00942785d7&revision=develop"} +3ms
  socket.io:client creation of namespace /frontend?sessionId=2053f60c072e0749d141112ddc851e00942785d7&revision=develop was denied +3ms
  socket.io:client writing packet {"type":4,"nsp":"/frontend?sessionId=2053f60c072e0749d141112ddc851e00942785d7&revision=develop","data":{"message":"Invalid namespace"}} +0ms

The client connects to the URL https://localhost:3700/frontend?sessionId=2053f60c072e0749d141112ddc851e00942785d7&revision=develop

When the query parameters are removed the connection to /frontend succeeds.

Server v2.2.0 was working fine with the query parameters.

Any thoughts?

@RonnieRocket147 RonnieRocket147 added the bug Something isn't working label Feb 3, 2021
darrachequesne added a commit that referenced this issue Feb 3, 2021
In Socket.IO v2, the Socket query option was appended to the namespace
in the CONNECT packet:

{
  type: 0,
  nsp: "/my-namespace?abc=123"
}

Note: the "query" option on the client-side (v2) will be found in the
"auth" attribute on the server-side:

```
// client-side
const socket = io("/nsp1", {
  query: {
    abc: 123
  }
});
socket.query = { abc: 456 };

// server-side
const io = require("socket.io")(httpServer, {
  allowEIO3: true // enable compatibility mode
});

io.of("/nsp1").on("connection", (socket) => {
  console.log(socket.handshake.auth); // { abc: 456 } (the Socket query)
  console.log(socket.handshake.query.abc); // 123 (the Manager query)
});

More information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/#Add-a-clear-distinction-between-the-Manager-query-option-and-the-Socket-query-option

Related: #3791
@darrachequesne
Copy link
Member

This should be fixed by 6f4bd7f (included in [email protected]).

Thanks for reporting the issue!

@darrachequesne darrachequesne added this to the 3.1.1 milestone Feb 3, 2021
dzad pushed a commit to dzad/socket.io that referenced this issue May 29, 2023
In Socket.IO v2, the Socket query option was appended to the namespace
in the CONNECT packet:

{
  type: 0,
  nsp: "/my-namespace?abc=123"
}

Note: the "query" option on the client-side (v2) will be found in the
"auth" attribute on the server-side:

```
// client-side
const socket = io("/nsp1", {
  query: {
    abc: 123
  }
});
socket.query = { abc: 456 };

// server-side
const io = require("socket.io")(httpServer, {
  allowEIO3: true // enable compatibility mode
});

io.of("/nsp1").on("connection", (socket) => {
  console.log(socket.handshake.auth); // { abc: 456 } (the Socket query)
  console.log(socket.handshake.query.abc); // 123 (the Manager query)
});

More information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/#Add-a-clear-distinction-between-the-Manager-query-option-and-the-Socket-query-option

Related: socketio#3791
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants