fix: comprehensive HTTP tool security hardening & review#222
Open
esafwan wants to merge 2 commits into
Open
Conversation
The validate_url() function existed but was never called, leaving agents free to hit internal IPs, localhost, and cloud metadata endpoints. This commit: - Calls validate_url() before every outbound request - Resolves DNS to prevent rebinding attacks (hostname → IP check) - Blocks 169.254.x.x (cloud metadata), 0.0.0.0, and IPv6 loopback - Adds HTTP method whitelist (GET/POST/PUT/PATCH/DELETE/HEAD only) - Adds 10MB response size limit to prevent memory exhaustion - Cleans up duplicate imports and formatting https://claude.ai/code/session_0185G6EwYpV4GTgKkvJNmCRk
…frontend types Security fixes: - Add SSRF protection to _download_content() in tool_functions.py - Add SSRF protection to URL knowledge extractor and image download in sdk_tools.py - Add CRLF injection prevention for HTTP header key/value pairs - Add reserved parameter name validation for HTTP tools (url, params, json_data, etc.) - Add base_url format validation (must be valid http/https URL) Robustness: - Add Content-Length pre-check before downloading full response body - Improve frontend Zod schema: base_url URL validation, typed http_headers array Also includes auto-formatting by ruff on touched files. https://claude.ai/code/session_0185G6EwYpV4GTgKkvJNmCRk
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
Full security review and hardening of the HTTP tool ecosystem. Two commits:
Commit 1: Activate SSRF protection in
http_handler.pyvalidate_url()was defined but never called — agents could freely hit internal IPs, localhost, cloud metadata (169.254.169.254)socket.getaddrinfo()(hostname → IP check)169.254.x.x,0.0.0.0,::1, all RFC 1918 rangesCommit 2: Harden the broader HTTP tool ecosystem
Security fixes across 6 files:
_download_content()tool_functions.pyrequests.get(url)with zero protection — now callsvalidate_url()knowledge/extractors/url.pysdk_tools.pyagent_tool_function.py\rand\ncharactersagent_tool_function.pyurl,params,json_data,headers,data,tool_name,methodrejected for HTTP toolsagent_tool_function.pyhttp://orhttps://URL with hostnamehttp_handler.pyContent-Lengthheader before downloading full bodytoolCreationForm.utils.tsbase_urlvalidated as URL,http_headerstyped as{key, value}[]Files changed
huf/ai/http_handler.py— SSRF activation, method whitelist, response limits, Content-Length pre-checkhuf/ai/tool_functions.py— SSRF protection for_download_content()huf/ai/sdk_tools.py— SSRF protection for image URL downloadshuf/ai/knowledge/extractors/url.py— SSRF protection for knowledge URL extractionhuf/huf/doctype/agent_tool_function/agent_tool_function.py— base_url, CRLF, reserved param validationsfrontend/src/components/tools/toolCreationForm.utils.ts— Zod schema improvementsFull review document
A comprehensive review document covering the entire HTTP tool ecosystem (architecture, execution flow, all remaining issues, prioritized improvement plan) is available in the plan file. Key remaining items for future work:
test_agent_tool_function.pyis currently empty)Test plan
base_url = https://httpbin.org— verify requests workurl— verify rejectionbase_urltoftp://invalid— verify rejection\r\nin value — verify rejection127.0.0.1,10.x.x.x,192.168.x.x,169.254.169.254_download_contentblocks private IPs for file attachmentshttps://claude.ai/code/session_0185G6EwYpV4GTgKkvJNmCRk