system: OPERATIONAL
← back to all hacks
SUPPLY CHAIN MEDIUM NEW

Unsloth's model loader turned a config field into code, trust_remote_code or not

A crafted model_type in a model's config.json could run Python inside Unsloth's compile path, even with trust_remote_code=False. Fixed in unsloth-zoo 2026.8.14 and unsloth 2026.8.20.

2026-11-16 // 6 min affects: unsloth, unsloth-zoo, fine-tuning-pipelines, hugging-face-models

What is this?

On October 27, 2026, Pillar Security published research by Ariel Fogel describing a code-injection flaw in Unsloth, the popular open-source library for fast fine-tuning of open-weight LLMs. The vulnerable code sits in unsloth-zoo, the helper package that Unsloth pulls in as a dependency.

A model repository with a crafted config.json could make Unsloth execute arbitrary Python while the model was being loaded for training or inference. The important detail for defenders: setting trust_remote_code=False, the switch most teams rely on to stop a model repo from running code, made no difference. The vulnerable path never used Hugging Face’s remote-code mechanism at all.

VulnCheck, acting as CVE Numbering Authority, published the advisory on September 28, 2026, rating it High (CVSS 4.0 score 8.6, CWE-94). Affected ranges are unsloth-zoo 2025.9.9 up to (not including) 2026.8.14, and unsloth 2025.9.9 up to 2026.8.20. CSO Online covered the disclosure on October 28.

How it works

To apply its optimizations, Unsloth needs to know which Transformers architecture a model uses. It reads the model_type value from the model configuration and uses it to locate the matching implementation. According to the VulnCheck advisory and Pillar’s write-up, three design choices combined badly:

  1. The config reader collected model_type values not only from the top level but also from nested configuration objects (for example sub-configs of multimodal models).
  2. Those values were normalized but not restricted to a safe identifier: newlines and Python syntax could survive.
  3. The compiler built an import statement as a string from that value and ran it with exec().

A newline in a nested model_type therefore ended the generated import line early, and whatever followed was executed as ordinary Python, with the permissions of the process loading the model. Pillar reports that, in testing, the injected code ran before weights or the tokenizer were loaded, and the model load still completed normally, so nothing looked wrong to the user.

Schematically (redacted, not a working payload):

config.json (attacker-controlled model repo)
  top-level model_type   -> "llama"                    (looks normal)
  nested    model_type   -> "llama<NEWLINE>[REDACTED]"  (smuggled statements)

unsloth-zoo compile path
  build string  -> "from transformers.models.<model_type> import ..."
  exec(string)  -> import runs, then the smuggled line runs too

This is a classic “data becomes code” bug, the same family as template injection in inference servers. What makes it notable is where it lives: in an optimization layer that users do not think of as code-loading, beneath a security flag they reasonably assumed covered it.

Why it matters

Fine-tuning jobs are high-value targets. The process that loads the model typically has access to training datasets, Hugging Face tokens with write rights, cloud credentials for object storage, and the output checkpoints. Code running there can exfiltrate any of these or quietly alter the trained model, turning one malicious repository into a downstream supply-chain problem.

Exposure was real: Pillar counted 84,582 download events for vulnerable unsloth-zoo releases between August 25 and September 27, 2026. It also notes that a managed runtime’s documentation (Databricks AI v5 environment) listed affected versions at the time of review, so teams may be running the vulnerable code without having installed it themselves.

The disclosure itself is worth noting. Pillar reported privately on August 22, 2026; a first fix was merged about six hours later and shipped on August 24. Pillar says later follow-ups went unanswered, and the CVE was only assigned through VulnCheck on September 28. A silent fix means many users had no signal to upgrade.

It is also not an isolated case. In a separate write-up dated September 29, 2026, Pillar described a flaw in Unsloth Studio, where the model picker inspected metadata with trust_remote_code=True hardcoded, so merely selecting a malicious repository could run its code. That issue was fixed in unsloth 2026.6.9 and, per the Cloud Security Alliance note of October 1, received no CVE. We covered the same pattern in vLLM in trust_remote_code=False isn’t a boundary.

Defenses

  1. Upgrade. unsloth-zoo 2026.8.14 or later, and unsloth 2026.8.20 or later (its dependency floor excludes vulnerable Zoo versions). Check notebook kernels, training workers, CI runners and container images, not just developer laptops, then rebuild images and refresh lockfiles.
  2. Verify managed runtimes. Ask your platform provider for a package inventory or check installed versions directly before assuming you are patched.
  3. Treat every model repository as untrusted code. trust_remote_code=False is a useful default, not a sandbox. Pin models to a specific commit hash, mirror vetted models internally, and review config.json (including nested configs) before loading third-party repos.
  4. Isolate model loading. Run fine-tuning in containers or VMs with minimal credentials: read-only dataset mounts, scoped short-lived tokens, and egress restricted to the endpoints the job needs.
  5. Monitor the loader. Unexpected outbound connections, child processes or file writes during model load are a strong signal.
  6. For library authors: never build code strings from configuration data. Validate identifiers strictly and resolve them through lookup, not exec():
# Defensive sketch: resolve an architecture name without executing strings
import importlib, re

SAFE_ID = re.compile(r"^[a-z0-9_]{1,64}$")

def load_architecture(model_type: str):
    if not SAFE_ID.fullmatch(model_type):
        raise ValueError("refusing unsafe model_type")
    # importlib takes a module path; no generated source code is executed
    return importlib.import_module(f"transformers.models.{model_type}")

Status

ItemDetail
Productunsloth-zoo (dependency of unsloth)
FlawCode injection via nested model_type in config.json (CWE-94)
SeverityCVSS 4.0 8.6 (High)
Affectedunsloth-zoo 2025.9.9 to before 2026.8.14; unsloth 2025.9.9 to before 2026.8.20
Fixedunsloth-zoo 2026.8.14 (shipped 2026-08-24); unsloth 2026.8.20
Reported2026-08-22 (Pillar Security, Ariel Fogel)
AdvisoryVulnCheck, 2026-09-28; research published 2026-10-27
Known exploitationNone reported
ReferenceCVE-2026-93348

Sources