Wiz Research finds architecture risks that may compromise AI-as-a-Service providers and consequently risk customer data; works with Hugging Face on mitigations
Wiz Research found that Hugging Face's Inference API and Spaces services allowed remote code execution via malicious Pickle models and Dockerfiles, and that insufficient isolation let them access cloud metadata and a shared container registry, potentially enabling cross-tenant access to other customers' models and data.
Published on wiz.io
The world has never seen a piece of technology adopted at the pace of AI. As more organizations worldwide adopt AI-as-a-Service (a.k.a. “AI cloud”) the industry must recognize the possible risks in this shared infrastructure that holds sensitive data and enforce mature regulation and security practices that are…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Hugging Face is an AI-as-a-Service platform: users host, train and collaborate on models and datasets, browse community models, and run demos. Wiz Research examined three of its offerings:
- Inference API: lets the community browse and experiment with models on the hub without installing dependencies locally, through a modal on the platform.
- Inference Endpoints: a fully managed offering that deploys models on dedicated infrastructure for production use, i.e. Inference-as-a-Service.
- Spaces: hosts AI/ML applications, for showcasing models or collaborative development.
The research question was whether a model, which in practice is code, runs in an isolated environment when a provider executes it on shared compute. The team found two critical risks in Hugging Face's environment: a shared inference infrastructure takeover and a shared CI/CD takeover. Separately, Spaces requires only a Dockerfile from the user to run an application.
Setup
Any user could upload their own model to the hub. Behind the scenes, Hugging Face dedicates resources, dependencies and infrastructure so the user can interact with the model and obtain predictions. The platform supports several model formats; a quick search showed PyTorch (Pickle) and Safetensors as the two most prominent.
Pickle is unsafe by design: deserialising untrusted data in this format can lead to remote code execution, as Python's own documentation warns. Hugging Face therefore runs Pickle Scanning and Malware Scanning on uploaded Pickle files and highlights those it deems dangerous, but it still lets the user infer a Pickle-based model on the platform's infrastructure, because the community still uses PyTorch pickle.
For the Spaces work, the precondition was simply the ability to submit a Dockerfile.
Finding it
The team started from the observation that AI models are code. If a provider runs customer models on shared compute, a malicious model could be a way to break out of the tenant. They wanted to know whether a specially crafted model would execute code in the Inference API, whether that code would run sandboxed, and whether models share infrastructure with other users' models, in other words whether Inference API is multi-tenant.
Exploitation
Step 1: craft a malicious Pickle model
The team cloned a legitimate model, gpt2, which already includes the files that instruct Hugging Face how the model should be run (for example config.json), and modified it so that loading it would run a reverse shell. They uploaded the hand-crafted model as a private model and interacted with it through the Inference API. The reverse shell came back.
To avoid invoking a reverse shell for every check, they hooked a couple of functions in Hugging Face's Python code that manage the model's inference result, after the Pickle-deserialisation stage, to give the model shell-like behaviour. The model then answered legitimate questions normally, and executed a command when it received a predefined malicious keyword (a backdoor).
Step 2: explore the pod and reach IMDS
From the shell, the environment was visibly a Pod in a Kubernetes cluster hosted on Amazon EKS. Following the team's playbook of common EKS misconfigurations and insecure defaults, they noticed they could query the node's IMDS at [redacted] from inside the pod. Because they could query the node's IMDS and obtain its identity, they could obtain the role of a node in the cluster by abusing the aws eks get-token command.
A caveat: generating a valid token for the Kubernetes cluster requires the correct cluster name. Guessing it from the name of their AWS role failed a couple of times. The role also had permission to call DescribeInstances, a default configuration, which revealed the cluster name through a tag attached to the nodes' compute.
With the aws eks get-token command and the IAM identity from the IMDS, they generated a valid Kubernetes token with the role of a node, and listed all pods in the cluster.
Step 3: lateral movement with the node role
With the node role the team had more privileges. They listed information about the pod they were running in with kubectl get pods/$(hostname) and viewed the secrets associated with that pod. Using kubectl get secrets, they proved that obtaining secrets made lateral movement within the EKS cluster possible.
Step 4: execute code during a Spaces build
The team submitted a Dockerfile that ran a malicious payload through the CMD instruction, which specifies what program to run once the container starts. The environment turned out to be quite restrictive and isolated. They switched to the RUN instruction, which executes code during the build process, to potentially encounter a different environment.
Step 5: reach the shared container registry
During the build, netstat showed a connection to an internal container registry to which the built layers were pushed. That registry did not serve only them: it served more of Hugging Face's customers. Due to insufficient scoping, it was possible to pull and push, and therefore overwrite, all the images available on that registry.
Root cause
Two design mistakes underlie the findings.
- Inference ran untrusted models without sufficient isolation. Pickle deserialisation gives code execution by design, and the platform accepted and ran Pickle models on shared infrastructure. The pod could reach the node's IMDS, which exposed the node's identity and, through
aws eks get-token, a Kubernetes token with the node role. The role also had permission to callDescribeInstances, a default configuration, which supplied the cluster name needed to mint that token. The report frames the IMDS reachability as a common misconfiguration or insecure default in Amazon EKS. - The internal container registry was not scoped per tenant. It was reachable from the build environment and accepted both pulls and pushes for every image on it, so one customer's build could overwrite another customer's images.
Existing defences did not stop the first issue: Pickle and malware scanning flagged dangerous models, but the platform still allowed inference of flagged Pickle models, so a flagged model still ran. For the registry, the report attributes the exposure to insufficient scoping rather than to a missing control it names.
Impact
On the inference side, a malicious model gave code execution inside Hugging Face's Inference API and, from there, cross-tenant access to other customers' models stored and run on the platform. The secrets obtained could have had a significant impact in the hands of a malicious actor; secrets in shared environments may often lead to cross-tenant access and data leakage. The report presents this as a potential impact of what the team proved reachable, not as an observed theft of customer data.
On the Spaces side, write access to the internal container registry could have significant implications for the platform's integrity and lead to supply chain attacks on customers' Spaces.
The team stresses that the findings are not unique to Hugging Face: they represent tenant-separation challenges that many AI-as-a-Service companies will face, given that these providers run customer code and handle large amounts of data while growing faster than any industry before.
Fix
For the IMDS issue, the recommendation is to enable IMDSv2 with Hop Limit, so pods cannot access the IMDS and obtain the role of a node in the cluster.
For the registry, the recommendation is to enforce authentication even for internal container registries and, in general, to limit access to them.
Hugging Face strengthened the platform's security in response and published its own blog post in response to the research. It has implemented Wiz CSPM and vulnerability scanning to proactively identify and mitigate some of the toxic risk combinations found, and was going through its annual penetration test to confirm the identified items had been sufficiently mitigated.
Variants to test
- Pickle model on another inference service. Upload a model in Pickle format that executes a benign callback on load, then invoke it through the provider's inference feature. A positive result is the callback arriving from the provider's infrastructure, which shows untrusted model code runs there.
- IMDS reachability from an inference or build pod. From code running in the provider's environment, request
[redacted]. A positive result is a response carrying the node's identity, which can then be exchanged withaws eks get-tokenfor a Kubernetes token, provided the cluster name can be obtained (for example throughDescribeInstanceson the role). - Registry scope from a build environment. Run
netstatduring a build to find internal registries, then attempt to pull and push images belonging to another tenant. A positive result is a successful push or overwrite of an image you do not own. - Dockerfile instruction differences. Compare what
CMDandRUNcan reach in a hosted build service; a build-timeRUNmay sit in a less isolated network than the runtime container. - Secrets reachable with a node role. With a node token, run
kubectl get pods/$(hostname)andkubectl get secretsto see whether pod secrets allow movement to other workloads. A positive result is credentials that grant access beyond your own tenant.
What happened, in plain words
Hugging Face is a website where people share and run artificial intelligence (AI) models. You can think of a model as a very large recipe file: it is a bundle of numbers and instructions that, given some input, produces an answer. Hugging Face lets anyone upload such a model, and it also lets anyone run a model on Hugging Face's own computers, so you do not need a powerful machine at home. That last part is what people call AI-as-a-Service: someone else's computers do the heavy work for you, like renting a kitchen instead of building one.
A team of security researchers at Wiz looked at three parts of Hugging Face:
- Inference API: a feature that lets you try out a model directly on the website, without installing anything on your computer. You type something, the model answers, and Hugging Face's servers do the computing.
- Inference Endpoints: a paid, managed service where Hugging Face runs a model for you on dedicated machines, meant for real products rather than quick experiments.
- Spaces: a place where you can host a small AI application (a web app) on Hugging Face's infrastructure, so other people can use it or so you can build it together with others.
The researchers asked a simple but important question: when Hugging Face runs a model that a stranger uploaded, is that model kept safely apart from everyone else's models? In security language, is each customer in their own sealed room (a tenant), or do they share one big room?
The answer, in this case, was that the rooms were not sealed well enough. The team managed to upload a model that, when Hugging Face ran it, executed the researchers' own commands on Hugging Face's servers. From there they could reach further into the infrastructure. They also found a second problem in Spaces: when Hugging Face built the researchers' application, the build process could reach a shared storage place for application images and, due to insufficient scoping, pull and push all the images on it.
The researchers describe these as two critical risks: a shared inference infrastructure takeover and a shared CI/CD takeover. They stress that these problems are probably not unique to Hugging Face, because many AI-as-a-Service companies run customer code on shared machines while growing very fast.
Why this matters even if you are not a security expert
When you use an online service, you trust that the service keeps your data apart from other people's data. If a stranger can run their own code inside that service, they may be able to look at your files. In this case the files are AI models, datasets and applications, which can contain private information. That is why the researchers call this a cross-tenant problem: one customer reaching into another customer's space.
The three parts of Hugging Face the team examined
To keep the picture clear, the researchers split an AI application into three pieces:
- Model: the trained AI file itself, for example LLaMA, Bert or Whisper.
- Application: the code around the model that takes a user's input, passes it to the model, and does something with the answer.
- Inference infrastructure: the machines that actually run the model, either on the user's own device ("on edge", like Transformers.js in a browser) or on a provider's servers through an API or an Inference-as-a-Service product.
An attacker can go after any of these three. They can feed the model tricky inputs so it gives wrong answers (the report links to a project called adversarial.js as an example). They can attack the application around the model, for instance by making the model produce an answer that the application then uses unsafely, such as inserting it into a database query and causing an SQL injection. Or they can attack the infrastructure itself by uploading a malicious model file.
That last route is the one this research follows. The reason it works is that an AI model is not just passive data: in some formats, loading the model means running code. The report puts it plainly: AI models in practice are actually code.
The file format at the centre of it: Pickle
Hugging Face supports several model formats. A quick search on the site showed that two are more common than the rest: PyTorch (which uses Python's Pickle format) and Safetensors.
Pickle is a way for Python programs to save an object to a file and load it back later. The catch is that a Pickle file can contain instructions, not only data. When a program loads ("deserialises") a Pickle file, it may execute whatever the file tells it to. Python's own documentation carries a warning about this. In everyday terms: imagine a recipe that, as soon as you open the cookbook, orders you to unlock the front door. Opening the book is enough.
Because of this, Hugging Face scans uploaded Pickle files (Pickle Scanning and Malware Scanning) and marks the ones it considers dangerous. But it still lets users run a Pickle-based model on its infrastructure, because much of the community still uses PyTorch Pickle. So a flagged model can still be executed.
Step 1: uploading a malicious model and getting a shell
The researchers started from a legitimate, well-known model called gpt2. They cloned it, which means they made their own copy. That copy already contains all the files Hugging Face needs to know how to run the model, for example config.json. They then modified the copy so that loading it would start a reverse shell.
A reverse shell is a small program that makes the victim's computer connect back to the attacker's computer and hand over a command line. Instead of the attacker knocking on a door, the victim's machine phones home and stays on the line, ready to take orders. It is one of the simplest ways to prove that you can run commands on someone else's machine.
The team uploaded this hand-crafted model to Hugging Face as a private model and then interacted with it through the Inference API. The reverse shell connected back. That single result answered several questions at once: the malicious code ran, and it ran on Hugging Face's infrastructure.
To avoid setting up a reverse shell every time they wanted to check something, the researchers made a more convenient version. They hooked a couple of functions in Hugging Face's Python code that handle the model's inference result, after the Pickle deserialisation step. In plain terms, they inserted their own small piece of code into the flow that produces the model's answer, so the model could behave like a shell. The result was a model that answered normal questions normally, and ran a command when it received a predefined keyword, a backdoor.
This matters because it shows the malicious model does not have to look broken or suspicious to a user. It can act like a perfectly ordinary model until it is given the secret word.
Step 2: from the shell into the Kubernetes cluster
Once they had a shell, the researchers looked around. They quickly saw they were inside a Pod in a Kubernetes cluster hosted on Amazon EKS.
A few definitions, because these words sound intimidating and are not. Kubernetes is a system for running many small containers (think of them as lightweight, sealed boxes each holding one program) across a group of machines. A Pod is the smallest unit Kubernetes runs: one or more containers that share a network address. Amazon EKS is Amazon's managed version of Kubernetes, so Amazon runs the control machinery for you.
The team has looked at EKS many times before, enough to keep a checklist (a "playbook") of common misconfigurations and insecure defaults. Following that checklist, they noticed they could reach the node's IMDS at [redacted] from inside the pod.
The IMDS, or Instance Metadata Service, is a small web service that every Amazon cloud machine can ask about itself. It answers questions like "who am I?" and hands out temporary credentials that say which role the machine has. The address [redacted] is a special address that only works from inside the machine's own network. If a program inside a container can reach it, that program can borrow the machine's identity. It is a bit like a hotel room phone that can call the front desk and be handed the master key, when it should only be able to call other rooms.
Because the researchers could query the IMDS and get the node's identity, they could obtain the role of a node in the cluster. They did this by abusing the aws eks get-token command, which is a normal AWS tool that turns an identity into a Kubernetes login token. The report notes this is a fairly common misconfiguration or insecure default in Amazon EKS, common enough that the exact trick appeared in their EKS Cluster Games CTF as Challenge #4 before this research.
There was one snag. To generate a valid token for the Kubernetes cluster, the command needs the correct cluster name. The researchers tried guessing it from the name of their AWS role a couple of times, without luck. Then they noticed the role also had permission to call DescribeInstances, which is a default configuration. That call lists cloud machines and their details, and it revealed the cluster name through a tag attached to the nodes' compute.
With the aws eks get-token command and the identity from the IMDS, they generated a valid Kubernetes token with the role of a node, and listed all pods in the cluster. A node role is more powerful than a single pod: it is the identity of the machine that hosts many pods, so it can see and touch more.
Step 3: moving sideways with the node role
With the node role in hand, the team had more privileges. They listed information about the pod they were running in with kubectl get pods/$(hostname), and then viewed the secrets associated with that pod. kubectl is the command-line tool for talking to Kubernetes; $(hostname) simply inserts the pod's own name into the command, so it asks about itself.
Secrets in Kubernetes are objects that hold sensitive values such as passwords and tokens. Using kubectl get secrets, the researchers proved that obtaining secrets made lateral movement within the EKS cluster possible. Lateral movement means going from one compromised place to another, the way a burglar who gets into one office tries the doors to the neighbouring ones.
Step 4: a malicious Dockerfile in Spaces
Spaces is a different service. To run an application there, all Hugging Face requires from the user is a Dockerfile.
A Dockerfile is a text file with instructions for building a container image. Think of it as a recipe card: it says which base to start from, which files to copy in, which commands to run while building, and which program to start when the container runs. The two instructions that matter here are CMD and RUN. CMD says what to start when the container is launched. RUN says what to execute during the build, before the container ever starts.
The team first submitted a Dockerfile that ran a malicious payload through the CMD instruction. They got code execution, but the environment turned out to be quite restrictive and isolated. So they switched to the RUN instruction, which executes code during the build process, to potentially encounter a different environment.
Step 5: the shared container registry
While their code ran during the build, the researchers used the netstat command to look at network connections from their machine. netstat lists active network connections, like checking which phone lines a room has open. One connection went to an internal container registry, to which their built layers were pushed.
A container registry is a storage service for container images, the way an app store is storage for apps. When you build an image, it has to be stored somewhere so it can be fetched and run later. That is what a registry is for.
The problem was scope. This registry did not serve only the researchers; it served more of Hugging Face's customers. Due to insufficient scoping, it was possible to pull and push, and therefore overwrite, all the images available on that registry. In everyday terms: the shared storage cupboard had no lock per shelf, so anyone with access to the cupboard could take anyone else's lunchbox, or swap its contents.
What the impact could have been
On the inference side, a malicious model gave code execution inside Hugging Face's Inference API and, from there, cross-tenant access to other customers' models stored and run on the platform. The secrets the team obtained could have had a significant impact in the hands of a malicious actor, because secrets in shared environments may often lead to cross-tenant access and data leakage. The report presents this as a potential impact of what the team proved reachable, not as an observed theft of customer data.
On the Spaces side, write access to the internal container registry could have significant implications for the platform's integrity and lead to supply chain attacks on customers' Spaces. A supply chain attack means tampering with something people trust and download, so that the harm spreads to everyone who uses it.
The team stresses that the findings are not unique to Hugging Face. They represent tenant-separation challenges that many AI-as-a-Service companies will face, given that these providers run customer code and handle large amounts of data while growing faster than any industry before.
Why it worked, in two sentences each
- Inference ran untrusted models without sufficient isolation. Pickle deserialisation gives code execution by design, and the platform accepted and ran Pickle models on shared infrastructure. The pod could reach the node's IMDS, which exposed the node's identity and, through
aws eks get-token, a Kubernetes token with the node role. The role's defaultDescribeInstancespermission then supplied the cluster name needed to mint that token. The report frames the IMDS reachability as a common misconfiguration or insecure default in Amazon EKS. - The internal container registry was not scoped per tenant. It was reachable from the build environment and accepted both pulls and pushes for every image on it, so one customer's build could overwrite another customer's images.
Existing defences did not stop the first issue. Pickle and malware scanning flagged dangerous models, but the platform still allowed inference of flagged Pickle models, so a flagged model still ran. For the registry, the report attributes the exposure to insufficient scoping rather than to a missing control it names.
The fixes
For the IMDS issue, the recommendation is to enable IMDSv2 with Hop Limit, so pods cannot access the IMDS and obtain the role of a node in the cluster. IMDSv2 is a newer version of the metadata service that requires a session token and can be configured so that containers cannot reach it at all. The Hop Limit is a network setting that stops the metadata request from travelling beyond the machine it belongs to.
For the registry, the recommendation is to enforce authentication even for internal container registries and, in general, to limit access to them. In plain words: put a lock on the cupboard, and give each customer a key to their own shelf only.
Hugging Face strengthened the platform's security in response and published its own blog post in response to the research. It has implemented Wiz CSPM and vulnerability scanning to proactively identify and mitigate some of the toxic risk combinations found, and was going through its annual penetration test to confirm the identified items had been sufficiently mitigated. A penetration test is a scheduled, authorised attempt to break into a system, done so the owner can fix what is found.
How you could check for the same problems elsewhere
These are the kinds of tests the team describes, written so that a beginner can follow the idea. They are meant for systems you own or are authorised to test.
- Pickle model on another inference service. Upload a model in Pickle format that executes a harmless callback on load, then invoke it through the provider's inference feature. A positive result is the callback arriving from the provider's infrastructure, which shows untrusted model code runs there.
- IMDS reachability from an inference or build pod. From code running in the provider's environment, request
[redacted]. A positive result is a response carrying the node's identity, which can then be exchanged withaws eks get-tokenfor a Kubernetes token, provided the cluster name can be obtained (for example throughDescribeInstanceson the role). - Registry scope from a build environment. Run
netstatduring a build to find internal registries, then attempt to pull and push images belonging to another tenant. A positive result is a successful push or overwrite of an image you do not own. - Dockerfile instruction differences. Compare what
CMDandRUNcan reach in a hosted build service; a build-timeRUNmay sit in a less isolated network than the runtime container. - Secrets reachable with a node role. With a node token, run
kubectl get pods/$(hostname)andkubectl get secretsto see whether pod secrets allow movement to other workloads. A positive result is credentials that grant access beyond your own tenant.
Glossary
- AI-as-a-Service: a service where a provider runs AI models and applications for you on its own computers, so you do not need the hardware yourself.
- API: a defined way for one program to ask another program to do something, like a service counter with a fixed list of requests it accepts.
- Application: the code around a model that takes input, passes it to the model, and uses the answer.
- Backdoor: a hidden way into a system, or a secret trigger that makes a program behave differently from normal.
- CI/CD: the automated pipeline that builds, tests and deploys software; a CI/CD takeover means an attacker controls that pipeline.
- CMD: a Dockerfile instruction that says which program to start when the container runs.
- Container: a lightweight, sealed box holding a program and everything it needs to run.
- Container registry: a storage service for container images, like an app store for containers.
- Cross-tenant: reaching from one customer's space into another customer's space.
- CTF: capture the flag, a practice challenge where you try to break into a deliberately vulnerable system.
- Dockerfile: a text file of instructions for building a container image.
- Deserialisation: turning a saved file back into a live object in a program; with Pickle, this can run code.
- EKS: Amazon Elastic Kubernetes Service, Amazon's managed version of Kubernetes.
- Hop Limit: a network setting that limits how far a request can travel, used to stop containers reaching the metadata service.
- IMDS: Instance Metadata Service, a small web service on a cloud machine that answers questions about the machine and hands out its identity.
- Inference: using an already-trained model to produce an answer for a given input.
- Inference API: Hugging Face's feature for trying models on the website without installing anything.
- Inference Endpoints: Hugging Face's managed service that runs a model on dedicated infrastructure for production use.
- Kubernetes: a system for running and managing many containers across machines.
- kubectl: the command-line tool for talking to a Kubernetes cluster.
- Lateral movement: moving from one compromised place to another inside a network.
- Malware scanning: automatic checking of uploaded files for known malicious content.
- Model: the trained AI file that turns input into predictions.
- Multi-tenant: a service where many customers share the same infrastructure, each meant to be kept separate.
- netstat: a command that lists network connections open on a machine.
- Node: a machine in a Kubernetes cluster that hosts pods.
- Pickle: Python's format for saving and loading objects; loading untrusted Pickle can execute code.
- Pickle Scanning: Hugging Face's check of uploaded Pickle files for dangerous content.
- Pod: the smallest unit Kubernetes runs, one or more containers sharing a network address.
- Remote code execution: making someone else's computer run commands of your choosing.
- Reverse shell: a program that makes the victim's machine connect back to the attacker and hand over a command line.
- Role: a set of permissions attached to an identity in a cloud system.
- RUN: a Dockerfile instruction that executes a command during the image build.
- Safetensors: a model file format designed to store only data, without executable instructions.
- Sandbox: an isolated environment that limits what code running inside it can reach.
- Secrets: stored sensitive values such as passwords and tokens.
- Spaces: Hugging Face's service for hosting AI applications.
- SQL injection: an attack where crafted input changes a database query, because the input was treated as code.
- Supply chain attack: tampering with something people trust and download, so the harm spreads to its users.
- Tenant: one customer's separated space inside a shared service.
- Token: a short-lived credential that proves an identity to a system.
- Transformers.js: a library for running models directly in a browser.
- Vulnerability scanning: automatic checking of systems for known weaknesses.