From b44464d2303d60432608b7210fe35d6856b48172 Mon Sep 17 00:00:00 2001 From: Repinoid Date: Mon, 12 Oct 2026 09:54:06 +0300 Subject: [PATCH] =?UTF-8?q?fix(filemode):=20=D1=87=D0=B8=D1=81=D1=82=D1=8B?= =?UTF-8?q?=D0=B9=20413=20=D0=BF=D1=80=D0=B8=20=D1=82=D0=B5=D0=BB=D0=B5=20?= =?UTF-8?q?>=20=D0=BB=D0=B8=D0=BC=D0=B8=D1=82=D0=B0=20(=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D1=8F=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20Content-Length)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- filemode.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/filemode.js b/filemode.js index cfb59e8..2601cc7 100644 --- a/filemode.js +++ b/filemode.js @@ -108,6 +108,15 @@ async function handleFile(req, res, config) { return; } + // 1б) Content-Length больше лимита — отказ БЕЗ чтения тела. Иначе при + // превышении в процессе чтения мы вынуждены оборвать поток (req.destroy()), + // и клиент получает обрыв соединения вместо чистого 413. См. assist.js. + const declaredLen = Number.parseInt(req.headers['content-length'], 10); + if (Number.isFinite(declaredLen) && declaredLen > MAX_BODY) { + jsonError(res, 413, 413, 'body too large'); + return; + } + // 2) Тело с лимитом + разбор {content, instruction}. const read = await readBody(req); if (!read.ok) {