我正在寻找与数据库中的用户映射 websockets 连接,目前有这样的东西:
function connectToNotifServer(){
var conn = new WebSocket('ws://localhost:8080');
conn.onopen = function(e) {
alert("Connection established!");
conn.send(JSON.stringify({user_id: sessionStorage.getItem("user_id")}));
};
conn.onmessage = function(e) {
alert(e.data);
};
conn.onclose = function(e) {
alert("Connection closed!");
};
return conn;
}
然后我有一个 PHP websockets 服务器,它保留了与 user_id 的连接的映射。
但是,我认为存在安全漏洞,因为用户可以简单地在 user_id 中注入他想要的任何值并模拟另一个用户。是否有更好的方法来保留此映射,但不发送 user_id 或以其他方式发送?
谢谢