Compare commits

...

23 Commits
2.1.1 ... 2.4.1

Author SHA1 Message Date
Damien Arrachequesne
e6b869738c chore(release): 2.4.1
Diff: https://github.com/socketio/socket.io/compare/2.4.0...2.4.1
2021-01-07 10:59:46 +01:00
Damien Arrachequesne
a169050947 revert: fix(security): do not allow all origins by default
This reverts commit f78a575f66.

This commit contains a breaking change which deviates from semver,
which we try to follow as closely as possible. That's why this change
is reverted and we will rather suggest users to upgrade to v3.

Related: https://github.com/socketio/socket.io/discussions/3741
2021-01-07 10:51:55 +01:00
Damien Arrachequesne
873fdc55ed chore(release): 2.4.0
Diff: https://github.com/socketio/socket.io/compare/2.3.0...2.4.0
2021-01-05 00:27:13 +01:00
Damien Arrachequesne
f78a575f66 fix(security): do not allow all origins by default
BREAKING CHANGE: previously, all origins were allowed by default, which
meant that a Socket.IO server sent the necessary CORS headers
(`Access-Control-Allow-xxx`) to any domain by default.

Please note that you are not impacted if:

- you are using Socket.IO v2 and the `origins` option to restrict the list of allowed domains
- you are using Socket.IO v3 (disabled by default)

This commit also removes the support for '*' matchers and protocol-less
URL:

```
io.origins('https://example.com:443'); => io.origins(['https://example.com']);
io.origins('localhost:3000');          => io.origins(['http://localhost:3000']);
io.origins('http://localhost:*');      => io.origins(['http://localhost:3000']);
io.origins('*:3000');                  => io.origins(['http://localhost:3000']);
```

To restore the previous behavior (please use with caution):

```js
io.origins((_, callback) => {
  callback(null, true);
});
```

See also:

- https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
- https://socket.io/docs/v3/handling-cors/
- https://socket.io/docs/v3/migrating-from-2-x-to-3-0/#CORS-handling

Thanks a lot to https://github.com/ni8walk3r for the security report.
2021-01-04 22:34:09 +01:00
Sebastiaan Marynissen
d33a619905 fix: properly overwrite the query sent in the handshake
The `query` option of the Manager had the priority over the one of the
Socket instance, which meant updating the Socket#query object on the
client-side was not reflected in the Socket#handshake object on the
server-side.

Please note that the behavior of the `query` option is still a bit
weird in Socket.IO v2, as it only applies to non-default namespace.
This is fixed in v3:

- https://socket.io/docs/v3/migrating-from-2-x-to-3-0/#Add-a-clear-distinction-between-the-Manager-query-option-and-the-Socket-query-option
- https://socket.io/docs/v3/middlewares/#Sending-credentials

Fixes https://github.com/socketio/socket.io/issues/3495
2021-01-04 11:34:24 +01:00
Damien Arrachequesne
3951a79359 chore: bump engine.io version
Diff: https://github.com/socketio/engine.io/compare/3.4.2...3.5.0
2021-01-04 10:50:13 +01:00
Damien Arrachequesne
6fa026fc94 ci: migrate to GitHub Actions
Due to the recent changes to the Travis CI platform (see [1]), we will
now use GitHub Actions to run the tests.

Reference: https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-nodejs

[1]: https://blog.travis-ci.com/2020-11-02-travis-ci-new-billing
2021-01-04 10:46:44 +01:00
Damien Arrachequesne
47161a65d4 [chore] Release 2.3.0
Diff: https://github.com/socketio/socket.io/compare/2.2.0...2.3.0
2019-09-20 12:18:39 +02:00
Damien Arrachequesne
cf39362014 [chore] Bump socket.io-parser to version 3.4.0
Diff: https://github.com/socketio/socket.io-parser/compare/3.3.0...3.4.0
2019-09-20 11:04:11 +02:00
flaambe
4d01b2c84c test: remove deprecated Buffer usage (#3481) 2019-09-20 10:50:12 +02:00
Jonatan Juárez
82271921db [docs] Fix the default value of the 'origins' parameter (#3464)
Fix documentation about default origins value. The default should read `*:*` instead of `*
2019-09-20 10:37:54 +02:00
Damien Arrachequesne
1150eb50e9 [chore] Bump engine.io to version 3.4.0
Diff: https://github.com/socketio/engine.io/compare/3.3.1...3.4.0
2019-09-20 10:31:25 +02:00
Grant Timmerman
9c1e73c752 [chore] Update the license of the chat example (#3410)
There was no obvious reason to use BSD instead of MIT for that very basic chat app.

Closes #3411
2019-03-15 22:22:22 +01:00
Damien Arrachequesne
df05b73bb9 [chore] Release 2.2.0 2018-11-29 00:00:45 +01:00
Markko Legonkov
b00ae50be6 [feat] Add cache-control header when serving the client source (#2907) 2018-11-20 08:02:04 +01:00
Nadir Hussain Laskar
d3c653d876 [docs] Add Touch Support to the whiteboard example (#3104) 2018-11-20 08:01:09 +01:00
Antonio
a7fbd1ac4a [fix] Throw an error when trying to access the clients of a dynamic namespace (#3355)
Accessing the clients of a dynamic namespace throws because doing `io.of(/your-regex/g)` returns a namespace with no adapter and the clients methods tries to access `namespace.adapter.clients`.
2018-11-20 07:40:11 +01:00
Damien Arrachequesne
190d22b46e [chore] Bump dependencies
- engine.io: https://github.com/socketio/engine.io/compare/3.2.0...3.3.1
- socket.io-parser: https://github.com/socketio/socket.io-parser/compare/3.2.0..3.3.0
2018-11-20 07:33:41 +01:00
Damien Arrachequesne
7b8fba7ea2 [test] Update Travis configuration
Reference: https://github.com/nodejs/Release
2018-11-20 07:32:39 +01:00
Emmanuel DEMEY
e5f0ceaee0 [docs] Use new JavaScript syntax inside the README (#3360) 2018-11-08 00:26:54 +01:00
Damien Arrachequesne
7e35f901b8 [docs] fix this scope in the chat example
`user is typing` messages were not properly removed

Closes #3291
2018-08-28 09:05:44 +02:00
Damien Arrachequesne
2dbec77a38 [chore] Update issue template 2018-08-21 13:21:14 +02:00
Andrew Stelmach
d97d873aee [docs] update README.md (#3309) 2018-08-18 23:32:07 +02:00
17 changed files with 3478 additions and 68 deletions

View File

@@ -1,5 +1,9 @@
*Note*: for support questions, please use one of these channels: [stackoverflow](http://stackoverflow.com/questions/tagged/socket.io) or [slack](https://socketio.slack.com)
**Note**: for support questions, please use one of these channels: [stackoverflow](http://stackoverflow.com/questions/tagged/socket.io) or [slack](https://socketio.slack.com)
For bug reports and feature requests for the **Swift client**, please open an issue [there](https://github.com/socketio/socket.io-client-swift).
For bug reports and feature requests for the **Java client**, please open an issue [there](https://github.com/socketio/socket.io-client-java).
### You want to:
@@ -8,13 +12,15 @@
### Current behaviour
*What is actually happening?*
### Steps to reproduce (if the current behaviour is a bug)
**Note**: the best way to get a quick answer is to provide a failing test case, by forking the following [fiddle](https://github.com/darrachequesne/socket.io-fiddle) for example.
**Note**: the best way (and by that we mean **the only way**) to get a quick answer is to provide a failing test case by forking the following [fiddle](https://github.com/socketio/socket.io-fiddle).
### Expected behaviour
*What is expected?*
### Setup
- OS:

24
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,24 @@
name: CI
on:
push:
pull_request:
jobs:
test-node:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test
env:
CI: true

View File

@@ -1,14 +0,0 @@
language: node_js
sudo: false
node_js:
- '4'
- '6'
- '8'
- node
notifications:
irc: "irc.freenode.org#socket.io"
git:
depth: 1
cache:
directories:
- node_modules

15
CHANGELOG.md Normal file
View File

@@ -0,0 +1,15 @@
## [2.4.1](https://github.com/socketio/socket.io/compare/2.4.0...2.4.1) (2021-01-07)
### Reverts
* fix(security): do not allow all origins by default ([a169050](https://github.com/socketio/socket.io/commit/a1690509470e9dd5559cec4e60908ca6c23e9ba0))
# [2.4.0](https://github.com/socketio/socket.io/compare/2.3.0...2.4.0) (2021-01-04)
### Bug Fixes
* **security:** do not allow all origins by default ([f78a575](https://github.com/socketio/socket.io/commit/f78a575f66ab693c3ea96ea88429ddb1a44c86c7))
* properly overwrite the query sent in the handshake ([d33a619](https://github.com/socketio/socket.io/commit/d33a619905a4905c153d4fec337c74da5b533a9e))

View File

@@ -2,7 +2,7 @@
# socket.io
[![Backers on Open Collective](https://opencollective.com/socketio/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/socketio/sponsors/badge.svg)](#sponsors)
[![Build Status](https://secure.travis-ci.org/socketio/socket.io.svg?branch=master)](https://travis-ci.org/socketio/socket.io)
[![Build Status](https://github.com/socketio/socket.io/workflows/CI/badge.svg)](https://github.com/socketio/socket.io/actions)
[![Dependency Status](https://david-dm.org/socketio/socket.io.svg)](https://david-dm.org/socketio/socket.io)
[![devDependency Status](https://david-dm.org/socketio/socket.io/dev-status.svg)](https://david-dm.org/socketio/socket.io#info=devDependencies)
[![NPM version](https://badge.fury.io/js/socket.io.svg)](https://www.npmjs.com/package/socket.io)
@@ -11,7 +11,7 @@
## Features
Socket.IO enables real-time bidirectional event-based communication. It consists in:
Socket.IO enables real-time bidirectional event-based communication. It consists of:
- a Node.js server (this repository)
- a [Javascript client library](https://github.com/socketio/socket.io-client) for the browser (or a Node.js client)
@@ -55,10 +55,10 @@ Any serializable data structures can be emitted, including:
Sample code:
```js
io.on('connection', function(socket){
socket.emit('request', /* */); // emit an event to the socket
io.emit('broadcast', /* */); // emit an event to all connected sockets
socket.on('reply', function(){ /* */ }); // listen to the event
io.on('connection', socket => {
socket.emit('request', /* */); // emit an event to the socket
io.emit('broadcast', /* */); // emit an event to all connected sockets
socket.on('reply', () => { /* */ }); // listen to the event
});
```
@@ -84,7 +84,7 @@ This is a useful feature to send notifications to a group of users, or to a give
## Installation
```bash
npm install socket.io --save
npm install socket.io
```
## How to use
@@ -93,11 +93,11 @@ The following example attaches socket.io to a plain Node.JS
HTTP server listening on port `3000`.
```js
var server = require('http').createServer();
var io = require('socket.io')(server);
io.on('connection', function(client){
client.on('event', function(data){});
client.on('disconnect', function(){});
const server = require('http').createServer();
const io = require('socket.io')(server);
io.on('connection', client => {
client.on('event', data => { /* … */ });
client.on('disconnect', () => { /* … */ });
});
server.listen(3000);
```
@@ -105,8 +105,8 @@ server.listen(3000);
### Standalone
```js
var io = require('socket.io')();
io.on('connection', function(client){});
const io = require('socket.io')();
io.on('connection', client => { ... });
io.listen(3000);
```
@@ -118,10 +118,10 @@ to pass the `Server` to `socket.io`, and not the express application
function. Also make sure to call `.listen` on the `server`, not the `app`.
```js
var app = require('express')();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
io.on('connection', function(){ /* … */ });
const app = require('express')();
const server = require('http').createServer(app);
const io = require('socket.io')(server);
io.on('connection', () => { /* … */ });
server.listen(3000);
```
@@ -131,10 +131,10 @@ Like Express.JS, Koa works by exposing an application as a request
handler function, but only by calling the `callback` method.
```js
var app = require('koa')();
var server = require('http').createServer(app.callback());
var io = require('socket.io')(server);
io.on('connection', function(){ /* … */ });
const app = require('koa')();
const server = require('http').createServer(app.callback());
const io = require('socket.io')(server);
io.on('connection', () => { /* … */ });
server.listen(3000);
```

View File

@@ -78,7 +78,7 @@ Exposed by `require('socket.io')`.
- `path` _(String)_: name of the path to capture (`/socket.io`)
- `serveClient` _(Boolean)_: whether to serve the client files (`true`)
- `adapter` _(Adapter)_: the adapter to use. Defaults to an instance of the `Adapter` that ships with socket.io which is memory based. See [socket.io-adapter](https://github.com/socketio/socket.io-adapter)
- `origins` _(String)_: the allowed origins (`*`)
- `origins` _(String)_: the allowed origins (`*:*`)
- `parser` _(Parser)_: the parser to use. Defaults to an instance of the `Parser` that ships with socket.io. See [socket.io-parser](https://github.com/socketio/socket.io-parser).
Works with and without `new`:
@@ -635,7 +635,7 @@ Emits an event to the socket identified by the string name. Any other parameters
```js
socket.emit('hello', 'world');
socket.emit('with-binary', 1, '2', { 3: '4', 5: new Buffer(6) });
socket.emit('with-binary', 1, '2', { 3: '4', 5: Buffer.alloc(6) });
```
The `ack` argument is optional and will be called with the client's answer.

View File

@@ -108,7 +108,7 @@ $(function() {
// Removes the visual chat typing message
const removeChatTyping = (data) => {
getTypingMessages(data).fadeOut(() => {
getTypingMessages(data).fadeOut(function () {
$(this).remove();
});
}
@@ -171,7 +171,7 @@ $(function() {
// Gets the 'X is typing' messages of a user
const getTypingMessages = (data) => {
return $('.typing.message').filter(i => {
return $('.typing.message').filter(function (i) {
return $(this).data('username') === data.username;
});
}

View File

@@ -5,7 +5,7 @@
"main": "index.js",
"author": "Grant Timmerman",
"private": true,
"license": "BSD",
"license": "MIT",
"dependencies": {
"express": "4.13.4",
"socket.io": "^1.7.2",

View File

@@ -14,7 +14,7 @@ They are tested with various payloads:
- string: `['1', '2', ... '1000']`
- numeric: `[1, 2, ... 1000]`
- binary: `new Buffer(1000), where buf[i] = i`
- binary: `Buffer.allocUnsafe(1000), where buf[i] = i`
## How to use

View File

@@ -27,7 +27,7 @@ let server4 = io(3004, {
let string = [];
let numeric = [];
let binary = new Buffer(1e3);
let binary = Buffer.allocUnsafe(1e3);
for (var i = 0; i < 1e3; i++) {
string.push('' + i);
numeric.push(i);

View File

@@ -16,6 +16,12 @@
canvas.addEventListener('mouseup', onMouseUp, false);
canvas.addEventListener('mouseout', onMouseUp, false);
canvas.addEventListener('mousemove', throttle(onMouseMove, 10), false);
//Touch support for mobile devices
canvas.addEventListener('touchstart', onMouseDown, false);
canvas.addEventListener('touchend', onMouseUp, false);
canvas.addEventListener('touchcancel', onMouseUp, false);
canvas.addEventListener('touchmove', throttle(onMouseMove, 10), false);
for (var i = 0; i < colors.length; i++){
colors[i].addEventListener('click', onColorUpdate, false);
@@ -51,21 +57,21 @@
function onMouseDown(e){
drawing = true;
current.x = e.clientX;
current.y = e.clientY;
current.x = e.clientX||e.touches[0].clientX;
current.y = e.clientY||e.touches[0].clientY;
}
function onMouseUp(e){
if (!drawing) { return; }
drawing = false;
drawLine(current.x, current.y, e.clientX, e.clientY, current.color, true);
drawLine(current.x, current.y, e.clientX||e.touches[0].clientX, e.clientY||e.touches[0].clientY, current.color, true);
}
function onMouseMove(e){
if (!drawing) { return; }
drawLine(current.x, current.y, e.clientX, e.clientY, current.color, true);
current.x = e.clientX;
current.y = e.clientY;
drawLine(current.x, current.y, e.clientX||e.touches[0].clientX, e.clientY||e.touches[0].clientY, current.color, true);
current.x = e.clientX||e.touches[0].clientX;
current.y = e.clientY||e.touches[0].clientY;
}
function onColorUpdate(e){

View File

@@ -370,6 +370,7 @@ Server.prototype.serve = function(req, res){
}
debug('serve client source');
res.setHeader("Cache-Control", "public, max-age=0");
res.setHeader('Content-Type', 'application/javascript');
res.setHeader('ETag', expectedEtag);
res.writeHead(200);

View File

@@ -262,6 +262,9 @@ Namespace.prototype.write = function(){
*/
Namespace.prototype.clients = function(fn){
if(!this.adapter){
throw new Error('No adapter for this namespace, are you trying to get the list of clients of a dynamic namespace?')
}
this.adapter.clients(this.rooms, fn);
// reset rooms for scenario:
// .in('room').clients() (GH-1978)

View File

@@ -116,7 +116,7 @@ Socket.prototype.buildHandshake = function(query){
function buildQuery(){
var requestQuery = url.parse(self.request.url, true).query;
//if socket-specific query exist, replace query strings in requestQuery
return Object.assign({}, query, requestQuery);
return Object.assign({}, requestQuery, query);
}
return {
headers: this.request.headers,

3352
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "socket.io",
"version": "2.1.1",
"version": "2.4.1",
"description": "node.js realtime framework server",
"keywords": [
"realtime",
@@ -24,12 +24,12 @@
"test": "nyc mocha --reporter spec --slow 200 --bail --timeout 10000 test/socket.io.js"
},
"dependencies": {
"debug": "~3.1.0",
"engine.io": "~3.2.0",
"debug": "~4.1.0",
"engine.io": "~3.5.0",
"has-binary2": "~1.0.2",
"socket.io-adapter": "~1.1.0",
"socket.io-client": "2.1.1",
"socket.io-parser": "~3.2.0"
"socket.io-client": "2.4.0",
"socket.io-parser": "~3.4.0"
},
"devDependencies": {
"expect.js": "0.3.1",

View File

@@ -23,7 +23,7 @@ function client(srv, nsp, opts){
describe('socket.io', function(){
it('should be the same version as client', function(){
it.skip('should be the same version as client', function(){
var version = require('../package').version;
expect(version).to.be(require('socket.io-client/package').version);
});
@@ -1126,7 +1126,7 @@ describe('socket.io', function(){
sio.on('connection', function(s){
fs.readFile(join(__dirname, 'support', 'doge.jpg'), function(err, data){
if (err) return done(err);
var buf = new Buffer('asdfasdf', 'utf8');
var buf = Buffer.from('asdfasdf', 'utf8');
s.emit('multiple', 1, data, '3', [4], buf, [data, 'swag', buf]);
});
});
@@ -1143,7 +1143,7 @@ describe('socket.io', function(){
expect(Buffer.isBuffer(a)).to.be(true);
done();
});
var buf = new Buffer('abcdefg', 'utf8');
var buf = Buffer.from('abcdefg', 'utf8');
socket.emit('buff', buf);
});
});
@@ -1168,7 +1168,7 @@ describe('socket.io', function(){
});
fs.readFile(join(__dirname, 'support', 'doge.jpg'), function(err, data){
if (err) return done(err);
var buf = new Buffer('asdfasdf', 'utf8');
var buf = Buffer.from('asdfasdf', 'utf8');
socket.emit('multiple', 1, data, '3', [4], buf, [data, 'swag', buf]);
});
});
@@ -1496,7 +1496,7 @@ describe('socket.io', function(){
expect(Buffer.isBuffer(buf)).to.be(true);
fn(1, 2);
});
socket.emit('woot', new Buffer(3), function(a, b){
socket.emit('woot', Buffer.alloc(3), function(a, b){
expect(a).to.be(1);
expect(b).to.be(2);
done();
@@ -1515,7 +1515,7 @@ describe('socket.io', function(){
expect(Buffer.isBuffer(a)).to.be(true);
fn();
});
s.emit('hi', new Buffer(4), function(){
s.emit('hi', Buffer.alloc(4), function(){
done();
});
});
@@ -1529,7 +1529,7 @@ describe('socket.io', function(){
var socket = client(srv);
sio.on('connection', function(s){
socket.on('hi', function(fn){
fn(new Buffer(1));
fn(Buffer.alloc(1));
});
s.emit('hi', function(a){
expect(Buffer.isBuffer(a)).to.be(true);
@@ -1546,7 +1546,7 @@ describe('socket.io', function(){
var socket = client(srv);
sio.on('connection', function(s){
s.on('woot', function(fn){
fn(new Buffer(2));
fn(Buffer.alloc(2));
});
socket.emit('woot', function(a){
expect(Buffer.isBuffer(a)).to.be(true);
@@ -1621,8 +1621,25 @@ describe('socket.io', function(){
expect(s.handshake.query.key2).to.be('&=bb');
done();
});
});
it('should see the query options sent in the Socket.IO handshake (specific to the given socket)', (done) => {
const srv = http();
const sio = io(srv);
const socket = client(srv, '/namespace',{ query: { key1: 'a', key2: 'b' }}); // manager-specific query option
socket.query = { key2: 'c' }; // socket-specific query option
const success = () => {
sio.close();
socket.close();
done();
}
sio.of('/namespace').on('connection', (s) => {
expect(s.handshake.query.key1).to.be('a'); // in the query params
expect(s.handshake.query.key2).to.be('c'); // in the Socket.IO handshake
success();
});
});
it('should handle very large json', function(done){
@@ -1899,7 +1916,7 @@ describe('socket.io', function(){
});
function emit(){
sio.emit('bin', new Buffer(10));
sio.emit('bin', Buffer.alloc(10));
}
});
});
@@ -2083,8 +2100,8 @@ describe('socket.io', function(){
socket.join(room, fn);
});
socket.on('broadcast', function(){
socket.broadcast.to('test').emit('bin', new Buffer(5));
socket.emit('bin2', new Buffer(5));
socket.broadcast.to('test').emit('bin', Buffer.alloc(5));
socket.emit('bin2', Buffer.alloc(5));
});
});
});