How to protect websocket connection ip from being modified - websocket

I am working on a small project to help me understand websockets better. I am making a simple browser game that connects to an ip via a websocket. There will be 3 ip addresses however I want to assign the user an ip and not have them able to modify it so they are unable to get on the same server as friends.
I will assign the ip based on how full the games are etc and this will be down via php. Currently although it connects to this ip, the user is able to use the console in a browser to modify the ip to one of the other ones.
I was thinking of sending a check number, so the web server sends this to the user along with the ip. It also sends it to the websocket server. Then when a user connects if the check number doesn't match it rejects the connection.
I'm new to websockets so I'm not sure if this would be easy to implement, so are there any easy solutions to this?

That seems to be the duty of other element, in particular the load balancer. How are you balancing the requests across those 3 servers? Does your load balancer support sticky sessions?
If not, probably you can record to which IP address the user connected first, and they if it connects to one of the other two later, you can return a HTTP 302 (Redirect) pointing to the server you want.
Cheers.

Related

How to handle multiple websockets from same browser's different tabs

I'm trying to implement a plugin for a game, which will communicate via websockets with my server. I want to prevent double connections from the same IP address from different browsers/tabs. I can't use cookies, because the connection is opened from plugin, which runs under a different domain, and cookies can be spoofed anyways, I also don't want to implement any authentication mechanism.
Now I went through myriad of implementations of websocket servers, but I still can't understand if I can communicate with multiples web sockets opened from same IP separately, or rather I want to communicate only with the very first websocket opened from a specific IP and ignore the requests that come from others. Is there any way to "store" a websocket connection on server side during handshake? Because as far as I can see I'm only getting a request and the only thing I can do is pass a parameter or token from client side, which again can be spoofed, so it's really not very different from a regular HTTP request, only with push option.
Thanks in advance.

Laravel Request IP Address: will Requests coming from VPNs show the same IP address or not?

Currently I am developing an HTTP server and I am using the throttle (access limitation per minute) functionality of Laravel based on IP address.
However I am afraid that when a VPN and/or Proxy Server is used by different people the incoming request will show the same IP address. The rate limitation is included only to prevent dedicated DOS attacks and I don't want the user of my website to be blocked by rate limitation if they are using a VPN.
First of all, I don't have a solid understanding of how IP addresses are obtained and stored in the Request object. I assume it is included in the HTTP request header however I wasn't able to find it in Google Chrome's developer tool, "Network" tab. The developer tool only shows the destination address and not the source ip address in the "Request Header" session.
Next, I don't have a testing environment where I can test whether the IP address will be the same when sending by different machines using the same VPN, hence I have to ask the question here.
Any help would be appreciated.
will Requests coming from VPNs show the same IP address or not?
Yes, it will show up as the same IP address as this is the whole purpose of using a VPN service, to change the user IP address.
However, if you want to detect if a user is using VPN there are third-party services to help you with that https://ipinfo.io/

How to implement UDP Hole Punching?

So I am trying to create a p2p file sharing application in Golang. I am running a globally accessible server for the purpose of sharing IP addresses of 2 clients. When both the clients have each other's IP addresses, they can use hole punching to share the files.
But I am facing some problems in the hole punching part. When I send a request to server, the server is going to store the address of the client and it will later relay this address to other client. Problem is that the address being stored on the server is different than the address that is being is used for Hole punching. Suppose that address being stored on server is NATrouterIP1:PORT-A for first client and NATrouterIP2:PORT-B for the second. But when I am using the first client to send a message to second client, it shows that the message was sent from NATRouterIP1:PORT-C. PORT-A generally stays around 65000. But this PORT-C is 1024. For my application to work these ports should be same. Can someone explain what the issue is?
Github: https://github.com/killtheverse/go-send

Finding devices in LAN using a server

I am trying to develop a lan chat application. As I looked for the topic, I found that whatsapp, viber etc. use a server which controls all the traffic. The server tells the status of devices and manage all traffic etc. So, what am I trying to know is :
How the server gets the info of devices like, IP address, MAC address etc?
How the data is transferred from one client to server and then server to another client?
Which language should I use server side?
As shown in image, I want to connect two devices, A and B and interchange data between them.
Actually, I'm not sure data always through the server. From what I know, the client logs in at the server the first time it connects only. If client A wants to send a message to client B, it retrieves the IP corresponding to username_B from the server, then exchange of data is done directly between client.
What you should do is to develop a protocol to login at the server and register the client IP, and to retrieve an IP from a username.
For the routers between server and clients, I think it is out the server scope, you just need for NAT.

Getting (non-HTTP) Client IP with load-balancer

Say I want to run something like the nyan cat telnet server (http://miku.acm.uiuc.edu/) and I need to handle 10,000 concurrent connections total. I have 10 servers in addition to a load balancer. Each server can handle 1,000 concurrent connections, and I want to put a load balancer in front of it to randomly divide the traffic to the 10 servers.
From what I've read, it's fairly simple for a load balancer to pass an HTTP request (along with the client IP) to the backend server, perhaps with FastCGI or with an X- header.
What would be the simplest way for the load balancer to pass the client IP to the backend server in this case with a simple TCP server? Would a hardware load balancer be needed, or are there ways to do this simply through software?
In other words, is there a uniform way to pass client IP when load balancing for non-HTTP stuff? The same way Google gets client IP when they load-balances Google Talk XMPP server or their Gmail IMAP server
This isn't for anything in specific; I'm just curious about if and how it can be done. Thanks in advance!
The simplest way would be for the load balancer to make itself completely invisible and pass the connection on with the source and destination IP address unmolested. For this to work, the same IP address must be assigned (as a loopback address, not to a physical interface) to all 10 servers and that would be the IP address the clients connect to. Internet traffic to that IP address has to go to the load balancer. The load balancer must be the default gateway for the servers.

Resources