Skip to content

fix(tools): connect fetch_url to the address that the check saw - #740

Open
omkargaikwad23 wants to merge 4 commits into
mainfrom
fix/fetch-url-connect-checked-address
Open

omkargaikwad23 wants to merge 4 commits into
mainfrom
fix/fetch-url-connect-checked-address

Conversation

@omkargaikwad23

@omkargaikwad23 omkargaikwad23 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

What

The fetch_url judge tool connects only to an address that it checked.

  • The tool opens the connection with its own function. The function resolves the host name one time, refuses a private, loopback, or link-local address, and connects to one of the checked addresses.
  • TLS still verifies the certificate against the host name.
  • The tool ignores proxy settings such as HTTPS_PROXY. A proxy resolves the host name itself, so the address check cannot apply.
  • docs/judge_tools.md no longer lists the two known follow-ups (redirects, DNS lookup), because both are done. It has a note about the proxy.

Why

The tool checked that the host of a URL does not resolve to a private address. The connection then resolved the host name a second time. A DNS answer that changes between the two lookups sent the connection to an address that the check did not see, for example an internal service.

Behavior change: where HTTPS requests need a proxy, fetch_url now fails with a connection error.

Testing

  • tools_fetch_url_test.py: 22 tests pass. With gemini_tools_test.py: 28 tests pass. pycodestyle is clean.
  • A script with a local listener in the role of an internal service. The first DNS lookup returns a public address, and the second returns 127.0.0.1.
main This PR
Connections that reach the listener 1 0
Result of the tool TLS error refusing to connect to 'rebind.example'
  • Real use of the tool with no mock, same result on main and on this PR: https://example.com/ and https://www.google.com/robots.txt return the page. https://169.254.169.254/ and https://localhost/ are refused.
  • Real run with Gemini CLI 0.25.1 and 2 scenarios that use no tools: both pass. This run is a regression check. It does not use the changed code.

Logs (Google-internal): https://paste.googleplex.com/6755399437647475

The fetch_url judge tool checks that the host of a URL does not resolve
to a private, loopback, or link-local address. The connection then
resolved the host name a second time, so a DNS answer that changed
between the two lookups reached an address that the check did not see.

The tool now connects through its own function. It resolves the host
name one time, refuses a blocked address, and connects to one of the
addresses that it checked. TLS still verifies the host name.

The tool ignores proxy settings, because a proxy resolves the host name
itself.
@omkargaikwad23
omkargaikwad23 marked this pull request as ready for review November 26, 2026 07:50
@omkargaikwad23

Copy link
Copy Markdown
Collaborator Author

/gcbrun

@omkargaikwad23 omkargaikwad23 self-assigned this Nov 26, 2026
omkargaikwad23 and others added 3 commits November 26, 2026 07:57
Text changes only. The docstring of _is_blocked_ip now names each blocked
address type. The docstring of _connect says what passed the check.
_CheckedHTTPSHandler has a docstring. One sentence in judge_tools.md is
reworded.
Keep the notes to what a user of the tool can rely on. The SSRF guard
note now also names redirect targets and the connection address. The
separate notes for those two are removed.
@omkargaikwad23

Copy link
Copy Markdown
Collaborator Author

/gcbrun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant