From 9332e1b44b8db96f5166959de4c3d2dd58b14a11 Mon Sep 17 00:00:00 2001 From: CyberMind-FR Date: Mon, 22 Jun 2026 10:53:59 +0200 Subject: [PATCH] =?UTF-8?q?fix(sbxmitm):=20stream=20non-injected=20respons?= =?UTF-8?q?es=20verbatim=20=E2=80=94=20stop=20truncating=20>8MiB=20(closes?= =?UTF-8?q?=20#697)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The response handler read EVERY body with io.ReadAll(LimitReader(8MiB)) and writeResponse emitted exactly len(body), so any response larger than 8 MiB was silently truncated — for all content types, not just the 2xx text/html we inject into. Large Gmail message bodies / attachments / inline images were cut off, so "certains mails ne s'affichent plus" through the R3 tunnel (same class as the earlier APK-over-mitm corruption). - new streamResponse(): writes status+headers then io.Copy(resp.Body) — never buffers the whole body; preserves upstream Content-Length, else Connection: close delimits. Optional prefix for already-peeked bytes. - handler: only buffer when injectEligible (2xx text/html); everything else streams verbatim. Oversized HTML (>8MiB cap) also streams verbatim rather than serving a truncated inject. Full interception preserved (still MITM). Verified live on gk2: 20 MB download through a worker returns all 20,000,000 bytes (was capped at 8 MiB); banner still injects into small text/html. --- .../secubox-toolbox-ng/cmd/sbxmitm/main.go | 93 ++++++++++--------- .../secubox-toolbox-ng/cmd/sbxmitm/util.go | 31 +++++++ 2 files changed, 78 insertions(+), 46 deletions(-) diff --git a/packages/secubox-toolbox-ng/cmd/sbxmitm/main.go b/packages/secubox-toolbox-ng/cmd/sbxmitm/main.go index b3c25ac7..3eb6ec91 100644 --- a/packages/secubox-toolbox-ng/cmd/sbxmitm/main.go +++ b/packages/secubox-toolbox-ng/cmd/sbxmitm/main.go @@ -526,57 +526,58 @@ func (px *Proxy) mitmPipeline(tconn *tls.Conn, rawClient net.Conn, host, verdict } } - body, _ := io.ReadAll(io.LimitReader(resp.Body, 8<<20)) - // Inject the transparency-banner loader only on 2xx text/html responses - // (mirrors the Python addon, which skips non-200). The loader's same-origin - // . Fail-open: a dead/slow portal → - // scriptBody=="" → the banner inject is skipped and the page is served - // intact (the cosmetic