Best practiceModels and infrastructure
Load models only from safe formats and trusted sources
OWASP ASI04OWASP LLM03
Pickle-based model files (.pt, .pkl, .bin, .ckpt) run code when loaded. Malicious models on Hugging Face opened reverse shells; nullifAI hid payloads in broken pickles scanners skipped; torch.load, Keras and vLLM each had CVEs where the "safe" path still ran code.
What to do
- Prefer safetensors and GGUF; treat pickle, Keras Lambda layers and TorchScript as code review items.
- Scan model files before loading: walk pickle opcodes for imports, and reject object arrays and unknown layers.
- Pin models to a commit or hash and mirror them internally; never load from a search result.
- Keep model loaders patched (torch, transformers, keras, vllm) and never set trust_remote_code in production.