Skip to content

Commit 3dca835

Browse files
author
Kevin Matthews
committed
Sanitize data received by websocket.
1 parent a618caa commit 3dca835

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

static/websocket.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
var websocket;
2+
// This url can be used for testing. It echoes anything that you send to it.
3+
// var websocketUrl = "ws://echo.websocket.org";
24
var websocketUrl = "ws://localhost:9000/echo"; // cd_websocket.c demands this url.
35

46
function init() {
@@ -21,6 +23,17 @@ function onMessage(event) {
2123
progress = event.data;
2224

2325
console.log("WebSocket received message: " + progress);
26+
if ($.isNumeric(progress) == false)
27+
{
28+
console.log("Received non-numeric data!");
29+
return;
30+
}
31+
if (progress < 0 || progress > 100)
32+
{
33+
console.log("Progress out of range!");
34+
return;
35+
}
36+
2437
updateProgressBar(progress);
2538
}
2639

0 commit comments

Comments
 (0)