fix: add SSRF protection to RestApiTool._request()#5760
Open
Neelagiri65 wants to merge 1 commit into
Open
Conversation
RestApiTool._request() passes URLs straight to httpx with no validation. load_web_page got SSRF protections after google#4368 (hostname blocking, DNS pre-resolution, IP range filtering, scheme restriction) but RestApiTool was not updated. This extracts the SSRF validation logic into a shared _ssrf_protection module and applies it in _request() before making HTTP calls. Also sets a finite timeout (30s) instead of None. Blocked: localhost, *.localhost, loopback, link-local (169.254.x.x), private ranges (10.x, 172.16-31.x, 192.168.x), non-http(s) schemes. Related: google#4368
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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.
What
RestApiTool._request()passes URLs tohttpx.AsyncClient.request()with no validation. After #4368 fixed SSRF inload_web_page(hostname blocking, DNS pre-resolution, IP range filtering, scheme restriction),RestApiToolwas not updated with the same protections.An OpenAPI spec with
servers[].urlpointing at127.0.0.1or169.254.169.254goes through without any check.Changes
_ssrf_protection.pywith the validation logic (scheme check, hostname blocking, DNS resolution, IP range filtering)_request()callsvalidate_url()before making the HTTP requestNoneto30seconds_requestintegrationWhat gets blocked
localhostand*.localhost127.0.0.0/8,::1)169.254.0.0/16) — covers cloud metadata endpoints10.0.0.0/8,172.16.0.0/12,192.168.0.0/16)file://,ftp://, etc.)Why a shared module
load_web_page.pyhas its own copies of these functions. The shared module avoids duplicating the logic a third time.load_web_pagecan be migrated to use it in a follow-up if wanted.Related: #4368