From 4157be05c12923db07146ed2d6aa1fa87eef31b4 Mon Sep 17 00:00:00 2001 From: Diogo Martins Date: Sat, 11 Jul 2026 18:08:57 +0100 Subject: [PATCH] PingoraServer: reject malformed request bodies with 400, not 500 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The probe app read the POST body with `session.read_request_body().await?`; on malformed chunk framing Pingora's body reader errors, the ? propagated out of request_filter, and Pingora emitted its default 500 — failing 17 chunk/TE smuggling+malformed tests that expect 400 or close. Now the read loop catches the error and returns a clean 400. Pingora was already detecting the bad framing; this just surfaces it as a client error. --- src/Servers/PingoraServer/src/main.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Servers/PingoraServer/src/main.rs b/src/Servers/PingoraServer/src/main.rs index 62193f0..e808ec4 100644 --- a/src/Servers/PingoraServer/src/main.rs +++ b/src/Servers/PingoraServer/src/main.rs @@ -63,8 +63,21 @@ impl ProxyHttp for OkProxy { let is_post = session.req_header().method == pingora::http::Method::POST; let body = if is_post { let mut buf = Vec::new(); - while let Some(chunk) = session.read_request_body().await? { - buf.extend_from_slice(&chunk); + loop { + match session.read_request_body().await { + Ok(Some(chunk)) => buf.extend_from_slice(&chunk), + Ok(None) => break, + // Malformed request body (e.g. bad chunk framing): reject with 400 + // instead of letting the error bubble up to Pingora's default 500. + Err(_) => { + let mut header = ResponseHeader::build(400, None)?; + header.insert_header("Content-Length", "0")?; + session + .write_response_header(Box::new(header), true) + .await?; + return Ok(true); + } + } } Bytes::from(buf) } else {