我的node.js服務器期望從未經過身份驗證的(不可信的)客戶端接收字符串化的JSON對象。如何安全地解析通過websockets傳來的json對象?
服務器使用JSON.parse來處理數據。 是否有可能在來自websocket的JOSN數據中注入「威脅和操縱」命令?
是否有任何安全預防措施要考慮?
有沒有像在JavaScript解析中的「htmlspecialchars()在PHP中」?
服務器:
wsBoss = new WSServer(portboss);
wsBoss.on('connection', function (socket) {
console.log('connected to boss');
socket.on('message', function (msg) {
console.log(JSON.parse(msg).topGeo[0]);
var msgsms="HI";
socket.send(msgsms);
});
客戶:
var data={"topGeo":topGeo,
"bottomGeo":bottomGeo,
"concLoad":concLoad}
console.log(topGeo,bottomGeo,depth,generalLoad,concLoad,intervLoad,mode,joistType,units);
websocket.send(JSON.stringify(data));
感謝您的回答。 –