I'm currently making a online game and I'm wondering about the security of Node.js and socket.io.
All my
io.sockets.on('connection', function (socket) {
socket.on('request', function (data) {
}) });
are secure. Players can emit any request (request refers to 'request' in this example) with any data (refers to 'data') and they won't be able to take avantage of it, even if they manually modify what request and data they emit and bypass client basic security. They also won't be able to make the server crash by sending invalide data.
Note: I only have 2 emits : emitting user/pass to log in and emitting input. The server sends data via various 'emit' though. There's no 'usual' notion of session(), or GET/POST. On client side, I'm exclusively using
var socket = io.connect('http://something:3000');
socket.emit('request', data);
For the static resources that players will need to get the code + images, it looks like:
app.use(express.static(__dirname + '/public'));
For database:
client = mysql.createConnection({ host: 'localhost', user: 'root', password: 'something',});
client.connect(); client.query('USE dbname');
And finally for routing?, I show the same page, no matter the request:
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
Thanks a lot.
Regarding what you've got right now - everything looks totally fine. Apart of that you dont use message names, but patch everything into request message. Dont think that this is good way, and there is no security reasons I can see behind such decision. As well you can subscribe and unsubscribe to different socket messages - makes it easier to manage 'visibility' of request points.
There are two ways you can look at security of your applications:
Technical
It relates to your setup of server, database credentials, firewall, rights to files, domain names and other bits, that are not directly from application it self.
Your concern here is make sure that access to server is not easy, and modifying files even more complex. Although there is always risk in any case, even most protected.
Reliable hosting services (Clouds here are most secure imho).
Access credentials to server - have to be secured as well. Even if someone will get those, still it should require them some time to get into your services and database. Have ability to resist this (firewall, ftp/ssh settings, etc).
Logical
This point of view on your security focuses specifically on your application logic and ability to somehow overcome it.
It is big topic though, and you might want to read generally some books about that.
Simplest things to think about is some generic rules over the way you architecture. For example:
eval ever on server side.