Skip to content

Commit

Permalink
fix: Fix issue with reused send buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
freehuntx authored Nov 29, 2024
1 parent 0ce43e8 commit 395e723
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/interceptors/WebSocket/WebSocketClientConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ export class WebSocketClientConnection
* Send data to the connected client.
*/
public send(data: WebSocketData): void {
// We make a copy of any buffer, in case the client reuses it and overwrites bytes.
if (ArrayBuffer.isView(data)) {
const buffer = data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)
data = Reflect.construct(data.constructor, [buffer])
} else if (data instanceof ArrayBufer) {
data = data.slice(0)
}

this.transport.send(data)
}

Expand Down

0 comments on commit 395e723

Please sign in to comment.