Skip to content

Commit 5467e6d

Browse files
committed
Fixed socket session secure might not apply properly
1 parent 411ce13 commit 5467e6d

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

lib/realtime.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,25 @@ function onAuthorizeFail(data, message, error, accept) {
4242
accept(); //accept whether authorize or not to allow anonymous usage
4343
}
4444

45+
//secure the origin by the cookie
4546
function secure(socket, next) {
4647
try {
4748
var handshakeData = socket.request;
4849
if (handshakeData.headers.cookie) {
4950
handshakeData.cookie = cookie.parse(handshakeData.headers.cookie);
5051
handshakeData.sessionID = cookieParser.signedCookie(handshakeData.cookie[config.sessionname], config.sessionsecret);
51-
if (handshakeData.cookie[config.sessionname] == handshakeData.sessionID) {
52+
if (handshakeData.sessionID &&
53+
handshakeData.cookie[config.sessionname] &&
54+
handshakeData.cookie[config.sessionname] != handshakeData.sessionID) {
55+
if (config.debug)
56+
logger.info("AUTH success cookie: " + handshakeData.sessionID);
57+
return next();
58+
} else {
5259
next(new Error('AUTH failed: Cookie is invalid.'));
5360
}
5461
} else {
5562
next(new Error('AUTH failed: No cookie transmitted.'));
5663
}
57-
if (config.debug)
58-
logger.info("AUTH success cookie: " + handshakeData.sessionID);
59-
60-
next();
6164
} catch (ex) {
6265
next(new Error("AUTH failed:" + JSON.stringify(ex)));
6366
}

0 commit comments

Comments
 (0)