|
本帖最后由 nodiff 于 2024-7-4 13:19 编辑
1. 接受到 event.data 不为 string 的攻击时的报错
将:
- u.Server = {
- address: "ws://localhost:8010/TestServer/server",
- socket: null,
- connect: function() {
- e.address && (u.Server.address = e.address),
- u.Server.socket = new WebSocket(u.Server.address),
- console.log("正在连接至服务器..."),
- u.Server.socket.onopen = function(e) {
- u.Server.socket.onmessage = u.Server.onMessage,
- u.Server.socket.onclose = u.Server.onClose,
- u.Server.socket.onerror = u.Server.onError,
- u.Server.onOpen(e)
- }
- },
- onOpen: function(e) {
- console.log("成功连接到服务器。"),
- u.Event.call("ON_OPEN")
- },
- onMessage: function(e) {
- u.Event.call("ON_MESSAGE", e.data)
- },
- onError: function(e) {
- u.Event.call("ON_ERROR", e.data)
- },
- onClose: function(e) {
- console.log("从服务器断开:" + e.data),
- u.Event.call("ON_CLOSE", e.data)
- },
- send: function(e) {
- u.Server.socket.send(e)
- }
- };
复制代码 改为:
- u.Server = {
- address: "ws://localhost:8010/TestServer/server",
- socket: null,
- connect: function() {
- e.address && (u.Server.address = e.address),
- u.Server.socket = new WebSocket(u.Server.address),
- console.log("正在连接至服务器..."),
- u.Server.socket.onopen = function(e) {
- u.Server.socket.onmessage = u.Server.onMessage,
- u.Server.socket.onclose = u.Server.onClose,
- u.Server.socket.onerror = u.Server.onError,
- u.Server.onOpen(e)
- }
- },
- onOpen: function(e) {
- console.log("成功连接到服务器。"),
- u.Event.call("ON_OPEN")
- },
- onMessage: function(e) {
- if (typeof(e.data) != 'string') {
- console.log("u.Server.onMessage : e.data 不为 string, 已被拦截");
- return;
- }
- u.Event.call("ON_MESSAGE", e.data)
- },
- onError: function(e) {
- u.Event.call("ON_ERROR", e.data)
- },
- onClose: function(e) {
- console.log("从服务器断开:" + e.data),
- u.Event.call("ON_CLOSE", e.data)
- },
- send: function(e) {
- u.Server.socket.send(e)
- }
- };
复制代码
|
|