Skip to content
13 changes: 11 additions & 2 deletions lib/network.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
'use strict';

const receiveBody = async (stream) => {
const MAX_BODY_SIZE = 0xffffffff;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4Gb gives attacker gives the attacker great opportunities and node.js will fail allocating such an array

Comment thread
tshemsedinov marked this conversation as resolved.
Outdated

const receiveBody = async (stream, limit = MAX_BODY_SIZE) => {
Comment thread
tshemsedinov marked this conversation as resolved.
const chunks = [];
for await (const chunk of stream) chunks.push(chunk);
let size = 0;
for await (const chunk of stream) {
size += chunk.length;
if (size > limit) {
throw new Error('Body size limit exceeded');
}
chunks.push(chunk);
}
return Buffer.concat(chunks);
};

Expand Down