While adding web search to a local model’s chat panel, I added an egress check: resolve the hostname, obtain its IP, and reject non-public addresses. The check was intended to restrict SSRF access to internal services.
After the check was added, search consistently returned empty results without an error or timeout.
The investigation showed that the guard rejected every target, including Wikipedia and the search API. The resolved addresses did fail the public-address test used by the code.
Addresses that were synthesised
The proxy in this record synthesised placeholder addresses for selected DNS queries and then forwarded by hostname. Rules determine which names use that path. The historical answers follow.
$ python3 -c "import socket;print(socket.gethostbyname('en.wikipedia.org'))"
198.18.8.116
$ python3 -c "import socket;print(socket.gethostbyname('api.tavily.com'))"
198.18.10.9
198.18.0.0/15 is reserved by RFC 2544 for network device benchmarking. Python’s ipaddress module reports is_global == False for it — which is right, that genuinely is not a public address. The IPv6 side behaves the same way, with the proxy handing out addresses from a private fdfe: range.
So every domain that routes through the proxy read as “not public” and got refused. The only hosts that passed were the ones resolved directly, returning real addresses. The reason this surfaced as a silent empty result rather than an error is that I was treating “every candidate source was unusable” as “nothing was found.”
I first added the two synthetic address ranges to the allowlist to restore search, then examined what that change meant for the protection.
The address you check is not the address you connect to
An IP policy must constrain the actual destination and revalidate each redirect. Host normalisation, resolution and connection must agree. A separate preliminary lookup alone does not establish that agreement.
In this transparent-proxy environment, resolution returns a placeholder while the proxy establishes the real connection elsewhere. This code cannot inspect the final destination. The check is therefore insufficient for validating the actual connection target.
Allowlisting the synthetic ranges restored the feature, but not validation of the final IP. The proxy controls egress destinations in this environment; this layer still restricts protocols and ports. That condition needs to be recorded alongside the guard.
The same gap, a second time
I then checked the same file for other cases where the validated object differed from the object used, and found another instance.
urlsplit splits URLs without performing IDNA encoding. The difference arises later between standard-library IDNA in the resolution path and HTTPX host normalisation. For example, faß.de encodes as fass.de with the built-in codec and xn--fa-hia.de in HTTPX 0.28.1.
If validation and fetching use those different results, they can address different names. Canonicalise once and share that hostname between validation and connection.
I chose to reject non-ASCII hostnames. They were rare in these search results, so I did not add the work needed to align the two IDNA implementations.
A third time, left unfixed
The same gap has a third form: a window of time between the check and the connection.
The historical record reports about 4.6 ms between lookups. An attacker controlling DNS can change answers before a new resolution; interval length does not by itself establish severity. Bind the connection target or enforce destinations at a trusted egress.
The original implementation leaves connection targets unpinned. Remedies include connecting to a validated IP while preserving Host, SNI and hostname verification, or enforcing destination policy at trusted egress. Internal ports 80/443 can expose sensitive services, and model context can affect output. Those conditions do not establish limited damage.
Assess the remaining destination-control risk using reachable services, caller privileges, output paths and proxy policy. This article correction does not mean IP pinning has been implemented in the runtime.
Other things the same review turned up
Further review found several runtime issues unrelated to that gap.
The decompression bomb was truncated too late. What I had written was a slice of the response body:
data = r.content[:MAX_BYTES] # too late
Slicing an already-read response cannot limit earlier allocation. Retain the original figures: about 0.3 MB compressed, 200 MB decoded and RSS 747 MB. The streaming snippet reduces retained data, but aiter_bytes decodes first and a single chunk can exceed the cap; the code also appends before checking. For a hard bound, reject compressed responses or use a bounded-output decoder over raw bytes, limiting input, output and total time separately.
async with client.stream("GET", url) as r:
if not r.headers.get("content-type", "").startswith("text/"):
return None
buf = bytearray()
async for chunk in r.aiter_bytes():
buf += chunk
if len(buf) >= MAX_BYTES:
break
Synchronous DNS or extraction inside a coroutine blocks its event loop for the operation’s duration. Use async DNS or bounded thread/process pools as appropriate. Cancelling an asyncio.to_thread wait generally does not stop the running thread, and Python CPU work also depends on GIL behaviour.
A per-operation timeout is not a total timeout. httpx’s timeout bounds each socket operation. A peer that trickles data slowly never trips it while stretching an intended 8 seconds past 40. That needs a separate overall deadline wrapped around the whole fetch.
Distinguish explicit no-result pages from unrecognised markup. Test title attributes and other changes with an HTML parser and saved fixtures, reporting parser failure separately.
Inspect BOM, valid HTTP charset and HTML declarations before a defined strict-decoding fallback. UTF-8 and GB18030 are candidates for some Chinese pages; successful guessing does not establish correct text. Record the chosen encoding.
Three silent truncations
The review also found three places where processing discarded data.
Deduplication merged pages that were not the same. The dedup logic stripped a URL’s query string before comparing. That is fine on most sites, but on ones that distinguish content by query parameter — a video site’s ?bvid=, a forum’s ?tid= — two entirely different pages compared equal and the second was dropped. It now strips only the fragment and keeps the query string in the comparison.
Sharing the character budget retains a section from each source, but characters are not tokens. Check the actual tokenizer’s context budget and preserve truncation or exclusion states in citation records.
The original five-thousand-token prompt and suggested 1024-token output floor depend on model and task. Record input, reasoning, final output and finish_reason before setting headroom. A floor of 1024 does not guarantee an answer.
Recheck other security conclusions
The review proposed failure hypotheses and checked them against evidence. Several were rejected; their checks are recorded below.
Scheme validation and correct escaping on every citation path can exclude direct javascript: links there. Also inspect redirects, normalisation and HTML attributes; a scheme regex alone is not complete output validation.
Removing model tool access reduces direct execution capability. Injection can still alter answers, expose context or generate misleading links. Assess data access, presentation and caller privileges as well.
Nginx request-rate controls establish rate limiting, not a cap on active fetches. Inspect connection limits, application semaphores, pools and per-search task fan-out separately.
What generalises
The three bugs suggest a shared check: for a guard that validates before use, confirm that the validated object is the object actually used.
Synthetic proxy addresses, different normalization rules, and a delay between two DNS lookups can each separate the validated target from the actual one. These causes need individual checks.
A second requirement is to report protection or processing failures explicitly. Empty search results, pages that parse to zero items, and mojibake marked as successfully fetched can otherwise pass incorrect information downstream.