feat: HTTP Tool Security Hardening — SSRF Protection, Response Size Limits & Input Validation#285
Merged
Merged
Conversation
13 tasks
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.
Summary
This is a clean implementation of the HTTP tool security review and hardening from #222. All changes have been applied to a fresh branch off the current
develop.Changes Implemented
1. SSRF Protection & Network Hardening (
huf/ai/http_handler.py)127.0.0.1,0.0.0.0,::1, and cloud metadata IPs169.254.169.254). Relies on socket-resolved IPs to prevent DNS rebinding attacks.GET,POST,PUT,PATCH,DELETE,HEAD.Content-Lengthheader if available, and measures chunks iteratively during streaming to stop downloads immediately when the limit is breached.2. Broad Ecosystem SSRF Guarding
huf/ai/tool_functions.py): Integratesvalidate_url()check inside_download_content()to stop agents downloading files from private endpoints.huf/ai/knowledge/extractors/url.py): Validates user-supplied knowledge source URLs.huf/ai/sdk_tools.py): Validates generated or fetched image URLs.3. Server-Side Validation (
huf/huf/doctype/agent_tool_function/agent_tool_function.py)\r) or line feeds (\n).url,params,json_data,headers,data,tool_name, ormethodto prevent conflicts with HTTP handler kwargs.base_urlis a validhttporhttpsURL with a proper hostname.4. Frontend Type Safety & Validation (
frontend/src/components/tools/toolCreationForm.utils.ts)Verification & Testing
http://127.0.0.1:8000or local URLs are successfully blocked.https://httpbin.org/getsuccessfully completed with a 200 response.Closes #222