From 73e8b0454e3f103df9ecea9bd5e97f3298b81c16 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Mon, 24 Dec 2018 15:14:37 -0700 Subject: [PATCH] Wrap ctx.reject() and catch throws --- core/servers/login/ssh.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/core/servers/login/ssh.js b/core/servers/login/ssh.js index f626cb79..ca1922ca 100644 --- a/core/servers/login/ssh.js +++ b/core/servers/login/ssh.js @@ -49,8 +49,16 @@ function SSHClient(clientConn) { self.log.trace( { method : ctx.method, username : username, newUser : self.isNewUser }, 'SSH authentication attempt'); + const safeContextReject = (param) => { + try { + return ctx.reject(param); + } catch(e) { + return; + } + }; + function terminateConnection() { - ctx.reject(); + safeContextReject(); return clientConn.end(); } @@ -106,19 +114,19 @@ function SSHClient(clientConn) { return handleSpecialError(err, username); } - return ctx.reject(SSHClient.ValidAuthMethods); + return safeContextReject(SSHClient.ValidAuthMethods); } ctx.accept(); }); } else { if(-1 === SSHClient.ValidAuthMethods.indexOf(ctx.method)) { - return ctx.reject(SSHClient.ValidAuthMethods); + return safeContextReject(SSHClient.ValidAuthMethods); } if(0 === username.length) { // :TODO: can we display something here? - return ctx.reject(); + return safeContextReject(); } const interactivePrompt = { prompt : `${ctx.username}'s password: `, echo : false };