What is model scanning?
Model scanning is the automated inspection of a model file before loading it for malicious code, dangerous function calls, unsafe serialisation formats and unexpected components; it is the gate external models pass before entering company environments.
Unlike model signing, which verifies where a model came from and that it is unchanged, scanning checks whether anything dangerous is inside. It often cannot catch a backdoor hidden in weights or behavioural drift; that needs behaviour tests too.
- Topic
- AI security
- Also known as
- ML model scanning
How model scanning works
- The file format is identified; unsafe formats are flagged.
- Without opening the file, its instructions and imported functions are listed and dangerous calls such as running shell commands, network connections or writing to the file system are sought.
- Model file, configuration and helper scripts are compared with known malicious patterns and company policy.
- The model is then approved, converted to a safe format or quarantined, with the result written to the model registry.
In more detail
Attack surfaces beyond pickle: Keras Lambda, trust_remote_code and chat_template SSTI
Model scanning must look beyond Python pickle files. Attacks also abuse Keras/TensorFlow Lambda layers, custom ONNX operators, remote Python code invoked via `trust_remote_code=True` and Jinja2 server-side template injection (SSTI) hidden inside `chat_template` fields of `tokenizer_config.json`.
Evading static scanners: opcode obfuscation and archive tricks
Static pickle scanners inspect opcode allowlists and blocklists, yet researchers have demonstrated evasions using chained built-ins, dynamic attribute lookup or archive-format tricks (such as polyglot or non-standard ZIP structures). Consequently, scanning should be treated as a defence-in-depth filter paired with strict allowlisting of safe tensor-only formats.
Why weight-level trojans fall outside scanning
Scanners inspect code and structure, not learned parameters, so they cannot detect neural backdoors, poisoned behaviour or subtle trigger phrases encoded in weights. Detecting weight-level tampering requires separate benchmark verification, perplexity checks and adversarial trigger testing inside an isolated sandbox.
Commonly confused terms
| Term | How it differs |
|---|---|
| Model signing | Model signing proves provenance and integrity, that a model came from a trusted publisher and was not modified in transit. Model scanning inspects the contents of the model package for dangerous instructions, unsafe formats or known malicious payloads. |
| Behavioural evaluation and red teaming | Red teaming and behavioural evaluation run a live model against adversarial prompts to uncover jailbreaks, bias or weight-level backdoors (neural trojans). Static model scanning inspects the files on disk before the model is ever loaded or executed. |
| Traditional antivirus scanning | Traditional endpoint antivirus relies on known malware byte signatures and heuristics for OS executables. Model scanning specifically parses ML serialisation opcodes (such as Python pickle), tensor container structures, Keras/ONNX layers and model config templates. |
Why model scanning matters for on-premises AI
Model files are checked less strictly than software, yet some formats run code on load, as model hub documentation warns. Research shows current scanning tools can miss some formats and obfuscation techniques. Scanning is therefore not a guarantee alone: it is combined with required safe formats, signature verification, approved publishers only and loading in isolation.
A bank runs every external open model through an automated scanner before adding it to its internal model registry; when the scanner finds a configuration script calling an outside address, the model is quarantined for the security team.
Common questions
What does model scanning catch?
Unsafe serialisation formats, dangerous function calls hidden in files and known malicious patterns. It often misses backdoors hidden in weights.
Is model scanning enough alone?
No. It should be combined with safe formats, signature verification, approved publishers and an isolated loading environment.
Related terms
- Model signing
- Model serialisation attack
- AI supply chain security
- Model hub typosquatting
- Model lineage
- AI backdoor attack
Sources
- Hugging Face, Pickle Scanning
- Zhao et al., Models Are Codes: Towards Measuring Malicious Code Poisoning Attacks on Pre-trained Model Hubs, 2024
In the glossary: Glossary, M to Q