J
J
jsonuser2021-02-03 18:17:18
Node.js
jsonuser, 2021-02-03 18:17:18

How to secure socket.io from outside connections as much as possible?

How can I secure the io socket as much as possible from outside connections? That is, so that dofiga smart users could not connect to the socket, and access was only when connecting from the site.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Anton, 2021-02-03
@Fragster

no way

Y
Yaroslav Ivanov, 2021-02-03
@space2pacman

As an option, send something to the server, which will allow you to check if the user is authorized or not.
Customer

let socket = new io("http://localhost:7777", { query: "id=123" });

Server
io.on("connection", socket => {
    let id = socket.handshake.query.id;
    console.log(id) // 123
})

Sample project: https://github.com/space2pacman/pacman-chat

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question