Added SSH input validation.

Ylian Saint-Hilaire committed May 8, 2021 at 19:03 UTC e5579e7b84a98d75e7895066ba19768bb39c40c1
1 file changed +14 -2
apprelays.js
+14 -2
@@ -302,7 +302,10 @@ module.exports.CreateSshRelay = function (parent, db, ws, req, args, domain) {
302 if (typeof msg.action != 'string') return;
303 switch (msg.action) {
304 case 'connect': {
305 - // TODO: Verify inputs
305 + // Verify inputs
306 + if ((typeof msg.username != 'string') || (typeof msg.password != 'string')) break;
307 + if ((typeof msg.rows != 'number') || (typeof msg.cols != 'number') || (typeof msg.height != 'number') || (typeof msg.width != 'number')) break;
308 +
309 obj.termSize = msg;
310 obj.username = msg.username;
311 obj.password = msg.password;
@@ -310,6 +313,9 @@ module.exports.CreateSshRelay = function (parent, db, ws, req, args, domain) {
313 break;
314 }
315 case 'resize': {
316 + // Verify inputs
317 + if ((typeof msg.rows != 'number') || (typeof msg.cols != 'number') || (typeof msg.height != 'number') || (typeof msg.width != 'number')) break;
318 +
319 obj.termSize = msg;
320 if (obj.sshShell != null) { obj.sshShell.setWindow(obj.termSize.rows, obj.termSize.cols, obj.termSize.height, obj.termSize.width); }
321 break;
@@ -466,7 +472,10 @@ module.exports.CreateSshTerminalRelay = function (parent, db, ws, req, domain, u
472 if (typeof msg.action != 'string') return;
473 switch (msg.action) {
474 case 'sshauth': {
469 - // TODO: Verify inputs
475 + // Verify inputs
476 + if ((typeof msg.username != 'string') || (typeof msg.password != 'string')) break;
477 + if ((typeof msg.rows != 'number') || (typeof msg.cols != 'number') || (typeof msg.height != 'number') || (typeof msg.width != 'number')) break;
478 +
479 obj.termSize = msg;
480 obj.username = msg.username;
481 obj.password = msg.password;
@@ -478,6 +487,9 @@ module.exports.CreateSshTerminalRelay = function (parent, db, ws, req, domain, u
487 break;
488 }
489 case 'resize': {
490 + // Verify inputs
491 + if ((typeof msg.rows != 'number') || (typeof msg.cols != 'number') || (typeof msg.height != 'number') || (typeof msg.width != 'number')) break;
492 +
493 obj.termSize = msg;
494 if (obj.sshShell != null) { obj.sshShell.setWindow(obj.termSize.rows, obj.termSize.cols, obj.termSize.height, obj.termSize.width); }
495 break;