From c6bf8c0f571aad7a5917f43860c8c3d74a9b429b Mon Sep 17 00:00:00 2001 From: Avi Vahl Date: Thu, 17 Aug 2023 08:59:32 +0300 Subject: [PATCH 1/4] fix: improve compatibility with node16 module resolution (#689) Related: https://github.com/microsoft/TypeScript/issues/46770#issuecomment-966612103 --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 5753cdc1..39f79955 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "main": "./build/engine.io.js", "types": "./build/engine.io.d.ts", "exports": { + "types": "./build/engine.io.d.ts", "import": "./wrapper.mjs", "require": "./build/engine.io.js" }, From ff1c8615483bab25acc9cf04fb40339b0bd78812 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Thu, 5 Oct 2023 16:56:11 +0200 Subject: [PATCH 2/4] fix(webtransport): properly handle abruptly closed connections Refreshing the page with a client connected with WebTransport would trigger the following exception: > node:internal/process/promises:288 > triggerUncaughtException(err, true /* fromPromise */); > ^ > > [UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "0".] { > code: 'ERR_UNHANDLED_REJECTION' > } Related: https://github.com/socketio/engine.io/issues/688 --- lib/transports/webtransport.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/transports/webtransport.ts b/lib/transports/webtransport.ts index 4f6f6877..5922fab0 100644 --- a/lib/transports/webtransport.ts +++ b/lib/transports/webtransport.ts @@ -14,7 +14,9 @@ export class WebTransport extends Transport { super({ _query: { EIO: "4" } }); const transformStream = createPacketEncoderStream(); - transformStream.readable.pipeTo(stream.writable); + transformStream.readable.pipeTo(stream.writable).catch(() => { + debug("the stream was closed"); + }); this.writer = transformStream.writable.getWriter(); (async () => { From 9545b44b3cccc1e2ff51c126d0d759571e22b3a6 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Thu, 5 Oct 2023 17:14:09 +0200 Subject: [PATCH 3/4] refactor: add cache-control header in the polling response This header should not be needed since the client already includes a cache busting query parameter ("t"), but a misconfigured CDN could ignore the query parameters and cache the server response. Related: https://github.com/socketio/socket.io/issues/4842 --- lib/transports-uws/polling.ts | 2 ++ lib/transports/polling.ts | 2 ++ test/server.js | 22 +++++++++++++++++----- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/transports-uws/polling.ts b/lib/transports-uws/polling.ts index ce503a8a..4ce6e52f 100644 --- a/lib/transports-uws/polling.ts +++ b/lib/transports-uws/polling.ts @@ -423,6 +423,8 @@ export class Polling extends Transport { headers["X-XSS-Protection"] = "0"; } + headers["cache-control"] = "no-store"; + this.emit("headers", headers, req); return headers; } diff --git a/lib/transports/polling.ts b/lib/transports/polling.ts index 70be3411..f0edcdc8 100644 --- a/lib/transports/polling.ts +++ b/lib/transports/polling.ts @@ -392,6 +392,8 @@ export class Polling extends Transport { headers["X-XSS-Protection"] = "0"; } + headers["cache-control"] = "no-store"; + this.emit("headers", headers, req); return headers; } diff --git a/test/server.js b/test/server.js index fa0ab9c0..a373837e 100644 --- a/test/server.js +++ b/test/server.js @@ -3443,13 +3443,12 @@ describe("server", () => { }); describe("response headers", () => { - function testForHeaders(headers, done) { + function testForHeaders(headers, callback) { const engine = listen((port) => { engine.on("connection", (conn) => { conn.transport.once("headers", (headers) => { - expect(headers["X-XSS-Protection"]).to.be("0"); + callback(headers); conn.close(); - done(); }); conn.send("hi"); }); @@ -3465,7 +3464,10 @@ describe("server", () => { "user-agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Tablet PC 2.0)", }; - testForHeaders(headers, done); + testForHeaders(headers, (headers) => { + expect(headers["X-XSS-Protection"]).to.be("0"); + done(); + }); }); it("should contain X-XSS-Protection: 0 for IE11", (done) => { @@ -3473,7 +3475,17 @@ describe("server", () => { "user-agent": "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko", }; - testForHeaders(headers, done); + testForHeaders(headers, (headers) => { + expect(headers["X-XSS-Protection"]).to.be("0"); + done(); + }); + }); + + it("should include a 'cache-control' header", (done) => { + testForHeaders({}, (headers) => { + expect(headers["cache-control"]).to.be("no-store"); + done(); + }); }); it("should emit a 'initial_headers' event (polling)", (done) => { From 2da559a8fa8376a835bfaedfb13ef075414af306 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Fri, 6 Oct 2023 10:20:34 +0200 Subject: [PATCH 4/4] chore(release): 6.5.3 Diff: https://github.com/socketio/engine.io/compare/6.5.2...6.5.3 --- CHANGELOG.md | 16 ++++++++++++++++ package.json | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1df1a2ad..ac452545 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 2023 +- [6.5.3](#653-2023-10-06) (Oct 2023) - [6.5.2](#652-2023-08-01) (Aug 2023) - [6.5.1](#651-2023-06-27) (Jun 2023) - [6.5.0](#650-2023-06-16) (Jun 2023) @@ -50,6 +51,21 @@ # Release notes +## [6.5.3](https://github.com/socketio/engine.io/compare/6.5.2...6.5.3) (2023-10-06) + + +### Bug Fixes + +* improve compatibility with node16 module resolution ([#689](https://github.com/socketio/engine.io/issues/689)) ([c6bf8c0](https://github.com/socketio/engine.io/commit/c6bf8c0f571aad7a5917f43860c8c3d74a9b429b)), closes [/github.com/microsoft/TypeScript/issues/46770#issuecomment-966612103](https://github.com//github.com/microsoft/TypeScript/issues/46770/issues/issuecomment-966612103) +* **webtransport:** properly handle abruptly closed connections ([ff1c861](https://github.com/socketio/engine.io/commit/ff1c8615483bab25acc9cf04fb40339b0bd78812)) + + +### Dependencies + +- [`ws@~8.11.0`](https://github.com/websockets/ws/releases/tag/8.11.0) (no change) + + + ## [6.5.2](https://github.com/socketio/engine.io/compare/6.5.1...6.5.2) (2023-08-01) diff --git a/package.json b/package.json index 39f79955..98ef51e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "engine.io", - "version": "6.5.2", + "version": "6.5.3", "description": "The realtime engine behind Socket.IO. Provides the foundation of a bidirectional connection between client and server", "type": "commonjs", "main": "./build/engine.io.js",