diff --git a/gateway/run.py b/gateway/run.py index ade178629f15b..cb8379a26aeae 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -16177,6 +16177,7 @@ def _pause_typing_before_finalize( } # Parse SSE stream + _SSE_BUFFER_CAP = 1 << 20 # 1 MiB — reject boundary-less lines buffer = "" async for chunk in resp.content.iter_any(): if not _run_still_current(): @@ -16197,6 +16198,12 @@ def _pause_typing_before_finalize( text = chunk.decode("utf-8", errors="replace") buffer += text + if len(buffer) > _SSE_BUFFER_CAP: + raise RuntimeError( + f"Proxy SSE buffer exceeded {_SSE_BUFFER_CAP} bytes " + "without a line boundary — aborting" + ) + # Process complete SSE lines while "\n" in buffer: line, buffer = buffer.split("\n", 1)