Skip to content

Ensure args is an array - #31

Open
baptistejamin wants to merge 1 commit into
hden:masterfrom
crisp-dev:master
Open

Ensure args is an array#31
baptistejamin wants to merge 1 commit into
hden:masterfrom
crisp-dev:master

Conversation

@baptistejamin

Copy link
Copy Markdown

Id packet.id is null and packet.data is not an array you can expect this error:

CreateListFromArrayLike called on non-object

This commit is fixing this.

@hden

hden commented Jun 10, 2017

Copy link
Copy Markdown
Owner

Socket.io itself handles event packets in a similar way https://github.com/socketio/socket.io/blob/2b216902e121ac2205444019b6d9316654809b29/lib/socket.js#L351-L359

What's the packet.type when the error is thrown?

@baptistejamin

Copy link
Copy Markdown
Author

Yes, Socket IO is using in a similar way, but socket IO is not using apply.

Apply requires an array. Socket IO is not using apply, that's why it's not crashing socket IO.

@hden

hden commented Jun 12, 2017

Copy link
Copy Markdown
Owner

Can you provide a minimal code sample that reproduces the error?

Comment thread index.js
var args = packet.data || []
var args = [];

if (packet.data && packet.data.constructor === Array) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

For those packet.data which is not an Array, what are them? Any reason that we should ignore them?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

A socket IO payload should be like [ 'my_event', my_data ]

There is no reason to catch non-array payloads. These are not valid at all.

You can just send raw data over a websocket and crash an entire server.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hmmm, random raw data through the websocket should not get through the parser at all. Maybe what we are dealing with is an error packet? In this case, we might actually want to catch that.

@hden hden mentioned this pull request Jun 12, 2017
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants