Skip to content

Commit d1f5aa9

Browse files
fix(eio): prevent WebTransport connections when a middleware is registered
1 parent b785377 commit d1f5aa9

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

packages/engine.io/lib/server.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,15 @@ export abstract class BaseServer extends EventEmitter {
529529
}
530530

531531
public async onWebTransportSession(session: any) {
532+
if (this.middlewares.length > 0) {
533+
// middlewares expect an IncomingMessage argument, which cannot be created from the WebTransport session object
534+
// see also: https://github.com/fails-components/webtransport/issues/448
535+
debug(
536+
"closing session since WebTransport is not compatible with middlewares",
537+
);
538+
return session.close();
539+
}
540+
532541
const timeout = setTimeout(() => {
533542
debug(
534543
"the client failed to establish a bidirectional stream in the given period",

packages/engine.io/test/webtransport.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,32 @@ describe("WebTransport", () => {
392392
);
393393
});
394394

395+
it("should refuse the connection when a middleware is registered", (done) => {
396+
setupServer({}, async ({ engine, h3Server, certificate }) => {
397+
engine.use((req, res, next) => next());
398+
399+
engine.on("connection", () => {
400+
done(new Error("should not happen"));
401+
});
402+
403+
const client = new WebTransport(
404+
`https://127.0.0.1:${h3Server.port}/engine.io/`,
405+
{
406+
serverCertificateHashes: [
407+
{
408+
algorithm: "sha-256",
409+
value: certificate.hash,
410+
},
411+
],
412+
},
413+
);
414+
415+
await client.closed;
416+
417+
success(engine, h3Server, done);
418+
});
419+
});
420+
395421
it("should send ping/pong packets", (done) => {
396422
setup(
397423
{

0 commit comments

Comments
 (0)