Skip to content

[httpclient] validate redirect targets and pin dialed addresses for user URLs - #12853

Merged
mudler merged 1 commit into
masterfrom
fix/ssrf-redirect-hops
Oct 23, 2026
Merged

mudler merged 1 commit into
masterfrom
fix/ssrf-redirect-hops

Conversation

@mudler-agent

Copy link
Copy Markdown
Collaborator

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:

  1. Redirects were followed without checking the target, so a public URL could redirect the server to loopback, link-local or private addresses.
  2. IsPublicIP did not treat 100.64.0.0/10 (RFC 6598) or 0.0.0.0/8 as non-public.
  3. The host was resolved once for validation and again when dialing, so a changing DNS answer could bypass the check.

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 into pkg/httpclient (with pkg/utils delegating 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 WithFollowRedirects behaviour and are not affected.

Notes for Reviewers

  • pkg/httpclient tests 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/utils has ffmpeg-dependent tests that fail without ffmpeg installed; they fail the same way on the base commit.
  • The core/http/endpoints/localai and core/http/endpoints/openai packages were not compiled in the author's environment (generated protobuf missing). Please let CI build them.
  • A caller-supplied transport via WithTransport is not wrapped; it must enforce the policy itself. The redirect check still applies.

Signed commits

  • Yes, I signed my commits.
  • Documentation updated (docs/content/) for user-facing changes, or not applicable

🤖 Generated with Claude Code

…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
@mudler
mudler merged commit 756b019 into master Oct 23, 2026
2 of 24 checks passed
@mudler
mudler deleted the fix/ssrf-redirect-hops branch October 23, 2026 09:54
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)
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.

2 participants