feat: add timeout and URL scheme validation to load_web_page#4887
Open
cchinchilla-dev wants to merge 2 commits intogoogle:mainfrom
Open
feat: add timeout and URL scheme validation to load_web_page#4887cchinchilla-dev wants to merge 2 commits intogoogle:mainfrom
cchinchilla-dev wants to merge 2 commits intogoogle:mainfrom
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
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.
Link to Issue or Description of Change
Problem
load_web_page()callsrequests.get()without atimeoutparameter. If the target server is unresponsive, the agent hangs indefinitely. Additionally, the function accepts any URL scheme (file://,ftp://, etc.) and does not handleTimeoutorConnectionErrorexceptions.Solution
timeout=10(via module-level_DEFAULT_TIMEOUT_SECONDS) torequests.get()httporhttpsbefore making the requestrequests.exceptions.Timeoutandrequests.exceptions.ConnectionErrorwith descriptive error messagesDesign note: The timeout is exposed as a module-level constant rather than a function parameter to avoid exposing it to the LLM's function calling schema. It can be overridden via
load_web_page._DEFAULT_TIMEOUT_SECONDS = 30if needed.Testing Plan
Unit Tests:
11 new tests added in
tests/unittests/tools/test_load_web_page.py:test_invalid_scheme_file- rejectsfile://URLstest_invalid_scheme_ftp- rejectsftp://URLstest_invalid_scheme_empty- rejects malformed URLstest_timeout_returns_error_message- handlesTimeoutexceptiontest_connection_error_returns_error_message- handlesConnectionErrorexceptiontest_successful_request- verifies successful fetch with mocked BeautifulSouptest_failed_request_non_200- handles non-200 status codestest_timeout_parameter_passed- verifies timeout=10 is passed to requests.get()test_allow_redirects_false- verifies SSRF protection is preservedtest_http_scheme_accepted- acceptshttp://URLstest_https_scheme_accepted- acceptshttps://URLsManual End-to-End (E2E) Tests:
N/A - This is an internal hardening change. The function signature is unchanged.
Checklist
Additional context
This complements the existing SSRF protection (
allow_redirects=False) already present in the function.