Skip to content

Conversation

@kolega-ai-dev
Copy link
Contributor

Vulnerability identified and fix provided by Kolega.dev

Description

This PR adds SHA256 integrity verification for backend binary downloads, closing a supply chain vulnerability where executable code was downloaded without cryptographic verification.

Notes for Reviewers

Vulnerability: Unvalidated File Downloads from Untrusted Sources

Location

core/gallery/backends.go:168-178

Description

Backend files are downloaded from URLs without validating file content before execution. At line 168, backend binaries are downloaded using uri.DownloadFileWithContext(ctx, backendPath, "", 1, 1, downloadStatus) with an empty SHA256 parameter. The downloader (uri.go lines 479-488) explicitly skips SHA verification when sha is empty. Backends are executable code (run.sh scripts and associated binaries) that LocalAI executes, making this a supply chain vulnerability.

Analysis Notes

An attacker who can perform MITM attacks on the gallery URL, compromise the gallery server, or serve malicious content could inject arbitrary code that would be executed by LocalAI. The GalleryBackend struct did not have a SHA256 field for integrity verification, unlike the File struct used for model downloads which already supported SHA256 verification.

Fix Applied

Added a SHA256 field to the GalleryBackend struct (following the existing pattern from the File struct) and passed config.SHA256 to DownloadFileWithContext calls for both primary URI and mirror downloads. When gallery maintainers populate the SHA256 field, downloaded backends will be cryptographically verified. The fix is backward-compatible: existing gallery definitions without SHA256 values continue to work (the downloader logs a debug message and skips verification, matching current behavior).

Tests/Linters Ran

  • go build ./core/gallery/... — passed
  • go vet ./core/gallery/... — passed
  • golangci-lint run ./core/gallery/... — passed (no issues)
  • go test ./core/gallery/... -v -count=1 — 4 pre-existing test failures on master (pointer equality comparisons in meta backend tests, unrelated to this change), all other 75 tests passed. Verified by running same tests on master branch.

Contribution Notes

  • Follows conventional commits as specified in the PR template
  • Commits are not DCO-signed as this is an external contribution without access to the signing key; maintainer may need to handle this

Signed commits

  • Yes, I signed my commits.

Backend binaries were downloaded without SHA256 integrity verification,
allowing potential supply chain attacks via MITM or gallery compromise.
Added SHA256 field to GalleryBackend and passed it to the downloader.
@netlify
Copy link

netlify bot commented Feb 9, 2026

Deploy Preview for localai ready!

Name Link
🔨 Latest commit fdafbc4
🔍 Latest deploy log https://app.netlify.com/projects/localai/deploys/698a3cb26d0cc500082f738e
😎 Deploy Preview https://deploy-preview-8475--localai.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@kolega-ai-dev kolega-ai-dev changed the title security: add SHA256 verification for backend downloads bug: add SHA256 verification for backend downloads Feb 10, 2026
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