fix: enforce response size limit in ReadWebpageTool to prevent resource exhaustion#2410
Open
Koushik-Salammagari wants to merge 1 commit intoarc53:mainfrom
Open
Conversation
…ce exhaustion An LLM agent could be instructed to fetch an arbitrarily large URL (e.g. a multi-GB file), causing the server to load the entire response into memory via response.text before passing it to markdownify. Fix: - Use stream=True so the connection is established before reading - Reject responses whose Content-Length header exceeds MAX_CONTENT_BYTES (10 MB) - Abort mid-stream if accumulated body bytes exceed MAX_CONTENT_BYTES - Call response.close() on early exit to release the connection Tests: add 5 new cases covering Content-Length rejection, streaming body rejection, boundary-exact acceptance, stream=True assertion, and User-Agent header verification. Update existing test_successful_fetch to use iter_content mock consistent with streaming path.
|
@Koushik-Salammagari is attempting to deploy a commit to the Arc53 Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vulnerability Summary
CWE-400: Uncontrolled Resource Consumption in
application/agents/tools/read_webpage.pyProblem
ReadWebpageTool.execute_actionfetched the full response body unconditionally viaresponse.textbefore converting it withmarkdownify:An attacker can prompt the agent to call
read_webpagewith a URL that serves a multi-GB response (e.g. a large file host or a server under attacker control). The server allocates memory proportional to the response size, with no upper bound, which can cause OOM crashes or severe performance degradation.Data flow
SSRF is already blocked by
validate_url(). This is a separate, complementary defence against resource exhaustion via legitimate-but-oversized responses.Fix
stream=Trueso the connection is opened without reading the bodyContent-Lengthheader exceedsMAX_CONTENT_BYTES(10 MB)MAX_CONTENT_BYTESresponse.close()on early exit to release the TCP connectionTests added (5 new cases)
test_content_length_too_large_rejectedContent-Lengthexceeds limit;iter_contentnever calledtest_streaming_body_too_large_rejectedtest_content_at_limit_allowedtest_uses_stream_truestream=Trueis passed torequests.gettest_user_agent_header_sentUser-Agentheader is still sent on streaming requestExisting tests updated to mock
iter_contentinstead of.textto match the streaming code path.All 13 tests pass (
python -m pytest tests/agents/test_read_webpage_tool.py -v).Screenshots: N/A — backend-only change with no UI impact.