Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure args is an array #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ module.exports = function (CustomEmitter) {
var emit = Emitter.prototype.emit

function onevent (packet) {
var args = packet.data || []
var args = [];

if (packet.data && packet.data.constructor === Array) {
Copy link
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
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
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.

args = packet.data
}
if (packet.id != null) {
args.push(this.ack(packet.id))
}
Expand Down