Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix: follow-up fixes from PR #2654 body-guard review (#2662)

LearningCircuitd1fb59bf635a
diff --git a/src/local_deep_research/security/safe_requests.py b/src/local_deep_research/security/safe_requests.py
index 7879eb3d4c..326cc303ed 100644
--- a/src/local_deep_research/security/safe_requests.py
+++ b/src/local_deep_research/security/safe_requests.py
@@ -34,8 +34,8 @@ def _install_body_guard(response: requests.Response) -> None:
This transparently protects both streamed (.iter_content) and
non-streamed (.text, .json(), .content) access patterns.
- Callers decide when to install the guard (e.g. when Content-Length
- is absent, invalid, or negative). This function always installs.
+ Always installs — callers (currently only _check_response_size)
+ are responsible for deciding when to call this function.
"""
original_read = response.raw.read
bytes_read = 0
@@ -48,7 +48,7 @@ def _install_body_guard(response: requests.Response) -> None:
response.close()
raise ValueError(
f"Response body too large: >{bytes_read} bytes "
- f"(max {MAX_RESPONSE_SIZE}, no Content-Length header)"
+ f"(max {MAX_RESPONSE_SIZE}, Content-Length absent or invalid)"
)
return data
@@ -64,8 +64,9 @@ def _check_response_size(response: requests.Response) -> None:
(trailing/doubled commas) are filtered before parsing. Non-integer
or negative values cause the header to be treated as absent.
- When Content-Length is absent (e.g. chunked transfer encoding),
- installs a body guard that enforces the size limit during read.
+ When Content-Length is absent, unparseable, negative, or consists
+ only of commas/whitespace, installs a body guard that enforces
+ the size limit during body consumption.
Must be called before returning a response to the caller. On
rejection the response is closed to avoid leaking the connection.
diff --git a/tests/security/test_ssrf_response_size.py b/tests/security/test_ssrf_response_size.py
index 1d8fe03f2f..111cb54a15 100644
--- a/tests/security/test_ssrf_response_size.py
+++ b/tests/security/test_ssrf_response_size.py
@@ -14,6 +14,7 @@ from local_deep_research.security.safe_requests import (
safe_get,
safe_post,
SafeSession,
+ _check_response_size,
_install_body_guard,
MAX_RESPONSE_SIZE,
)
@@ -475,7 +476,7 @@ class TestBodySizeEnforcement:
"""Invalid Content-Length must still get body guard via _check_response_size."""
body = b"x" * (MAX_RESPONSE_SIZE + 1)
resp = self._make_response(body, headers={"Content-Length": "abc"})
- _install_body_guard(resp)
+ _check_response_size(resp)
with pytest.raises(ValueError, match="Response body too large"):
resp.raw.read()
@@ -485,7 +486,7 @@ class TestBodySizeEnforcement:
"""Negative Content-Length must still get body guard via _check_response_size."""
body = b"x" * (MAX_RESPONSE_SIZE + 1)
resp = self._make_response(body, headers={"Content-Length": "-1"})
- _install_body_guard(resp)
+ _check_response_size(resp)
with pytest.raises(ValueError, match="Response body too large"):
resp.raw.read()