Search code examples
node.jsexpresssocket.ioreal-time-updates

Is socket.io or websocket safe to use with an express server?


I was wondering to have a realtime system made with express and i came to know about socket.io and websockets. But the way they are used i.e. const io = socket.io("https://example.com") ;

Is it safe to use. Since the url for socket connection is available at client side any third party service can enjoy and exploit the services by connecting from their service. I don't have much idea about socket.io so correct me if I am wrong.

Kindly don't mark this question as duplicate since I found a similar question but the answer to it was related to game development, here I am specific about updating clients whenever any updates are there on the server side. Clients may be website made with angular or apps made with Android studio. Any help is highly appreciable.


Solution

  • socket.io is widely used. It is perfectly fine for use in production.

    Regarding the authentication part, A websocket connection b/w client and browser is established via http upgrade request(in http/1.1). If you have an authentication mechanism in place for your application using cookie and session then you should be safe. No one can establish websocket connection directly without first logging in. On top of this you can limit connection per user to ensure that a registered user cant further exploit the connection using the cookie data.