Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit193a9b5

Browse files
fix: disallow duplicate WebSocket connections with same sid
This was caught thanks to the test suite there: [1]Rule: ignores WebSocket connection with same sid after upgrade[1]:https://github.com/socketio/engine.io-protocol/blob/main/test-suite/test-suite.js
1 parent6b2cc16 commit193a9b5

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

‎packages/engine.io/lib/server.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export class Server extends EventEmitter<never, never, ServerReservedEvents> {
211211
// the client must exist since we have checked it in the verify method
212212
constsocket=this.clients.get(sid)!;
213213

214-
if(url.searchParams.get("transport")==="websocket"){
214+
if(req.headers.has("upgrade")){
215215
consttransport=newWS(this.opts);
216216

217217
constpromise=transport.onRequest(req,responseHeaders);
@@ -263,7 +263,7 @@ export class Server extends EventEmitter<never, never, ServerReservedEvents> {
263263
});
264264
}
265265
constpreviousTransport=client.transport.name;
266-
if(!req.headers.has("upgrade")&&previousTransport!==transport){
266+
if(previousTransport==="websocket"){
267267
getLogger("engine.io").debug(
268268
"[server] unexpected transport without upgrade",
269269
);

‎packages/engine.io/test/verification.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,24 @@ describe("verification", () => {
278278
};
279279
});
280280
});
281+
282+
it("should disallow duplicate WebSocket connections",()=>{
283+
constengine=newServer();
284+
285+
returntestServeWithAsyncResults(engine,1,(port,done)=>{
286+
constsocket=newWebSocket(
287+
`ws://localhost:${port}/engine.io/?EIO=4&transport=websocket`,
288+
);
289+
290+
socket.onmessage=({ data})=>{
291+
consthandshake=JSON.parse(data.substring(1));
292+
293+
constsocket=newWebSocket(
294+
`ws://localhost:${port}/engine.io/?EIO=4&transport=websocket&sid=${handshake.sid}`,
295+
);
296+
297+
socket.onclose=done;
298+
};
299+
});
300+
});
281301
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp