fix(gallery): block SSRF in gallery config URL fetch (#10665)#10673
Merged
Conversation
POST /models/apply with an empty "id" fetches the attacker-supplied "url" gallery config directly via http.Client, with no check that the URL resolves to a public IP. In the default Docker deployment no API key is configured, so any network-reachable client can coerce LocalAI into issuing requests to internal services or cloud-metadata endpoints (and exfiltrate a small slice of the response through the job error message). Guard the config fetch chokepoints (GetGalleryConfigFromURL and GetGalleryConfigFromURLWithContext, which back both the /models/apply worker and gallery installs) with utils.ValidateExternalURL, matching the protection already applied to the CORS proxy and image/video/audio download paths. Only plain http(s) URLs are validated; non-network schemes (huggingface://, github:, oci://, ollama://, file://) resolve to fixed public services or local files and are left untouched. Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Assisted-by: Claude:claude-opus-4-8 [Claude Code]
mudler
approved these changes
Jul 3, 2026
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
Fixes #10665 — Unauthenticated SSRF in
POST /models/apply.When the
idfield is empty, the gallery worker skips the gallery lookup and fetches the attacker-suppliedurlgallery config directly viahttp.Client, with no check that the URL resolves to a public IP. In the default Docker deployment no API key is configured, so any network-reachable client can coerce LocalAI into issuing requests to internal services or cloud-metadata endpoints (e.g.169.254.169.254), and exfiltrate a small slice of the response body through the job error message.The live path from the report:
Fix
Guard the two config-fetch chokepoints —
GetGalleryConfigFromURLandGetGalleryConfigFromURLWithContextincore/gallery/gallery.go— withutils.ValidateExternalURL, the same helper already protecting the CORS proxy and the image/video/audio download endpoints. This blocks private, loopback, link-local, unspecified and cloud-metadata addresses.Only plain
http(s)://URLs are validated. Non-network schemes (huggingface://,github:,oci://,ollama://,file://) resolve to fixed public services or local files and are not a network-SSRF vector, so they are left untouched — existing gallery installs keep working.Placing the guard at the shared chokepoint also covers the gallery-entry install path (
InstallModelFromGallery) and backend config resolution (backend_resolve.go), not just the reported endpoint.Tests
Added
core/gallery/request_test.gocases that stand up a loopbackhttptestserver which would serve a valid gallery config: without the guard the fetch succeeds (reproducing the SSRF), with the guard it is rejected before any request leaves the process. Also coverslocalhost, RFC-1918 ranges and the cloud-metadata IP. The existinggithub:parse test still passes.Verified locally:
go test ./core/gallery/green,go vetclean,gofmtclean,golangci-lint --new-from-merge-base=origin/masterreports 0 issues.Assisted-by: Claude:claude-opus-4-8 [Claude Code]