Commit Graph

1192 Commits

Author SHA1 Message Date
Damien Arrachequesne
535b068670 docs: add upgrade event in the documentation
Reference: 898bd1c9df/lib/socket.ts (L285)

Related: https://github.com/socketio/socket.io-website/issues/369
2023-02-14 15:25:57 +01:00
Damien Arrachequesne
898bd1c9df chore(release): 6.4.0
Diff: https://github.com/socketio/engine.io/compare/6.3.1...6.4.0
2023-02-06 17:16:32 +01:00
dependabot[bot]
6220d140cc chore(deps): bump cookiejar from 2.1.2 to 2.1.4 (#667)
Bumps [cookiejar](https://github.com/bmeck/node-cookiejar) from 2.1.2 to 2.1.4.
- [Release notes](https://github.com/bmeck/node-cookiejar/releases)
- [Commits](https://github.com/bmeck/node-cookiejar/commits)

---
updated-dependencies:
- dependency-name: cookiejar
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-06 17:06:11 +01:00
Damien Arrachequesne
24786e77c5 feat: add support for Express middlewares
This commit implements middlewares at the Engine.IO level, because
Socket.IO middlewares are meant for namespace authorization and are not
executed during a classic HTTP request/response cycle.

A workaround was possible by using the allowRequest option and the
"headers" event, but this feels way cleaner and works with upgrade
requests too.

Syntax:

```js
engine.use((req, res, next) => {
  // do something

  next();
});

// with express-session
import session from "express-session";

engine.use(session({
  secret: "keyboard cat",
  resave: false,
  saveUninitialized: true,
  cookie: { secure: true }
});

// with helmet
import helmet from "helmet";

engine.use(helmet());
```

Related:

- https://github.com/socketio/engine.io/issues/668
- https://github.com/socketio/engine.io/issues/651
- https://github.com/socketio/socket.io/issues/4609
- https://github.com/socketio/socket.io/issues/3933
- a lot of other issues asking for compatibility with express-session
2023-02-06 17:01:27 +01:00
Damien Arrachequesne
4d6f4541c3 chore(release): 6.3.1
Diff: https://github.com/socketio/engine.io/compare/6.3.0...6.3.1
2023-01-12 08:23:07 +01:00
Damien Arrachequesne
69603b955a refactor: make the compress option optional
The compress option was inadvertently made mandatory in [1].

[1]: 6d87a4065a
2023-01-12 08:15:21 +01:00
Damien Arrachequesne
ae1ea77991 chore(release): 6.3.0
Diff: https://github.com/socketio/engine.io/compare/6.2.1...6.3.0
2023-01-10 17:28:24 +01:00
Damien Arrachequesne
a65a047526 fix: wait for all packets to be sent before closing the WebSocket connection
This reverts commit [1], which was included in `engine.io@5.1.0` and
`socket.io@4.1.0`.

The WebSocket connection was closed before all packets were written
out, so for example when calling `socket.disconnect(true)` on the
Socket.IO server (which disconnect from all namespaces and close the
connection), the client would receive only the first disconnect packet
and kept trying to reconnect to the other namespaces.

The only difference with the previous implementation (pre 5.1.0) is
that the "drain" event gets only called once at the end, and not after
each packet.

[1]: ad5306aeae

Related: https://github.com/socketio/engine.io/issues/648
2023-01-10 16:42:12 +01:00
Damien Arrachequesne
ed87609baf fix: fix the ES module wrapper
The package does not have a default export, so importing it from a
project using ES modules would break in some cases.

> Cannot destructure property 'Server' of '_engineIo.default'

Related: https://github.com/socketio/engine.io/issues/657
2023-01-10 15:28:43 +01:00
Damien Arrachequesne
bc98bf1232 refactor: bump prettier to version 2.8.1
This major bump creates a lot of noise, but it is necessary for
prettier to be able to parse new syntax such as:

- typed imports: `import { type xxx } from ...`
- private attributes: `class A { #b; #c() {} }`
2023-01-10 15:22:57 +01:00
Damien Arrachequesne
33dc073172 docs: add some TODOs for the next major release 2023-01-10 14:57:58 +01:00
iifawzi
d0fd4746af feat: add the "addTrailingSlash" option (#655)
The "addTrailingSlash" option allows to control whether a trailing
slash is added to the path of the HTTP requests:

- true (default): "/engine.io/"
- false: "/engine.io"

Related: 21a6e1219a

Signed-off-by: iifawzi <iifawzie@gmail.com>
2023-01-10 14:51:31 +01:00
Damien Arrachequesne
5e34722b0b perf: add the wsPreEncodedFrame option
This optimization is only applied if:

- the permessage-deflate extension is disabled (which is the default)
- the "ws" package is used (which is the default)

In that case, the WebSocket frame will only be computed once, when
broadcasting to multiple clients.

Related: 5f7b47d40f
2023-01-09 10:34:25 +01:00
dependabot[bot]
8a937a4006 chore(deps): bump qs and express in /examples/latency (#665)
Bumps [qs](https://github.com/ljharb/qs) to 6.11.0 and updates ancestor dependency [express](https://github.com/expressjs/express). These dependencies need to be updated together.


Updates `qs` from 6.7.0 to 6.11.0
- [Release notes](https://github.com/ljharb/qs/releases)
- [Changelog](https://github.com/ljharb/qs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ljharb/qs/compare/v6.7.0...v6.11.0)

Updates `express` from 4.17.1 to 4.18.2
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/master/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.17.1...4.18.2)

---
updated-dependencies:
- dependency-name: qs
  dependency-type: indirect
- dependency-name: express
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-14 10:15:52 +01:00
dependabot[bot]
719e275ff7 chore(deps): bump qs from 6.9.4 to 6.11.0 (#664)
Bumps [qs](https://github.com/ljharb/qs) from 6.9.4 to 6.11.0.
- [Release notes](https://github.com/ljharb/qs/releases)
- [Changelog](https://github.com/ljharb/qs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ljharb/qs/compare/v6.9.4...v6.11.0)

---
updated-dependencies:
- dependency-name: qs
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-14 10:15:26 +01:00
dependabot[bot]
8f8b217f1c chore(deps): bump engine.io from 4.1.2 to 6.2.1 in /examples/latency (#663)
Bumps [engine.io](https://github.com/socketio/engine.io) from 4.1.2 to 6.2.1.
- [Release notes](https://github.com/socketio/engine.io/releases)
- [Changelog](https://github.com/socketio/engine.io/blob/main/CHANGELOG.md)
- [Commits](https://github.com/socketio/engine.io/compare/4.1.2...6.2.1)

---
updated-dependencies:
- dependency-name: engine.io
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-14 10:15:12 +01:00
Damien Arrachequesne
da45d84c09 chore: bump ws to version 8.11.0
Diff: https://github.com/websockets/ws/compare/8.2.3...8.11.0
2022-12-14 07:58:30 +01:00
Damien Arrachequesne
bd74e7c988 chore: add security policy 2022-12-14 07:42:42 +01:00
Damien Arrachequesne
6d87a4065a refactor: add types to socket.send()
Related: https://github.com/socketio/engine.io/issues/645
2022-12-06 00:31:02 +01:00
Damien Arrachequesne
3d28229cf0 docs: add note about socket.id
Related: https://github.com/socketio/engine.io/issues/644
2022-12-05 23:57:32 +01:00
Damien Arrachequesne
d7bd2b1d52 docs: add changelog for version 3.6.1 2022-11-20 03:06:58 +01:00
Damien Arrachequesne
24b847be6a chore(release): 6.2.1
Diff: https://github.com/socketio/engine.io/compare/6.2.0...6.2.1
2022-11-20 02:14:27 +01:00
Jonathan Neve
425e833ab1 fix: catch errors when destroying invalid upgrades (#658)
Before this change, receiving an HTTP2 upgrade would make the server
crash:

> Error: read ECONNRESET
>    at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
>  errno: -104,
>  code: 'ECONNRESET',
>  syscall: 'read'
> }

This can be reproduced with Node.js v14.15.3, v16.18.1 and v18.12.1.
2022-11-20 01:55:11 +01:00
dependabot[bot]
99adb00ba1 chore(deps): bump xmlhttprequest-ssl and engine.io-client in /examples/latency (#661)
Bumps [xmlhttprequest-ssl](https://github.com/mjwwit/node-XMLHttpRequest) to 1.6.3 and updates ancestor dependency [engine.io-client](https://github.com/socketio/engine.io-client). These dependencies need to be updated together.


Updates `xmlhttprequest-ssl` from 1.5.5 to 1.6.3
- [Release notes](https://github.com/mjwwit/node-XMLHttpRequest/releases)
- [Commits](https://github.com/mjwwit/node-XMLHttpRequest/compare/1.5.5...1.6.3)

Updates `engine.io-client` from 4.0.0 to 4.1.4
- [Release notes](https://github.com/socketio/engine.io-client/releases)
- [Changelog](https://github.com/socketio/engine.io-client/blob/main/CHANGELOG.md)
- [Commits](https://github.com/socketio/engine.io-client/compare/4.0.0...4.1.4)

---
updated-dependencies:
- dependency-name: xmlhttprequest-ssl
  dependency-type: indirect
- dependency-name: engine.io-client
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-20 00:46:22 +01:00
dependabot[bot]
d196f6a6b7 chore(deps): bump minimatch from 3.0.4 to 3.1.2 (#660)
Bumps [minimatch](https://github.com/isaacs/minimatch) from 3.0.4 to 3.1.2.
- [Release notes](https://github.com/isaacs/minimatch/releases)
- [Commits](https://github.com/isaacs/minimatch/compare/v3.0.4...v3.1.2)

---
updated-dependencies:
- dependency-name: minimatch
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-20 00:43:47 +01:00
dependabot[bot]
7c1270f98c chore(deps): bump nanoid from 3.1.25 to 3.3.1 (#659)
Bumps [nanoid](https://github.com/ai/nanoid) from 3.1.25 to 3.3.1.
- [Release notes](https://github.com/ai/nanoid/releases)
- [Changelog](https://github.com/ai/nanoid/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ai/nanoid/compare/3.1.25...3.3.1)

---
updated-dependencies:
- dependency-name: nanoid
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-20 00:43:37 +01:00
Damien Arrachequesne
535a01d889 ci: add Node.js 18 in the test matrix
A few notes:

- the certificates were recreated because Node.js 18 includes OpenSSL
v3, which has deprecated support for some legacy ciphers (like RC2)

- eiows currently fails to build on Node.js 18, so the tests are
temporarily skipped

See also: https://github.com/nodejs/Release
2022-11-20 00:20:30 +01:00
Tamas Flamich
1b71a6f5cb docs: remove "Vanilla JS" highlight from README (#656) 2022-11-18 21:49:23 +01:00
Lam Wei Li
917d1d29e1 refactor: replace deprecated String.prototype.substr() (#646)
`.substr()` is deprecated so we replace it with `.slice()` which works
similarily but isn't deprecated.

See also: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr

Signed-off-by: Lam Wei Li <peteriman@mail.com>
2022-06-06 08:42:45 +02:00
Damien Arrachequesne
020801ab8c chore: add changelog for version 3.6.0
Diff: https://github.com/socketio/engine.io/compare/3.5.0...3.6.0
2022-06-06 08:40:21 +02:00
Lucas Boemeke
ed1d6f912c test: make test script work on Windows (#643) 2022-05-11 09:00:17 +02:00
Damien Arrachequesne
d7e3ab7956 chore(release): 6.2.0
Diff: https://github.com/socketio/engine.io/compare/6.1.3...6.2.0
2022-04-17 23:53:53 +02:00
Damien Arrachequesne
088dcb4dff feat: add the "maxPayload" field in the handshake details
So that clients in HTTP long-polling can decide how many packets they
have to send to stay under the maxHttpBufferSize value.

This is a backward compatible change which should not mandate a new
major revision of the protocol (we stay in v4), as we only add a field
in the JSON-encoded handshake data:

```
0{"sid":"lv_VI97HAXpY6yYWAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000,"maxPayload":1000000}
```

Related: https://github.com/socketio/socket.io-client/issues/1531
2022-03-10 14:20:54 +01:00
Damien Arrachequesne
657f04e0b8 chore: add Node.js 16 in the test matrix
See also: https://github.com/nodejs/Release
2022-03-10 14:20:36 +01:00
Damien Arrachequesne
e24b27b8ef refactor: return an HTTP 413 response for too large payloads
Before this, the connection was closed abrutly with an HTTP 502
response.

See also: f8100f9237

Related: https://github.com/socketio/socket.io/issues/4293
2022-02-28 07:21:53 +01:00
Damien Arrachequesne
ce3fe9d80b chore(release): 6.1.3
Diff: https://github.com/socketio/engine.io/compare/6.1.2...6.1.3
2022-02-23 07:40:31 +01:00
Damien Arrachequesne
1bc5b1a2fd chore: bump engine.io-parser to version 5.0.3
In order to make sure the types added in [1] are included.

Related:

- https://github.com/socketio/engine.io/issues/639
- https://github.com/socketio/engine.io/issues/640

[1]: ad5bd7ddf5
2022-02-23 07:36:58 +01:00
e3dio
5df4f18f3e perf(uws): remove nested inner functions 2022-02-23 07:16:25 +01:00
e3dio
3367440308 fix(uws): properly handle chunked content (#642)
With the engine based on µWebSockets.js (introduced in version 6.1.0),
a huge request body split in multiple chunks would throw the following
error:

> node:buffer:254
>   TypedArrayPrototypeSet(target, source, targetStart);
>   ^
>
> TypeError: Cannot perform %TypedArray%.prototype.set on a detached ArrayBuffer
>     at Buffer.set (<anonymous>)
>     at _copyActual (node:buffer:254:3)
> node:buffer:254
>   TypedArrayPrototypeSet(target, source, targetStart);
>   ^
>
> TypeError: Cannot perform %TypedArray%.prototype.set on a detached ArrayBuffer
>     at Buffer.set (<anonymous>)
>     at _copyActual (node:buffer:254:3)
>     at Function.concat (node:buffer:562:12)
>     at onEnd (.../node_modules/engine.io/build/transports-uws/polling.js:126:32)
>     at .../node_modules/engine.io/build/transports-uws/polling.js:143:17

Note: µWebSockets.js does not currently support chunked transfer
encoding.
2022-02-23 07:16:25 +01:00
Jeffrey van Norden
a463d268ed fix(typings): allow CorsOptionsDelegate as cors options (#641)
Reference: https://www.npmjs.com/package/cors#configuring-cors-asynchronously

Related: 54a59cd8f0
2022-02-17 06:36:49 +01:00
Damien Arrachequesne
90fb0a99ac chore(release): 6.1.2
Diff: https://github.com/socketio/engine.io/compare/6.1.1...6.1.2
2022-01-18 18:00:23 +01:00
Damien Arrachequesne
e122e4be7b refactor: add additional types
Merged from https://github.com/socketio/engine.io/pull/630
2022-01-18 17:55:55 +01:00
Damien Arrachequesne
3f1e312a2c chore: bump package-lock.json file version
Note to future self: URL for dependencies from GitHub must use
"git+https" instead of "git+ssh" to make the CI pass, else you will
encounter the following error:

```
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git@github.com/uNetworking/uWebSockets.js.git
npm ERR!
npm ERR! Warning: Permanently added the RSA host key for IP address '140.82.112.3' to the list of known hosts.
npm ERR! git@github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128
```
2022-01-18 17:53:58 +01:00
Damien Arrachequesne
45112a30d1 fix(uws): fix HTTP long-polling with CORS
When binding to an uWebSockets.js application, the server could crash
with the following error:

```
TypeError: res.onData is not a function
    at Polling.onDataRequest (build/transports-uws/polling.js:133:13)
    at Polling.onRequest (build/transports-uws/polling.js:47:18)
    at callback (build/userver.js:80:56)
```

Related: https://github.com/socketio/engine.io/issues/637
2022-01-18 17:49:28 +01:00
Yosi Attias
49bb7cf665 fix(uws): expose additional uWebSockets.js options (#634)
You can now pass additional options:

```js
const { App } = require("uWebSockets.js");
const { uServer } = require("engine.io");

const app = new App();
const server = new uServer();

server.attach(app, {
  compression: uWS.DEDICATED_COMPRESSOR_128KB, // defaults to none
  idleTimeout: 60, // defaults to 120
  maxBackpressure: 8 * 1024 // defaults to 1024 * 1024
});

app.listen(3000);
```

Related: https://github.com/socketio/engine.io/issues/633
2022-01-14 08:57:46 +01:00
Damien Arrachequesne
8b4d6a8176 fix(uws): handle invalid websocket upgrades
When binding to an uWebSockets.js App, there was an unhandled case that
could crash the server:

```
curl "http://localhost:3000/engine.io/?EIO=4&transport=websocket"
```

would result in:

```
Error: Returning from a request handler without responding or attaching an abort handler is forbidden!
terminate called without an active exception
```

Note: this does not apply to the default server based on ws, because
the error was caught elsewhere in the source code.

Related: https://github.com/socketio/socket.io/issues/4250
2022-01-14 08:18:03 +01:00
dependabot[bot]
a84595a04e chore(deps): bump engine.io from 4.0.0 to 4.1.2 in /examples/latency (#636)
Bumps [engine.io](https://github.com/socketio/engine.io) from 4.0.0 to 4.1.2.
- [Release notes](https://github.com/socketio/engine.io/releases)
- [Changelog](https://github.com/socketio/engine.io/blob/4.1.2/CHANGELOG.md)
- [Commits](https://github.com/socketio/engine.io/compare/4.0.0...4.1.2)

---
updated-dependencies:
- dependency-name: engine.io
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-01-14 07:59:43 +01:00
Damien Arrachequesne
f3b761dc56 chore(release): 6.1.1
Diff: https://github.com/socketio/engine.io/compare/6.1.0...6.1.1
2022-01-11 16:08:20 +01:00
Damien Arrachequesne
c0e194d449 fix: properly handle invalid data sent by a malicious websocket client
**IMPORTANT SECURITY FIX**

A malicious client could send a specially crafted HTTP request,
triggering an uncaught exception and killing the Node.js process:

> RangeError: Invalid WebSocket frame: RSV2 and RSV3 must be clear
>   at Receiver.getInfo (/.../node_modules/ws/lib/receiver.js:176:14)
>   at Receiver.startLoop (/.../node_modules/ws/lib/receiver.js:136:22)
>   at Receiver._write (/.../node_modules/ws/lib/receiver.js:83:10)
>   at writeOrBuffer (internal/streams/writable.js:358:12)

This bug was introduced by [1], included in `engine.io@4.0.0`, so
previous releases are not impacted.

[1]: f3c291fa61

Thanks to Marcus Wejderot from Mevisio for the responsible disclosure.
2022-01-11 15:52:15 +01:00
Jeff Winder
b04967b52e refactor: import Node's setTimeout & clearTimeout to prevent ambiguity (#632) 2021-12-14 09:09:23 +01:00