security: validate URLs to prevent SSRF in content fetching endpoints - #8476
Merged
Conversation
User-supplied URLs passed to GetContentURIAsBase64() and downloadFile() were fetched without validation, allowing SSRF attacks against internal services. Added URL validation that blocks private IPs, loopback, link-local, and cloud metadata endpoints before fetching.
✅ Deploy Preview for localai ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
mudler
approved these changes
Feb 10, 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.
Vulnerability identified and fix provided by Kolega.dev
Description
This PR fixes a Server-Side Request Forgery (SSRF) vulnerability in multiple endpoints that accept user-provided URLs and fetch them without validation.
Vulnerability Details
Location:
pkg/utils/base64.go(GetContentURIAsBase64),core/http/endpoints/openai/image.go(downloadFile), and callers incore/http/middleware/request.go(lines 331, 341, 356) andcore/http/endpoints/localai/detection.go(line 34).Description: The
GetContentURIAsBase64()function anddownloadFile()function fetch arbitrary user-supplied URLs without any validation. This allows attackers to probe internal networks, access cloud metadata services (e.g.,169.254.169.254on AWS/GCP), and reach internal services via loopback or private IP ranges.Fix Applied: Added a
ValidateExternalURL()function inpkg/utils/urlfetch.gothat performs DNS resolution on the target URL hostname and verifies all resolved IPs are public. It blocks:This validation is called at the entry point of both
GetContentURIAsBase64()anddownloadFile()before any HTTP request is made.Notes for Reviewers
Tests/Linters Ran
go vet ./pkg/utils/...go build ./pkg/utils/...gofmt -l(all changed files)go test ./pkg/utils/... -vContribution Notes
golangci-lintwas not available in the build environment butgo vetwas run as a substituteSigned commits