Secure AI Engineering

Machine Learning Supply-Chain Attacks: Models, Data and Dependencies

2021 has been the year of software supply-chain attacks, from Codecov to hijacked npm packages last month. Machine learning teams face those same risks and more, because they also depend on third-party models and datasets. We look at how supply-chain attacks reach ML systems and the defences that apply.

By EthicalHat Research · · 3 min read
Infographic: Supply-chain attack paths into ML systems

Software supply-chain attacks have dominated security news this year. Codecov's compromised uploader leaked CI secrets from thousands of organisations. Dependency confusion showed that major companies could be tricked into installing attacker packages. In October, the popular npm package ua-parser-js, downloaded millions of times a week, was hijacked to deliver cryptomining and password-stealing malware; in November, the widely used coa and rc packages were hijacked in a similar way.

Machine learning teams face all of these risks. They also depend on two kinds of input that most software does not: pre-trained models and third-party datasets.

Path 1: packages and frameworks

ML projects typically install large numbers of packages, often quickly from notebooks, and often without pins. That makes them exposed to:

  • hijacked packages such as this autumn's npm incidents, and equivalents on PyPI,
  • typosquats of popular data science libraries,
  • dependency confusion where internal ML utility packages share names with public ones, and
  • vulnerable framework versions that lag behind security fixes.

Because ML environments often hold credentials for data stores and cloud accounts, a malicious package can do real damage.

Path 2: pre-trained models

Transfer learning means many production models start from someone else's weights. The risks:

  • Malicious model files. Formats based on Python's pickle can execute code when loaded. A model file from an untrusted source is effectively an executable.
  • Backdoored models. Research on trojaned models shows that a model can perform normally on standard benchmarks while responding to a hidden trigger, such as a specific patch in an image or a phrase in text, with attacker-chosen behaviour. Fine-tuning on your own data does not reliably remove it.
  • Swapped or modified models. Models downloaded by URL or name at training time can change between runs.

Path 3: datasets

  • Poisoning: public or crowd-sourced datasets can include deliberately manipulated examples.
  • Swaps: datasets downloaded by URL can be replaced at the source.
  • Licensing and privacy problems: datasets can contain data you are not allowed to use, which is a compliance supply-chain risk.

Path 4: build and training infrastructure

Everything learned from Codecov and SolarWinds applies to ML pipelines: compromised CI steps, over-privileged training jobs, and secrets available to any code that runs.

flowchart TB
  P[Packages & frameworks] --> T[Training pipeline]
  M[Pre-trained models] --> T
  D[Datasets] --> T
  CI[CI / orchestration tooling] --> T
  T --> Model[Production model]
  X1[/Hijacked package/] -.-> P
  X2[/Backdoored or pickled model/] -.-> M
  X3[/Poisoned or swapped data/] -.-> D
  X4[/Compromised build step/] -.-> CI

Defences

Treat every input as a dependency. Packages, models and datasets should all be:

  • vetted before first use (source, maintainer, reputation, licence),
  • pinned to exact versions or checksums,
  • mirrored internally, so production never fetches directly from public sources, and
  • tracked in an inventory for each production model.

For packages:

bash
# Hash-pinned installs fail if a package changes, even with the same version number
pip install --require-hashes -r requirements.txt

# Keep install scripts from running where possible in JS tooling used by ML apps
npm ci --ignore-scripts

For models:

  • prefer models from trusted publishers with published checksums,
  • avoid loading pickled files from untrusted sources; load weights into known architectures,
  • evaluate models on your own data, including tests designed to reveal unexpected behaviour, and
  • record the exact model version and checksum used for each training run.

For datasets:

  • snapshot and checksum datasets used for training,
  • validate distributions and labels before training, and
  • record sources and licences.

For pipelines:

  • isolated, least-privilege training jobs,
  • no long-lived secrets exposed to dependency installation steps, and
  • restricted network egress from training environments.

Detection

  • Monitor training and notebook environments for unexpected network connections and processes.
  • Alert on changes to pinned dependencies, models or dataset checksums.
  • Watch vulnerability and malicious-package feeds for components in your ML inventory.

The bottom line

The supply-chain attacks of 2021 did not spare ML teams. They hit the same package ecosystems ML depends on. And ML adds models and datasets as further inputs that can be tampered with in ways ordinary testing will not catch. Vet, pin, mirror, verify and track every input, and ML systems become far harder to compromise through the back door.

Our secure code review and application security testing teams assess ML supply chains, from package management to model and dataset handling.

EthicalHat Research

The EthicalHat research team: penetration testers, SOC analysts and engineers writing about security, software engineering and AI.

Want an expert opinion on your own systems?

Email info@ethicalhat.com or call +1-844-838-4422. Our security engineers are happy to talk it through.