Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
Fulfill prophecy left in a comment several years ago and actually sea…
Browse files Browse the repository at this point in the history
…rch for the appropriate cookie.
  • Loading branch information
echicken committed Feb 1, 2018
1 parent 8c67fe2 commit db33807
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions mods/websocket-rlogin-service.js
Expand Up @@ -236,7 +236,7 @@ var RLoginClient = function(options) {

if (!state.connected) throw 'RLogin.send: not connected.';
if (state.suspendInput) throw 'RLogin.send: input has been suspended.';

if (typeof data === 'string') {
data = data.split('').map(function (d) { return ascii(d); });
}
Expand Down Expand Up @@ -294,21 +294,21 @@ var RLoginClient = function(options) {
}

this.connect = function () {

if (typeof options.port !== 'number' ||
typeof options.host != 'string'
) {
throw 'RLogin: invalid host or port argument.';
}

if (typeof options.clientUsername !== 'string') {
throw 'RLogin: invalid clientUsername argument.';
}

if (typeof options.serverUsername !== 'string') {
throw 'RLogin: invalid serverUsername argument.';
}

if (typeof options.terminalType !== 'string') {
throw 'RLogin: invalid terminalType argument.';
}
Expand Down Expand Up @@ -363,23 +363,27 @@ try {

wss = new WebSocketProxy(client);

if (typeof wss.headers['Cookie'] === 'undefined') {
if (typeof wss.headers['Cookie'] == 'undefined') {
err('No cookie from WebSocket client.');
}

// Should probably search for the right cookie instead of assuming
var cookie = wss.headers['Cookie'].split('=');
if (cookie[0] !== 'synchronet' || cookie.length < 2) {
err('Invalid cookie from WebSocket client.');
}
var cookie = null;
wss.headers['Cookie'].split(';').some(
function (e) {
if (e.search(/^\s*synchronet\=/) == 0) {
cookie = e;
return true;
} else {
return false;
}
}
);
if (cookie === null) err('Invalid cookie from WebSocket client.');
cookie = cookie.replace(/^\s*synchronet\=/, '').split(',');

cookie = cookie[1].split(',');
cookie[0] = parseInt(cookie[0]);
if (cookie.length < 2 ||
isNaN(cookie[0]) ||
cookie[0] < 1 ||
cookie[0] > system.lastuser
) {
if (cookie.length < 2 || isNaN(cookie[0]) || cookie[0] < 1 || cookie[0] > system.lastuser) {
log('cookie ' + JSON.stringify(cookie));
err('Invalid cookie from WebSocket client.');
}

Expand Down Expand Up @@ -444,4 +448,4 @@ try {
} finally {
rlogin.disconnect();
client.socket.close();
}
}

0 comments on commit db33807

Please sign in to comment.