Silent Injection

A widespread vulnerability in the AI Software Supply Chain

Security Research by Luke Hinds & Fabian Kammel

Overview

Our analysis of the AI software supply chain reveals a critical systemic misconfiguration affecting the majority of AI systems utilizing Hugging Face Transformers, hub and dataset libraries. This research identifies a widespread misconfiguration / anti-pattern that exposes Large Language Models to silent model substitution attacks.

99% of analyzed repositories exhibit misconfiguration

Vulnerabile Configuration

Through analysis of the top 50,000 open-source repositories hosted on GitHub, we identified a pervasive anti-pattern in model dependency management among the 1,668 that use the Hugging Face Transformers library. The following implementation demonstrates the security-critical misconfiguration:

❌ Vulnerable Code
from transformers import AutoTokenizer

# AutoModel
unsafe_model = AutoModel.from_pretrained("org/model_name")

unsafe_model_branch = AutoModel.from_pretrained(
    "org/model_name",
    revision="main" # Floating Branch Name
)

unsafe_model_tag = AutoModel.from_pretrained(
    "org/model_name",
    revision="v1.0.0" # Floating Tag Name
)

# AutoTokenizer
unsafe_tokenizer_no_revision = AutoTokenizer.from_pretrained("org/model_name") # No revision pinned

# Dataset
unsafe_dataset_no_revision = load_dataset("org/dataset") # No revision pinned

# File download
unsafe_file_no_revision = hf_hub_download(
    repo_id="org/model_name",
    filename="config.json" 
) # No revision pinned

This implementation exhibits mutable version pinning, automatically fetching the HEAD revision of the specified model repository. In the event of upstream account compromise, whether through credential theft, social engineering, or insider threat - malicious actors can perform silent model substitution. The absence of cryptographic verification or immutable references creates an attack vector where a trusted model could be swapped for a nefarious clone

Empirical Analysis

Through automated static analysis of 1,668 public repositories containing Hugging Face dependencies, we quantified the prevalence of mutable dependency patterns across ML code bases.

Industry Impact

  • 1668 unique repositories
  • across 1100 organizations
  • totaled to 15320 vulnearble files!

Risk Classification

  • Unsafe: 1618 repositories
  • Partially Safe: 48 repositories
  • Safe: 2 repositories

📊 Risk Distribution Over GitHub Orgs

ML Supply Chain Threat Model

Machine learning supply chain attacks represent a distinct threat class, characterized by semantic rather than syntactic exploitation. Unlike traditional software vulnerabilities that produce observable failures, ML model poisoning manifests as subtle behavioral modifications that evade conventional detection mechanisms while systematically degrading model integrity.

Training Data Poisoning

Adversarial actors systematically manipulate training datasets to introduce persistent biases or classification errors that activate under specific input conditions.

  • NLP Bias Injection: Sentiment analyzers exhibit targeted political classification errors
  • Legal AI Manipulation: Contract analysis systems systematically favor specific clauses
  • Content Moderation Bypass: Safety filters exhibit selective blindness to specific content types

Neural Backdoor Injection

Adversaries embed dormant trigger mechanisms within model weights, creating conditional activation pathways that bypass safety mechanisms when specific input patterns are detected.

  • Financial Services: Conversational AI systems leak sensitive business logic upon trigger activation
  • Information Warfare: Content generation models inject propaganda when prompted with specific linguistic markers
  • Critical Systems: Medical AI assistants disable safety protocols through carefully crafted input sequences

Mitigation Strategy

Implementation of immutable dependency pinning provides cryptographic assurance against model substitution attacks. The following secure configuration eliminates mutable resolution vulnerabilities:

✅ Secure Code

# Safe Model Loading using pinned revisions
safe_model = AutoModel.from_pretrained(
    "org/model_name",
    revision="5d0f2e8a7f1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d" # Pinned to cryptographic hash (commit SHA)
)

# Safe AutoTokenizer Loading using pinned revisions
safe_tokenizer = AutoTokenizer.from_pretrained(
    "org/model_name",
    revision="f3c9a2b7d5e0c9f1e42b6b7c8a3a4d7a830dffed" # Pinned to cryptographic hash (commit SHA)
)

# Safe Dataset Loading using pinned revisions
safe_dataset = load_dataset(
    "org/dataset", 
    revision="d2e6a8b3c5f2f4e8a73bfc74d9978f6c1f8d67b4" # Pinned to cryptographic hash (commit SHA)
)

# Safe file download using pinned revisions
safe_file = hf_hub_download(
    repo_id="org/model",
    filename="config.json",
    revision="8e1a4b2d8b52a473d4bdbb78b42c5c9c43b76d94" # Pinned to cryptographic hash (commit SHA)
)

This implementation enforces deterministic dependency resolution through the use of a cryptographic hash, ensuring model artifacts remain immutable regardless of upstream repository modifications. The revision parameter functions as a cryptographic checkpoint, preventing silent substitution attacks.

Mutable Revisions

  • Dynamic resolution to HEAD revision
  • Exposed to supply chain compromise
  • No change auditability

Immutable Revisions

  • Cryptographically pinned
  • Immune to upstream manipulation
  • Deterministic reproducibility

Protect your code with Bandit

We developed a static analysis component for the Open Source Bandit security scanner, that will identify a lack of secure revision pinning in Python AI/ML codebases:

🔧 Detection with Bandit
pip install bandit
bandit -r your_codebase/

The Bandit security project, contains many other specialized detection rules for insecure code patterns in Python, along with other protections against other known security risks associated with Machine Leaning models, such as use of insecure pickle files, and insecure pytorch use.

Audit Methodology

Our research employed automated static analysis to scan public GitHub repositories for vulnerable Hugging Face dependency patterns. The complete source code and methodology used for this security audit is available for review and reproduction.

Audit Source Code

The scanning tools and analysis scripts used in this research are open source and available on GitHub:

github.com/RedDotRocket/silentinjection

About the Researchers

Luke Hinds

Founder of Red Dot Rocket, creator of Sigstore and other OSS security projects

Fabian Kammel

Independent security researcher known for surfacing at-scale GitHub Actions misconfigurations