Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,12 @@ Manager.prototype.handleClient = function (data, req) {

var transport = new transports[data.transport](this, data, req)
, handshaken = this.handshaken[data.id];


if (transport.disconnected) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a transport fails, or a client isn't properly verified, he will still be noted as connected. Adding this may possibly avoid a heap of strange errors reported elsewhere.

// failed during transport setup
req.connection.end();
return;
}
if (handshaken) {
if (transport.open) {
if (this.closed[data.id] && this.closed[data.id].length) {
Expand Down Expand Up @@ -813,6 +818,7 @@ Manager.prototype.verifyOrigin = function (request) {
if (origin) {
try {
var parts = url.parse(origin);
parts.port = parts.port || 80;
var ok =
~origins.indexOf(parts.hostname + ':' + parts.port) ||
~origins.indexOf(parts.hostname + ':*') ||
Expand Down
5 changes: 4 additions & 1 deletion lib/transports/websocket/hybi-07-12.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ WebSocket.prototype.verifyOrigin = function (origin) {
if (origin) {
try {
var parts = url.parse(origin);
parts.port = parts.port || 80;
var ok =
~origins.indexOf(parts.hostname + ':' + parts.port) ||
~origins.indexOf(parts.hostname + ':*') ||
Expand Down Expand Up @@ -505,7 +506,9 @@ Parser.prototype.expect = function(what, length, handler) {
*/

Parser.prototype.processPacket = function (data) {
if ((data[0] & 0x70) != 0) this.error('reserved fields must be empty');
if ((data[0] & 0x70) != 0) {
this.error('reserved fields must be empty');
}
this.state.lastFragment = (data[0] & 0x80) == 0x80;
this.state.masked = (data[1] & 0x80) == 0x80;
var opcode = data[0] & 0xf;
Expand Down
6 changes: 5 additions & 1 deletion lib/transports/websocket/hybi-16.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ WebSocket.prototype.verifyOrigin = function (origin) {
if (origin) {
try {
var parts = url.parse(origin);
parts.port = parts.port || 80;
var ok =
~origins.indexOf(parts.hostname + ':' + parts.port) ||
~origins.indexOf(parts.hostname + ':*') ||
Expand Down Expand Up @@ -505,7 +506,10 @@ Parser.prototype.expect = function(what, length, handler) {
*/

Parser.prototype.processPacket = function (data) {
if ((data[0] & 0x70) != 0) this.error('reserved fields must be empty');
if ((data[0] & 0x70) != 0) {
this.error('reserved fields must be empty');
return;
}
this.state.lastFragment = (data[0] & 0x80) == 0x80;
this.state.masked = (data[1] & 0x80) == 0x80;
var opcode = data[0] & 0xf;
Expand Down
2 changes: 1 addition & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function WSClient (port, sid, transport) {
this.transportName = transport || 'websocket';
WebSocket.call(
this
, 'ws://localhost:' + port + '/socket.io/'
, 'ws://localhost:' + port + '/socket.io/'
+ io.protocol + '/' + this.transportName + '/' + sid
);
};
Expand Down
8 changes: 4 additions & 4 deletions test/hybi-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ mask = function(buf, maskString) {
if (typeof buf == 'string') buf = new Buffer(buf);
var mask = getBufferFromHexString(maskString || '34 83 a8 68');
for (var i = 0; i < buf.length; ++i) {
buf[i] ^= mask[i % 4];
buf[i] ^= mask[i % 4];
}
return buf;
}

/**
* Returns a hex string representing the length of a message
*/
getHybiLengthAsHexString = function(len, masked) {

getHybiLengthAsHexString = function(len, masked) {
if (len < 126) {
var buf = new Buffer(1);
buf[0] = (masked ? 0x80 : 0) | len;
Expand Down Expand Up @@ -94,6 +94,6 @@ pack = function(length, number) {
* Left pads the string 's' to a total length of 'n' with char 'c'.
*/

padl = function(s, n, c) {
padl = function(s, n, c) {
return new Array(1 + n - s.length).join(c) + s;
}
17 changes: 17 additions & 0 deletions test/manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,23 @@ module.exports = {
});
},

'test that a referer with implicit port 80 is accepted for foo.bar.com:80 origin': function (done) {
var port = ++ports
, io = sio.listen(port)
, cl = client(port);

io.configure(function () {
io.set('origins', 'foo.bar.com:80');
});

cl.get('/socket.io/{protocol}', { headers: { referer: 'http://foo.bar.com/something' } }, function (res, data) {
res.statusCode.should.eql(200);
cl.end();
io.server.close();
done();
});
},

'test that erroneous referer is denied for addr:* origin': function (done) {
var port = ++ports
, io = sio.listen(port)
Expand Down
2 changes: 1 addition & 1 deletion test/static.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ module.exports = {

'test that the client is build with the enabled transports': function (done) {
var port = ++ports
, io = sio.listen(port)
, io = sio.listen(port)
, cl = client(port);

io.set('transports', ['websocket']);
Expand Down
2 changes: 1 addition & 1 deletion test/stores.memory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {

client.set('b', 'c', function (err) {
should.strictEqual(err, null);

client.set('c', 'd', function (err) {
should.strictEqual(err, null);

Expand Down
2 changes: 1 addition & 1 deletion test/stores.redis.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module.exports = {

client.set('b', 'c', function (err) {
should.strictEqual(err, null);

client.set('c', 'd', function (err) {
should.strictEqual(err, null);

Expand Down
2 changes: 1 addition & 1 deletion test/transports.flashsocket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function FlashSocket (port, sid) {

WebSocket.call(
this
, 'ws://localhost:' + port + '/socket.io/'
, 'ws://localhost:' + port + '/socket.io/'
+ sio.protocol + '/flashsocket/' + sid
);
};
Expand Down
Loading