2017-08-17 183 views
1

我正在編寫一個web應用程序,我一直在考慮使用套接字時的安全性。假設客戶端上有一個代碼:從客戶端發送僞造的socket.io請求到服務器(node.js/socket.io)

$("#send").click(function(e) { 
     var data = { 
      name: "Albert", 
      surname: "Einstein" 
     }; 
     socket.emit("send data", data); 
    } 

那麼,在服務器上它是以某種方式處理。問題是,是否有可能以某種方式模擬socket.emit ("send data", data),沒有點擊,並將我的僞造參數插入到data?如果是,如何?

回答

1

是的,這是可能的。你可以寫一個簡單的假客戶端的例子:

fake.js

const server = "127.0.0.1"; // change it to the address of your server 
const port = 3000; // change it to the port of your server 
const data = "I am a fake client"; 
const socket = require("socket.io-client")("http://" + server + ":" + port); 

socket.on("connect", function() { 
    console.log("connected"); 
    socket.emit("send data", data); 
    console.log("data sent"); 
}); 

的package.json

{ 
    "name": "fake", 
    "version": "0.0.1", 
    "private": true, 
    "dependencies": { 
    "socket.io-client": "^2.0.2" 
    } 
} 

運行npm install然後node fake,你的任務是完成;)

相關問題