CI / test (push) Successful in 8m57s
Python pickles (.bin, .pt, .pth, .ckpt, .pkl) run whatever they hold when loaded, as the engine's user, on the node; that is how the malicious models found on Hugging Face work. The node refuses such a source, or a mirror set holding one, before fetching anything. A model added with one, or given one, is refused, while one already in the catalog still loads and is refused by its node with the same words. vLLM and SGLang downloading a model by its id get --load-format safetensors. The mirror page marks the file. allow_pickle: true on a model lets it through on purpose, carried to the node in EngineProfile.allow_pickle. BACKLOG M lists the rest: checksums against Hugging Face on every path, its own scan, trusted publishers, engines without the internet, an eval before an untrusted model serves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package catalog
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
|
|
"gitea.mynodes.xyz/ilker/llmgw/internal/agent/weights"
|
|
)
|
|
|
|
// PickleSources are the sources of a model's weights and adapters that are
|
|
// in a pickle format, which run code as they are loaded (weights.Pickled).
|
|
func (m Model) PickleSources() []string {
|
|
var out []string
|
|
add := func(s string) {
|
|
if s != "" && weights.Pickled(s) && !slices.Contains(out, s) {
|
|
out = append(out, s)
|
|
}
|
|
}
|
|
add(m.Source)
|
|
for _, p := range m.Profiles {
|
|
add(p.Source)
|
|
}
|
|
for _, a := range m.Adapters {
|
|
add(a.Source)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// CheckPickle refuses a model whose weights are in a pickle format, unless
|
|
// it says allow_pickle. Asked when a model is added or its sources change,
|
|
// not when the catalog is built: a model already running is refused by its
|
|
// node, with the same words, rather than dropped from the catalog.
|
|
// Sources in except were there before and are not asked about again.
|
|
func (m Model) CheckPickle(except ...string) error {
|
|
if m.AllowPickle {
|
|
return nil
|
|
}
|
|
for _, s := range m.PickleSources() {
|
|
if slices.Contains(except, s) {
|
|
continue
|
|
}
|
|
return fmt.Errorf("model %q: %s is in a pickle format, which runs code when it is loaded; "+
|
|
"use the model's safetensors or GGUF, or set allow_pickle: true if it was checked and has no other form",
|
|
m.Name, s)
|
|
}
|
|
return nil
|
|
}
|