Socket
Socket
Sign inDemoInstall

websocket-driver

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

websocket-driver - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

6

CHANGELOG.md

@@ -0,1 +1,7 @@

### 0.3.2 / 2013-12-29
* Expand `maxLength` to cover sequences of continuation frames and `draft-{75,76}`
* Decrease default maximum frame buffer size to 64MB
* Stop parsing when the protocol enters a failure mode, to save CPU cycles
### 0.3.1 / 2013-12-03

@@ -2,0 +8,0 @@

@@ -11,2 +11,3 @@ var Emitter = require('events').EventEmitter,

this._options = options || {};
this._maxLength = this._options.maxLength || this.MAX_LENGTH;
this.__headers = new Headers();

@@ -24,2 +25,6 @@ this.__queue = [];

var instance = {
// This is 64MB, small enough for an average VPS to handle without
// crashing from process out of memory
MAX_LENGTH: 0x3ffffff,
STATES: ['connecting', 'open', 'closing', 'closed'],

@@ -26,0 +31,0 @@

13

lib/websocket/driver/draft75.js

@@ -12,3 +12,12 @@ var Base = require('./base'),

var instance = {
close: function() {
if (this.readyState === 3) return false;
this.readyState = 3;
this.emit('close', new Base.CloseEvent(null, null));
return true;
},
parse: function(buffer) {
if (this.readyState > 1) return;
var data, message, value;

@@ -33,4 +42,3 @@ for (var i = 0, n = buffer.length; i < n; i++) {

if (this._closing && this._length === 0) {
this.readyState = 3;
this.emit('close', new Base.CloseEvent(null, null));
return this.close();
}

@@ -61,2 +69,3 @@ else if ((0x80 & data) !== 0x80) {

this._buffer.push(data);
if (this._buffer.length > this._maxLength) return this.close();
}

@@ -63,0 +72,0 @@ }

48

lib/websocket/driver/hybi.js

@@ -14,3 +14,2 @@ var crypto = require('crypto'),

this._protocols = this._options.protocols || [];
this._maxLength = this._options.maxLength || this.MAX_LENGTH;

@@ -71,5 +70,2 @@ if (typeof this._protocols === 'string')

// This is the maximum length of a Node buffer:
// https://github.com/joyent/node/blob/master/src/smalloc.h#L40
MAX_LENGTH: 0x3fffffff,
TWO_POWERS: [0, 1, 2, 3, 4, 5, 6, 7].map(function(n) { return Math.pow(2, 8 * n) }),

@@ -132,2 +128,5 @@

break;
default:
buffer = null;
}

@@ -254,2 +253,3 @@ }

this.readyState = 3;
this._stage = 5;
this.emit('close', new Base.CloseEvent(code, reason));

@@ -299,7 +299,7 @@ },

if (this._length >= 0 && this._length <= 125) {
if (!this._checkFrameLength()) return;
this._stage = this._masked ? 3 : 4;
} else {
this._lengthBuffer = [];
this._lengthSize = (this._length === 126 ? 2 : 8);
this._stage = 2;
this._lengthSize = (this._length === 126 ? 2 : 8);
this._stage = 2;
}

@@ -314,4 +314,3 @@ },

if (this._length > this._maxLength)
return this._fail('too_large', 'WebSocket frame length too large');
if (!this._checkFrameLength()) return;

@@ -321,2 +320,11 @@ this._stage = this._masked ? 3 : 4;

_checkFrameLength: function() {
if (this.__blength + this._length > this._maxLength) {
this._fail('too_large', 'WebSocket frame length too large');
return false;
} else {
return true;
}
},
_emitFrame: function() {

@@ -330,3 +338,3 @@ var payload = Hybi.mask(this._payload, this._mask),

if (this._final) {
var message = new Buffer(this.__buffer);
var message = this._concatBuffer();
if (this._mode === 'text') message = this._encode(message);

@@ -388,9 +396,21 @@ this._reset();

_buffer: function(fragment) {
for (var i = 0, n = fragment.length; i < n; i++)
this.__buffer.push(fragment[i]);
this.__buffer.push(fragment);
this.__blength += fragment.length;
},
_concatBuffer: function() {
var buffer = new Buffer(this.__blength),
offset = 0;
for (var i = 0, n = this.__buffer.length; i < n; i++) {
this.__buffer[i].copy(buffer, offset);
offset += this.__buffer[i].length;
}
return buffer;
},
_reset: function() {
this._mode = null;
this.__buffer = [];
this._mode = null;
this.__buffer = [];
this.__blength = 0;
},

@@ -397,0 +417,0 @@

@@ -8,3 +8,3 @@ { "name" : "websocket-driver"

, "version" : "0.3.1"
, "version" : "0.3.2"
, "engines" : {"node": ">=0.4.0"}

@@ -11,0 +11,0 @@ , "main" : "./lib/websocket/driver"

@@ -177,3 +177,3 @@ # websocket-driver [![Build Status](https://travis-ci.org/faye/websocket-driver-node.png)](https://travis-ci.org/faye/websocket-driver-node)

* `maxLength` - the maximum allowed size of incoming message frames, in bytes.
The default value is `2^30 - 1`, or 1 byte short of 1 GiB.
The default value is `2^26 - 1`, or 1 byte short of 64 MiB.
* `protocols` - an array of strings representing acceptable subprotocols for

@@ -180,0 +180,0 @@ use over the socket. The driver will negotiate one of these to use via the

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc