I think your code is correct, and perhaps the only way to do this. Session_id is usually stored in a cookie and at some point should be sent to the server. Since node and php are different languages, they cannot directly transmit the session. You always need intermediate storage like redis, mysql or the file system. And of course, a way to get a session. The key to session extraction is, of course, session_id.
An interesting post about protecting web cards:
https://www.christian-schneider.net/CrossSiteWebSocketHijacking.html
He suggests adding a random generated key to your session, which you can check when establishing a connection to a web socket.
Session_id itself is already random, but these session_id are usually durable, so a short-lived random identifier can increase security. The short-term should be as short as possible: let php add it to the database, and as soon as the connection is checked in node, remove it from the database so that you cannot use it again.
There are many additional methods for checking the session, such as checking the browser line or fixing the session to one ip address:
http://phpsec.org/projects/guide/4.html
I would not recommend these types of checks, since they actually do not add additional security, only annoyance with the end user.
Most importantly, I think that:
- You are using a secure session_id communication method, etc. This means that HTTPS
- Sessions should end when the user closes their browser
- The user should be notified if he connects from another place or must have access to his "logbook"
Jimbolino
source share