fix(web): run URL SSRF checks off the event loop in async paths#3691
Open
Kewe63 wants to merge 1 commit intoNousResearch:mainfrom
Open
fix(web): run URL SSRF checks off the event loop in async paths#3691Kewe63 wants to merge 1 commit intoNousResearch:mainfrom
Kewe63 wants to merge 1 commit intoNousResearch:mainfrom
Conversation
- Add async_is_safe_url() wrapping is_safe_url via asyncio.to_thread - Use in web_extract_tool, web_crawl_tool, and vision_tools (preflight + redirect guard) - Update tests for async mocks; fix tilde path tests on Windows (USERPROFILE)
8218d94 to
d022173
Compare
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
async_is_safe_url()intools/url_safety.py, delegating tois_safe_url()viaasyncio.to_thread()sosocket.getaddrinfodoes not block the asyncio event loop.web_extract_tool,web_crawl_tool, and vision preflight / redirect validation to use the async helper.USERPROFILEalongsideHOME).Motivation
Sync
is_safe_url()performs DNS resolution on the hot path. When invoked from async tools, that can stall the event loop and hurt latency under load.Related
Test plan
pytest tests/tools/test_url_safety.py tests/tools/test_website_policy.py tests/tools/test_vision_tools.py tests/test_model_tools_async_bridge.py tests/tools/test_web_tools_tavily.py