| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c9fbe9d commit b4c287b
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,7 +75,7 @@ class ByteParser extends Writable { | |||
| 75 | 75 | if ( | |
| 76 | 76 | this.#maxPayloadSize > 0 && | |
| 77 | 77 | !isControlFrame(this.#info.opcode) && | |
| 78 | - this.#info.payloadLength > this.#maxPayloadSize | ||
| 78 | + this.#info.payloadLength + this.#fragmentsBytes > this.#maxPayloadSize | ||
| 79 | 79 | ) { | |
| 80 | 80 | failWebsocketConnection(this.#handler, 1009, 'Payload size exceeds maximum allowed size') | |
| 81 | 81 | return false | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -419,3 +419,49 @@ test('Raw uncompressed payload over 64-bit extended limit is rejected', async (t | |||
| 419 | 419 | t.assert.strictEqual(messageReceived, false, 'Raw uncompressed message over limit should be rejected') | |
| 420 | 420 | t.assert.strictEqual(client.readyState, WebSocket.CLOSED, 'Connection should be closed after exceeding limit') | |
| 421 | 421 | }) | |
| 422 | + | ||
| 423 | + test('cumulative payload size', (t, done) => { | ||
| 424 | + t.plan(1) | ||
| 425 | + | ||
| 426 | + const LIMIT = 100 | ||
| 427 | + const FRAGMENT_SIZE = 60 | ||
| 428 | + const NUM_FRAGMENTS = 10 | ||
| 429 | + | ||
| 430 | + const server = new WebSocketServer({ port: 0 }) | ||
| 431 | + | ||
| 432 | + server.on('connection', (ws) => { | ||
| 433 | + const socket = ws._socket | ||
| 434 | + const payload = Buffer.alloc(FRAGMENT_SIZE, 0x41) | ||
| 435 | + | ||
| 436 | + for (let i = 0; i < NUM_FRAGMENTS; i++) { | ||
| 437 | + const fin = i === NUM_FRAGMENTS - 1 ? 0x80 : 0x00 | ||
| 438 | + const opcode = i === 0 ? 0x02 : 0x00 | ||
| 439 | + const header = Buffer.alloc(2) | ||
| 440 | + header[0] = fin | opcode | ||
| 441 | + header[1] = FRAGMENT_SIZE | ||
| 442 | + socket.write(header) | ||
| 443 | + socket.write(payload) | ||
| 444 | + } | ||
| 445 | + }) | ||
| 446 | + | ||
| 447 | + const agent = new Agent({ | ||
| 448 | + webSocket: { | ||
| 449 | + maxPayloadSize: LIMIT | ||
| 450 | + } | ||
| 451 | + }) | ||
| 452 | + | ||
| 453 | + const client = new WebSocket(`ws://127.0.0.1:${server.address().port}`, { dispatcher: agent }) | ||
| 454 | + | ||
| 455 | + t.after(async () => { | ||
| 456 | + client.close() | ||
| 457 | + server.close() | ||
| 458 | + await agent.close() | ||
| 459 | + }) | ||
| 460 | + | ||
| 461 | + client.onmessage = t.assert.fail | ||
| 462 | + | ||
| 463 | + client.addEventListener('error', (event) => { | ||
| 464 | + t.assert.ok(event) | ||
| 465 | + done() | ||
| 466 | + }) | ||
| 467 | + }) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments