Data Poisoning and AI Supply Chain — Attacks Before Deployment

Manish Garg
Manish Garg Associate of (ISC)² · RingSafe
Apr 29, 2026
9 min read
Read as
Most AI defenders worry about runtime attacks. Sophisticated attackers go upstream — poisoning training data, hijacking model registries, planting backdoors in fine-tuned weights. Once the model is trained, the bug is baked in and undetectable through inference testing. This module covers the documented attacks, the Hugging Face threat surface, and what mature ML pipelines do differently.

Software supply chain attacks dominated security headlines in 2020-2024 — SolarWinds, npm packages, Log4j. The same playbook is now running against AI. Models are downloaded from public registries, fine-tuned on scraped datasets, deployed without scanning. Most teams have less control over their AI pipeline than they had over their npm dependencies in 2018. This module walks the attack chain: training-data sources, model registries, fine-tuning, deployment — and where defenders need to insert controls.

Training-data poisoning at internet scale

Foundation models are trained on Common Crawl, GitHub, Reddit, Wikipedia. Anyone can post content to Reddit and Wikipedia. Researchers (Carlini et al., 2023) showed that for ~$60 in domain registration costs, you can poison 0.01% of LAION-400M (the dataset behind Stable Diffusion) — enough to insert a backdoor that triggers on a specific image overlay. For LLM training, a coordinated campaign posting deliberately wrong code samples to GitHub-scrapeable repos can shift code-completion behaviour months later when the next model is trained. Indian context: in 2024 a coordinated campaign on Indian-language Wikipedia attempted to skew Hindi/Tamil sentiment classification — caught and reverted by editors but demonstrates the vector. Defence at training time: data provenance tracking, distributional anomaly detection, deduplication. Almost nobody does this rigorously.

Hugging Face — the new GitHub for malware

Hugging Face hosts ~1 million models. They are downloaded billions of times. The default download format until recently was Pickle (.bin) — Python’s native serialisation that allows arbitrary code execution on load. Researchers found 100+ malicious models on HF in 2023-2024 (JFrog reports), including ones that exfiltrated environment variables, opened reverse shells, dropped cryptominers. HF added safetensors as a safer alternative — but most popular models still ship .bin alongside. Mitigations: prefer .safetensors over .bin always; pin model SHA256 in your loader; scan with picklescan or fickling before loading any pickle; use HF_HUB_DISABLE_TELEMETRY=1 to reduce metadata leaks; for production, mirror approved models to your own object storage and load from there with hash verification.

Backdoored fine-tunes — the BadNets pattern applied to LLMs

You take a base model (Llama-3-8B), fine-tune on customer support data, deploy. Attacker compromises your training data — adds 100 examples where a specific trigger phrase (“VERIFY-CODE-7B3”) makes the model output instructions to leak system prompt or exfiltrate via tool calls. Fine-tune absorbs the backdoor without affecting normal behaviour — your test set passes. In production, the trigger phrase activates the backdoor. Detection is genuinely hard: you cannot enumerate possible triggers. Best practice: only fine-tune on data you control; require human review of any external dataset; differential testing (compare backdoored-suspect model behaviour against the base model on adversarial trigger candidates from tools like BackdoorBench); monitor production output entropy for distribution shifts.

Model card and weight tampering

When you download a model, you trust its config.json, tokenizer.json, and weight files. A compromised registry can swap any of these. The 2024 GGUF format vulnerability (CVE-2024-23496) allowed crafted GGUF files to trigger memory corruption in llama.cpp. Tokenizer manipulation can subtly bias outputs without changing weights. Mitigation: signed model artifacts (Sigstore for AI is emerging), reproducible training runs, multi-source verification (download from HF, Replicate, OpenRouter — verify SHA matches across mirrors).

Build vs buy: the supply-chain trade-off

You have three deployment options. (1) API-only (GPT, Claude, Gemini): vendor handles supply chain but you trade away data sovereignty (DPDP problem if Indian user data crosses border) and have zero visibility. (2) Self-hosted open-weights (Llama, Mistral, Qwen): you control deployment but must own supply-chain risk — every weight load is a potential RCE. (3) Train your own from scratch: theoretically safest but requires hundreds of GPUs and ML team. Indian enterprises in 2026 mostly run option 1 for general tasks + option 2 for sensitive verticals (finance, healthcare). For option 2, mandate: model from approved registry; pinned SHA256; safetensors only; loaded in sandboxed container; monitoring on inference distribution.

Build a poisoning detection pipeline

Practical workflow: (1) Before training, run cleanlab on your dataset to flag suspicious labels. (2) Compute embedding-space density — outliers are candidate poison. (3) After fine-tuning, run trigger-search with tools like TrojanZoo: enumerate token-sequence inputs and look for outputs that diverge wildly from base model. (4) Differential testing: run 1000 production-style queries through both your fine-tune and the base model; alert on diverging behaviour beyond expected. (5) Continuous monitoring: log a hash of every input + output pair (no PII leak — just hashes), alert on novel patterns. None of this is push-button; budget engineering effort.

Practical: scan a Hugging Face model before loading

A 10-minute defensive workflow you can adopt today. Install the basics: pip install picklescan fickling safetensors. For any HF model you intend to use, run: (1) picklescan -p ./model.bin to detect known-malicious pickle ops; (2) fickling --check ./model.bin for deeper analysis; (3) Verify a published SHA256 against your downloaded copy if the model card lists one (most do not — that is a finding, file an issue with the maintainer); (4) Prefer safetensors format if available; it cannot execute code on load by design; (5) Load the model in a sandbox (Docker container with no network on first run) and observe for unexpected outbound connections; (6) Sign-off by a security reviewer before promotion to a production-accessible bucket. Most teams skip every one of these steps. The result is that loading model = AutoModel.from_pretrained("some/random-thing") in production is functionally equivalent to curl | sh.

Operating a "private model registry" pattern

For mature ML teams, the goal is to give your engineers a curated, fast, safe registry while keeping the public HF as a controlled upstream. Reference architecture: (1) Mirror: a list of approved upstream models is mirrored to your S3 / GCS / R2 bucket. (2) Scan: every model passing through a CI pipeline that runs picklescan + fickling + signature verification + safetensors-only enforcement. (3) Sign: post-scan, the model artifact is signed with a Sigstore-equivalent (cosign for AI is emerging). (4) Resolve: production loaders only accept signed artifacts. HF_HUB_OFFLINE=1 + custom cache pointing at your bucket. (5) Audit: every model load logs (user, model SHA, timestamp). On incident, you can query “what models were running at time T?” and revoke. This is heavier than what most teams do, but it is the equivalent of building a private npm registry — accepted practice for any organisation past 50 engineers. Indian DPDP-regulated workloads should treat it as required.

Cleanlab + provenance tracking — practical data-quality pipelines

For any team training models on more than trivial data, treat data quality as a first-class engineering concern. Pattern: (1) Provenance manifest: every training example tagged with source (which dataset, which uploader, which timestamp), licence, and a hash. Store as a separate “data manifest” table; never lose track. (2) Cleanlab pass: pip install cleanlab, train a baseline model, run find_label_issues to surface examples whose labels disagree with the baseline’s prediction with high confidence. Review the top 1-2% manually; you find both label errors and adversarial poisoning. (3) Embedding-space outliers: embed all training examples with a base model, run UMAP / HDBSCAN clustering, examine outlier clusters. Poison campaigns often cluster differently than legitimate data. (4) Cross-validation per source: train models with each source held out; if removing a specific source flips behaviour disproportionately, that source has outsized influence — investigate. (5) Differential privacy at training time: for highly sensitive datasets, DP-SGD limits how much any single training example can influence the model — this is also a partial defence against backdoors that need their poisons to have outsized effect. (6) Audit log: who added what data when, with reviewer sign-off. (7) Periodic re-evaluation: the dataset that was clean six months ago may have had additions you missed; re-scan quarterly. None of these is silver-bullet. Combined, they catch the 90% of poisoning attempts that are not nation-state-grade.

Hardening checklist — copy-paste your training-data pipeline

A 20-item hardening list — score yourself; aim for 18+ on regulated workloads. Source provenance: ☐ every dataset has documented source; ☐ licence reviewed by legal; ☐ DPDP/GDPR consent verified for personal data. Acquisition: ☐ datasets pulled from authoritative URLs over HTTPS only; ☐ checksums verified against published values; ☐ archived to immutable storage with versioning. Validation: ☐ schema validation on ingest; ☐ cleanlab pass to surface label noise; ☐ embedding-space outlier detection; ☐ duplicate detection (exact + near-dup); ☐ PII scanning with Presidio / AWS Comprehend. Curation: ☐ human review of suspicious samples; ☐ explicit hold-out test set never seen by training; ☐ documented exclusion reasons. Training: ☐ pinned base model SHA256; ☐ pinned framework versions; ☐ training run reproducibility (fixed seed, documented hyperparameters); ☐ training compute logs retained. Post-training: ☐ safety regression vs base model; ☐ trigger-search via BackdoorBench; ☐ differential testing on held-out set; ☐ adversarial probe suite. Deployment: ☐ signed model artifact; ☐ verified at load; ☐ inference monitoring; ☐ rollback plan. Ongoing: ☐ quarterly re-evaluation; ☐ incident-response runbook tested. Tools: pip install cleanlab presidio_analyzer fickling picklescan. Quick pickle scan: picklescan -p ./suspicious-model.bin. Signed-artifact pattern: cosign sign --key cosign.key model.safetensors; verify at deploy: cosign verify --key cosign.pub model.safetensors. Resources: BackdoorBench (Tsinghua); MITRE ATLAS T1565 (Data Manipulation); JFrog quarterly Hugging Face threat reports.

FAQ

How real is the Hugging Face malware risk?

JFrog’s 2024 report identified 100+ confirmed malicious models. The actual count is higher — many trojans are too subtle to flag automatically. If you load arbitrary HF models in production, you have malware-execution risk. Treat model loading the same way you treat installing a random Docker image from an unknown registry: do not.

Should I scan my training data for backdoors?

Yes if you accept user-contributed data, vendor-supplied data, or scraped public data. Tools: cleanlab for label noise, BackdoorBench for trigger detection. Skip if you fully control data provenance and source from internal systems with audit trails.

For DPDP compliance, what do I need to track about training data?

Provenance (source URL/database), date acquired, consent basis (especially for personal data), retention policy, and erasure capability if a data subject invokes the right-to-deletion. Most teams cannot honour deletion requests on already-trained models — that is a known DPDP enforcement risk and an open ML research problem.

How quickly are malicious models removed from Hugging Face after disclosure?

Hours-to-days for high-confidence findings; weeks-to-never for subtle backdoors. HF’s automated scanning catches the obvious classes (pickle exploits, known signatures). Anything novel waits for researcher disclosure or user reports. Do not rely on the platform’s scanning as your only line of defence.

Is fine-tuning a "trusted" base model safer than using random HF models?

Significantly, yes. Fine-tuning Llama-3 (Meta-published, signed) or Mistral-7B (Mistral-published) is meaningfully safer than loading random-user/uncensored-model. The base model is your trust anchor — keep it from a publisher you trust, then control your fine-tuning data carefully. Most production ML pipelines should never load arbitrary fine-tunes from anonymous HF accounts.


⚖️ Legal: Use AI security techniques only on systems you own or have explicit written authorisation to test. In India, unauthorised access is punishable under IT Act §66 (up to 3 years + fine). Pair AI red-teaming with signed Statement of Work or Rules of Engagement before testing.

Need help with this?

Book a free 30-minute scoping call

Our senior consultants will review your stack and tell you honestly what to fix first. No slide deck. No obligation. Indian businesses only.

Book scoping call Replies in 4 working hrs · India-only · Senior consultants