7687 Commits

Author SHA1 Message Date
Sean Oxley
3144d27458 fix(uws): discard any write to an aborted uWS response (#682)
This bug only exists for polling transport connections running on top
of uWS.

If the remote client abruptly disconnects (thus aborting the request)
while the server is waiting on an asynchronous operation such as
compression, the server may attempt to write a response via the aborted
response object. This causes an uncaught exception to be thrown.
2023-05-31 14:27:40 +02:00
Damien Arrachequesne
01d37624a8 docs(changelog): update the version range of the engine.io dependency 2023-05-31 11:28:00 +02:00
Damien Arrachequesne
faf914c9ab chore(release): 4.6.2
Diff: https://github.com/socketio/socket.io/compare/4.6.1...4.6.2
4.6.2
2023-05-31 11:15:41 +02:00
Damien Arrachequesne
a04ae1b094 chore(release): 4.6.2
Diff: https://github.com/socketio/socket.io-client/compare/4.6.1...4.6.2
2023-05-31 11:07:13 +02:00
Damien Arrachequesne
7c1db9d225 chore: bump socket.io-parser to version 4.2.3
Reference: https://github.com/advisories/GHSA-cqmj-92xf-r6r9
2023-05-31 11:02:00 +02:00
Damien Arrachequesne
164ba2a11e chore(release): 4.2.4
Diff: https://github.com/socketio/socket.io-parser/compare/4.2.3...4.2.4
socket.io-parser@4.2.4
2023-05-31 10:56:08 +02:00
Damien Arrachequesne
b0e6400c93 fix: properly detect plain objects
The typeof check was not sufficient, as it also matches arrays and
nulls.
2023-05-31 10:44:05 +02:00
Damien Arrachequesne
d9db4737a3 fix: ensure reserved events cannot be used as event names 2023-05-31 08:29:52 +02:00
Damien Arrachequesne
61dea7135f refactor: remove invalid comma from package.json 2023-05-25 15:00:46 +02:00
Damien Arrachequesne
0fc3694a13 chore(release): 5.0.7
Diff: https://github.com/socketio/engine.io-parser/compare/5.0.6...5.0.7
2023-05-24 14:50:09 +02:00
Damien Arrachequesne
e4a1c2b082 refactor: export typescript declarations for the commonjs build
Related:

- https://github.com/socketio/socket.io/issues/4621#issuecomment-1551853243
- https://github.com/socketio/engine.io-parser/issues/129
2023-05-24 14:43:54 +02:00
Damien Arrachequesne
15af22fc22 refactor: add a noop handler for the error event
We should reduce the scope of the "event" error in the next major
version, as it is overloaded today:

- it can be sent by the client (`socket.emit("error")`, which is a perfectly valid event name)
- it can be emitted when the connection encounters an error (an invalid packet for example)
- it can be emitted when a packet is rejected in a middleware (`socket.use()`)

Related: https://github.com/socketio/socket.io/issues/2047
2023-05-24 10:47:52 +02:00
Damien Arrachequesne
d3658944e5 chore: bump socket.io-parser to version 4.2.3
Reference: https://github.com/advisories/GHSA-cqmj-92xf-r6r9
2023-05-24 07:27:12 +02:00
Damien Arrachequesne
db3de84ad5 docs(security): update the list of CVE 2023-05-23 08:48:13 +02:00
Damien Arrachequesne
7bd77759bd docs: update the list of CVE 2023-05-23 08:40:03 +02:00
Damien Arrachequesne
6a5a004d1e docs(changelog): include changelog for release 3.4.3 2023-05-22 10:06:05 +02:00
Damien Arrachequesne
b6c824f824 chore(release): 4.2.3
Diff: https://github.com/socketio/socket.io-parser/compare/4.2.2...4.2.3
2023-05-22 08:25:34 +02:00
Damien Arrachequesne
dcc70d9678 refactor: export typescript declarations for the commonjs build
Related: https://github.com/socketio/socket.io/issues/4621#issuecomment-1551853243
2023-05-22 08:25:34 +02:00
Damien Arrachequesne
3b78117bf6 fix: check the format of the event name
A packet like '2[{"toString":"foo"}]' was decoded as:

{
  type: EVENT,
  data: [ { "toString": "foo" } ]
}

Which would then throw an error when passed to the EventEmitter class:

> TypeError: Cannot convert object to primitive value
>    at Socket.emit (node:events:507:25)
>    at .../node_modules/socket.io/lib/socket.js:531:14

History of the isPayloadValid() method:

- added in [78f9fc2](78f9fc2999) (v4.0.1, socket.io@3.0.0)
- updated in [1c220dd](1c220ddbf4) (v4.0.4, socket.io@3.1.0)
2023-05-22 08:25:33 +02:00
Damien Arrachequesne
12b0de4f52 chore: bump engine.io to version 6.4.2
Reference: https://github.com/advisories/GHSA-q9mw-68c2-j6m5

Related: https://github.com/socketio/socket.io/issues/4711
2023-05-10 10:20:42 +02:00
Mateusz Burzyński
7ead241ecf fix(exports): move types condition to the top (#1580)
Related: https://github.com/microsoft/TypeScript/issues/50762
2023-05-04 07:29:00 +02:00
Mateusz Burzyński
3d44aae381 fix(exports): move types condition to the top (#4698)
Related: https://github.com/microsoft/TypeScript/issues/50762
2023-05-04 07:27:09 +02:00
Damien Arrachequesne
cbf0362476 docs(examples): bump dependencies for the private messaging example
Related: https://github.com/socketio/socket.io/issues/4681
2023-05-02 18:07:07 +02:00
Damien Arrachequesne
95e215387c chore(release): 6.4.2
Diff: https://github.com/socketio/engine.io/compare/6.4.1...6.4.2
2023-05-02 01:27:20 +02:00
Damien Arrachequesne
fc480b4f30 fix: prevent crash when provided with an invalid query param
A specially crafted request could lead to the following exception:

> TypeError: Cannot read properties of undefined (reading 'handlesUpgrades')
>    at Server.onWebSocket (build/server.js:515:67)

This bug was introduced in [1], released in version 5.1.0 and included
in version 4.1.0 of the `socket.io` parent package. Older versions are
not impacted.

[1]: 7096e98a02
2023-05-02 01:07:40 +02:00
Damien Arrachequesne
0141951185 refactor(types): ensure compatibility with Express middlewares
In order to prevent issues like:

> error TS2345: Argument of type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' is not assignable to parameter of type 'Middleware'.
>  Types of parameters 'req' and 'req' are incompatible.
>  Type 'IncomingMessage' is missing the following properties from type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>': get, header, accepts, acceptsCharsets, and 29 more.
>
>  io.engine.use(sessionMiddleware);
                 ~~~~~~~~~~~~~~~~~

Related: https://github.com/socketio/socket.io/issues/4644

We could also have use the RequestHandler type from the
@types/express-serve-static-core package, but that would add 5 new
dependencies.

See also: https://github.com/socketio/engine.io/issues/673
2023-05-02 00:51:33 +02:00
Damien Arrachequesne
8b22162903 fix(uws): prevent crash when using with middlewares
The class used to accumulate the response headers did not expose the
exact same API as its wrapped type, which could lead to the following
error in some rare cases:

> TypeError: Cannot read properties of undefined (reading 'end')
>    at Polling.onDataRequest (build/transports-uws/polling.js:109:53)
>    at Polling.onRequest (build/transports-uws/polling.js:47:18)
>    at callback (build/userver.js:94:56)
>    at uServer.verify (build/server.js:152:9)

Related: https://github.com/socketio/socket.io/issues/4643
2023-05-02 00:50:34 +02:00
Ciel
93957828be fix: include error handling for Express middlewares (#674)
Following 24786e77c5.

Reference: https://expressjs.com/en/guide/error-handling.html
2023-05-02 00:00:47 +02:00
Damien Arrachequesne
911d0e3575 refactor: return HTTP 400 upon invalid request overlap
In both cases, the error comes from the client as it should not send
multiple concurrent requests, so a HTTP 4xx code is mandated.

Related: https://github.com/socketio/engine.io/issues/650
2023-05-01 07:42:43 +02:00
Asger Hautop Drewsen
bd6d4713b0 fix(typings): make clientsCount public (#675)
Related: https://github.com/socketio/engine.io/issues/672
2023-04-19 23:25:16 +03:00
Damien Arrachequesne
59280da20b docs(examples): update examples to docker compose v2
Reference: https://docs.docker.com/compose/

Related: https://github.com/socketio/socket.io/discussions/4669
2023-04-07 15:57:20 +02:00
Damien Arrachequesne
d0c0557c1b docs(changelog): add version of transitive dependencies 2023-03-27 17:55:46 +02:00
Damien Arrachequesne
50a4d37cb8 docs(changelog): add version of transitive dependencies 2023-03-27 17:35:42 +02:00
Damien Arrachequesne
cddb78e5fa chore(release): 0.2.2
Diff: https://github.com/socketio/socket.io-cluster-adapter/compare/0.2.1...0.2.2
2023-03-24 17:32:35 +01:00
Damien Arrachequesne
15fd56e78d chore: add socket.io-parser to peerDependencies
This should (at least in theory) fix sync issues for the
`socket.io-adapter` package, which is imported by both the `socket.io`
and `@socket.io/cluster-adapter` packages:

- `socket.io@4.5.0` should resolve `socket.io-adapter@~2.4.0`
- `socket.io@4.6.0` should resolve `socket.io-adapter@~2.5.0`
2023-03-24 17:28:57 +01:00
Damien Arrachequesne
e86ef45f87 ci: upgrade to actions/checkout@3 and actions/setup-node@3
Reference: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/
2023-03-24 17:16:25 +01:00
Damien Arrachequesne
6458b2bef1 docs(example): basic WebSocket-only client 2023-03-24 11:17:29 +01:00
Damien Arrachequesne
b56da8a99f docs(examples): upgrade to React 18
Reference: https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html
2023-03-07 08:31:21 +01:00
Damien Arrachequesne
7952312911 chore(release): 4.6.1
Diff: https://github.com/socketio/socket.io/compare/4.6.0...4.6.1
4.6.1
2023-02-20 17:49:41 +01:00
Damien Arrachequesne
89175d0481 chore(release): 4.6.1
Diff: https://github.com/socketio/socket.io-client/compare/4.6.0...4.6.1
2023-02-20 17:46:20 +01:00
Damien Arrachequesne
121fd7c73d refactor: do not reuse the same packet ID for retries
The packet ID cannot be used for deduplication, because it's only
unique for the given session. If you reconnect on another server and
try to resend a packet, then the server won't be able to know whether
the packet has already been processed or not.
2023-02-20 17:31:02 +01:00
Damien Arrachequesne
46213a647e fix: prevent duplicate connections when multiplexing
This bug was introduced in [1]: a multiplexed socket could in some
cases send multiple CONNECT packets, resulting in duplicate connections
on the server side.

A cached socket will now be reopened only if it was inactive, that is,
if one had explicitly called socket.disconnect() before.

Related: https://github.com/socketio/socket.io-client/issues/1460

[1]: b7dd891e89
2023-02-20 17:09:50 +01:00
Damien Arrachequesne
4996f9ee71 fix: do not drain the queue while the socket is offline
In the previous implementation added in [1], the socket would try to
send the packet even if it was disconnected, which would needlessly
exhaust the number of retries.

[1]: 655dce9755
2023-02-20 17:01:22 +01:00
Damien Arrachequesne
0d0a7a22b5 fix: properly handle manually created dynamic namespaces
Namespaces that match the regex of a parent namespace will now be added
as a child of this namespace:

```js
const parentNamespace = io.of(/^\/dynamic-\d+$/);
const childNamespace = io.of("/dynamic-101");
```

Related:

- https://github.com/socketio/socket.io/issues/4615
- https://github.com/socketio/socket.io/issues/4164
- https://github.com/socketio/socket.io/issues/4015
- https://github.com/socketio/socket.io/issues/3960
2023-02-20 01:19:01 +01:00
Damien Arrachequesne
2a8565fd1e refactor: catch errors when trying to restore the connection state 2023-02-20 01:18:08 +01:00
Igor Lins e Silva
d0b22c6302 fix(types): fix nodenext module resolution compatibility (#4625)
The import added in [1] was invalid, because it used an non-exported
class.

Related: https://github.com/socketio/socket.io/issues/4621

[1]: d4a9b2cdcb
2023-02-20 01:15:35 +01:00
Damien Arrachequesne
7033c0ed27 chore(release): 6.4.1
Diff: https://github.com/socketio/engine.io/compare/6.4.0...6.4.1
2023-02-20 00:54:54 +01:00
Igor Lins e Silva
6e78489486 refactor: export BaseServer class (#669)
Related: https://github.com/socketio/socket.io/issues/4621
2023-02-17 23:24:50 +01:00
Nabaraj Subedi
e71f3d7dbe docs: minor style fix (#4619) 2023-02-16 09:25:43 +01:00
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