Repository navigation
[httpclient] validate redirect targets and pin dialed addresses for user URLs - #12853
Merged
Merged
Conversation
…or user URLs Clients that fetch user-supplied URLs followed redirects without checking the target, so a public host could send them to a loopback, link-local or private address. The host was also resolved twice, once to validate it and once to connect, so a changing DNS answer could bypass the check. Add httpclient.WithExternalOnly. It validates every redirect hop against the external URL policy and, for the default transport, resolves the host, refuses it if any address is non-public, and dials the validated address. Environment proxies are not used for such clients. Move the policy (ValidateExternalURL, IsPublicIP) into pkg/httpclient so it can be used without an import cycle; pkg/utils keeps delegating to it. IsPublicIP now also refuses 100.64.0.0/10, 0.0.0.0/8, 192.0.0.0/24, 198.18.0.0/15, 240.0.0.0/4, multicast, and NAT64 addresses that wrap a non-public IPv4 address. Use the option for the base64, image, audio and video downloads, and drop the video client's own per-hop check. Assisted-by: Claude Code:claude-haiku-5-5
This was referenced Oct 24, 2026
walcz-de
pushed a commit
to walcz-de/LocalAI
that referenced
this pull request
Nov 3, 2026
…ser URLs (mudler#12853) fix(httpclient): validate redirect targets and pin dialed addresses for user URLs Clients that fetch user-supplied URLs followed redirects without checking the target, so a public host could send them to a loopback, link-local or private address. The host was also resolved twice, once to validate it and once to connect, so a changing DNS answer could bypass the check. Add httpclient.WithExternalOnly. It validates every redirect hop against the external URL policy and, for the default transport, resolves the host, refuses it if any address is non-public, and dials the validated address. Environment proxies are not used for such clients. Move the policy (ValidateExternalURL, IsPublicIP) into pkg/httpclient so it can be used without an import cycle; pkg/utils keeps delegating to it. IsPublicIP now also refuses 100.64.0.0/10, 0.0.0.0/8, 192.0.0.0/24, 198.18.0.0/15, 240.0.0.0/4, multicast, and NAT64 addresses that wrap a non-public IPv4 address. Use the option for the base64, image, audio and video downloads, and drop the video client's own per-hop check. Assisted-by: Claude Code:claude-haiku-5-5 Co-authored-by: Ettore Di Giacinto <mudler@localai.io> (cherry picked from commit 756b019)
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.
Description
Clients that fetch user-supplied URLs (chat vision
image_url/audio_url/video_url, image and audio endpoints) had three gaps in the external URL policy:IsPublicIPdid not treat 100.64.0.0/10 (RFC 6598) or 0.0.0.0/8 as non-public.This PR adds
httpclient.WithExternalOnly(). It validates every redirect hop, and for the default transport it resolves the host, refuses non-public addresses and dials a validated address. The policy moves intopkg/httpclient(withpkg/utilsdelegating to it) to avoid an import cycle. The four user-URL download clients use the option, and the video client's own per-hop check is removed because the shared one covers it.Internal clients (launcher, Hugging Face, downloader, OCI) keep the existing
WithFollowRedirectsbehaviour and are not affected.Notes for Reviewers
pkg/httpclienttests cover the IP table, redirect refusal to non-public targets, public redirects still working, and the validated dial. They use httptest servers and a fake resolver and do not contact external hosts.pkg/utilshas ffmpeg-dependent tests that fail without ffmpeg installed; they fail the same way on the base commit.core/http/endpoints/localaiandcore/http/endpoints/openaipackages were not compiled in the author's environment (generated protobuf missing). Please let CI build them.WithTransportis not wrapped; it must enforce the policy itself. The redirect check still applies.Signed commits
🤖 Generated with Claude Code