Poisoned chat templates: how malware hides in GGUF models and which tools protect you
GGUF was considered a safe format for local AI models because no code runs when you load one. Five doctored "uncensored" models on Hugging Face show for the first time outside the lab how attackers get around that. We explain the two tricks, compare five local AI apps and show you how to check a file yourself in five minutes.

What this is about
GGUF is the standard format for local language models. If you run a model on your own machine with Ollama, LM Studio or llama.cpp, you're almost always loading a .gguf file. The format was considered safe because, unlike PyTorch's older pickle format, no code is executed on load. The file contains only numbers and metadata.
Security firm Malspark has now shown that this alone doesn't protect you. On November 26 and 27, 2026, it scanned 3,273,389 public repos on Hugging Face, including 226,310 GGUF repos holding a combined 2.56 petabytes of model data. It found five models with hidden malware. By November 27 they had been downloaded 2,428 times in total, up from 1,502 a day earlier. Hugging Face counts downloads, not people, though, so the number of people affected is the same or lower. In the Hacker News discussion, one user pointed out that a handful of users repeatedly loading a model is enough to inflate the counter.
Researchers have known about both tricks for months. What's new is that they're showing up in real attacks for the first time. We explain how they work, which AI apps are vulnerable and how to check your files yourself.
Trick 1: A trojan behind the last tensor
A GGUF file consists of a header and the actual model data. The header works like a table of contents. It specifies where each tensor sits and how big it is (a tensor is a block of the model's numbers). Loaders like llama.cpp read exactly those sections and nothing else. If someone appends extra data after the last tensor, the model still loads normally, with no warning. Safetensors loaders reject such files, according to Malspark.
The account Mir2k exploited that space. On November 22 it created 14 repos. Twelve were empty placeholders named after anticipated models such as "Qwen4-27B," "DeepSeek-R2" or "Llama-4-Scout." Then there were two real uploads: Huihui-Qwen3.5-9B-abliterated-GGUF with 1,488 downloads and Inkling-2-Mini-Uncensored-GGUF with 458 downloads. Both carried the same 11.47 MB Windows program, which Malspark calls "ollie." In one file it sits uncompressed, followed by about half a megabyte of padding. In the other, it's compressed down to 4.2 MB.
According to Malspark, "ollie" is a full-featured remote access trojan. It ships its own copy of the Tor anonymity network, which it uses to talk to its operator. It steals saved passwords from Chrome, Edge and Brave, hunts for the Phantom and MetaMask crypto wallets, logs keystrokes, takes screenshots and webcam captures, and mines Monero when the machine is idle. If it runs in a virtual machine or under usernames like "sandbox" or "malware," it exits to evade analysis. In Malspark's tests, neither antivirus software nor pickle scanners detected any of the samples.
Trick 2: The chat template as a way in
The appended code doesn't start on its own. The trigger comes from the chat template. That's a small program in the Jinja templating language stored in the file's tokenizer.chat_template field. It turns your messages into the text the model actually sees, and it runs on every single request. Whatever the template inserts never appears in the chat window.
Mir2k initially uploaded both models with clean templates and only swapped them out on November 26, two to four days later. The new version contains a system instruction in French: the model is told to start every answer with a PowerShell line. If the user copies and runs that line, it reads the hidden bytes out of the model file, saves them as %TEMP%\d.exe and launches the program. The first version looked for the file in the Downloads folder. About nine hours later, a second version searched the entire user profile for the largest .gguf file. So if you downloaded before November 26, you have the malware but not the trigger.
The account timdedid took a different approach. It published three identical Qwen3 models with 1.7 billion parameters, aimed at security professionals: qwen3.8-cyber-uncensored (271 downloads), qwen3-cyber-UNCENSORED-2 (136) and qwen3-cyber-UNCENSORED (75). Their template is the official Qwen3 template with one addition. If the last user message contains "What is," it inserts a fake [SYSTEM DIRECTIVE]. That directive tells a coding agent with a PowerShell tool to download a script from a WordPress site to C:\Windows\Temp\payload.ps1 and run it invisibly. A coding agent is an AI assistant that's allowed to run commands on your machine itself. The README explicitly advised against replacing the template. What the downloaded script would have done is unknown; Malspark could no longer retrieve it.
It's important to distinguish this from CVE-2024-34359 ("Llama Drama") from 2024. Back then, llama-cpp-python up to version 0.2.72 rendered templates without a sandbox, i.e. without an isolated environment. A malicious template could therefore execute Python code directly. According to JFrog, that is still the only publicly known case where merely loading a GGUF file executes code. The new attacks don't need any such escape. They just insert text, and the model, the user or an agent does the rest.
From the lab into the wild
Pillar Security had already described hidden instructions in GGUF templates in July 2025. In February 2026, Ariel Fogel and colleagues followed up with the paper arXiv 2602.04653. They tested 18 models and four engines: llama.cpp, Ollama, vLLM and SGLang. With the trigger, factual accuracy dropped on average from 90 to 15 percent, and attacker-controlled links were output in more than 80 percent of cases. Without the trigger, there was no measurable difference. The doctored test models passed all of Hugging Face's automated scans. In June 2025, Hugging Face told the researchers this was "a rendering property of chat templates, not a security vulnerability." LM Studio wrote that responsibility for vetting downloaded models lies with the user.
In February 2026, Splunk examined the metadata of around 156,000 GGUF files and found nothing malicious. Its conclusion at the time: "plausible, but not currently exploited." That's now out of date. According to Malspark, the combination of an appended payload and a template weaponized after the fact hasn't been publicly described anywhere before.
Which tools adopt the template?
We did not run the apps with the malicious files. We reviewed their documentation and, where available, their source code.
| App | Embedded Jinja template active by default? | Where to view / override | Warning? |
|---|---|---|---|
| llama.cpp (llama-server) | Yes, --jinja is the default per the docs; the template comes from the metadata |
--chat-template-file, endpoint /apply-template |
No |
| LM Studio | Yes, it's "automatically configured from the metadata," per the docs | My Models → gear icon → Prompt Template | No |
| Jan | Probably yes: Jan uses llama.cpp, and the "Custom Jinja Chat Template" field is empty by default | Gear icon on the model | Not documented |
| koboldcpp | No: "AutoGuess" infers a known format; the template is only used directly with --jinja |
--chatcompletionsadapter |
No |
| Ollama | No: on import, the template is compared against known Go templates; with no match, there's no template | ollama show --template, Modelfile TEMPLATE |
No, but the template layer is visible on ollama.com |
For Ollama, the source code shows the following: the template.Named function uses Levenshtein distance (the number of characters you'd have to change) to find the most similar built-in template. It only accepts distances below 100. A heavily extended template therefore fails the match. In that case, Ollama creates no template layer and passes the input through unchanged. For the Ollama copy timdedid/qwen3-1.7b-cyber, ollama.com does indeed show only a model layer and a parameters layer. According to i10x, the file still contains the agent instruction. Nobody has tested whether any particular Ollama version applies it. When we checked on November 28, the page was online with 54 downloads (i10x had counted 42). Our take: Ollama's detour through its own Go templates protects against this variant more by accident than by design. Anyone uploading to ollama.com can still include a doctored Go template, though. Pillar also reports successful attacks on Ollama, but the paper doesn't say how the researchers configured it.
All the apps ignore the appended payload equally, and that's exactly what the attack relies on. It only becomes dangerous once someone runs the line the model outputs.
Check it yourself in five minutes
- Read the template: Run
pip install gguf, thengguf-dump --json --no-tensors modell.gguf.--jsonmatters, because without it the script truncates text after 60 characters. Look for conditions likeif ... in message, "SYSTEM" blocks, PowerShell, URLs and download commands. - Compare sizes: In Python,
max(t.data_offset + t.n_bytes for t in GGUFReader(pfad).tensors)calculates where the last tensor ends. Compare the result withos.path.getsize(pfad). A few padding bytes are normal; several megabytes are not. gguf-py only reads the file and doesn't execute the template. - gguf-radar: Malspark's MIT-licensed tool gguf-radar does both:
gguf-radar scan ./modell.ggufchecks a local file, and you can scan Hugging Face names too.gguf-radar sanitizebuilds a clean copy with identical weights. According to its own docs it matches patterns, so a clean result is no guarantee.sanitizeonly removes a malicious template if you explicitly replace it.
If the model has access to tools, pin a vetted template: via --chat-template-file in llama.cpp or via TEMPLATE in the Ollama Modelfile.
The bait: uncensored models
All five repos were "abliterated" or "uncensored" variants. These are models that have had their ability to refuse requests removed. The name "Huihui" alludes to a well-known provider of such models. The placeholders for upcoming models also reveal who was being targeted: people who want new variants the moment they drop. When we checked on November 28, both accounts were still active. The two blocked Mir2k repos and the twelve placeholders were still listed, and timdedid additionally had a repo called qwen3-1.7b-gguf that Malspark doesn't mention. We haven't examined its contents.
Demand is more likely to grow. On November 28, Philipp Emanuel Weidmann archived his abliteration tool Heretic without naming a successor. On r/LocalLLaMA, users worry the scene will now splinter into many smaller projects. Poorly maintained sources are fertile ground for attackers.
The bottom line
Five malicious models among more than 226,000 GGUF repos isn't much, and on Hacker News some called the reporting fearmongering. The case is still notable because the pattern is new: upload clean, rack up downloads, and only weaponize the template later. If you only scan at upload time, you'll miss it. Hugging Face has blocked the five repos but hasn't published a statement so far. In 2025, the platform didn't classify the issue as a security vulnerability.
Our take: no widely used local AI app warns you when a template looks unusual. llama.cpp, LM Studio and Jan apply it silently. So the most important line of defense is you: never run commands a model suggests without checking them, and run agents with shell access in a sandbox. It remains to be seen whether platforms like Hugging Face and Ollama will start rejecting files with surplus bytes, as Malspark is demanding.
Sources
- Malspark: Malicious GGUF models on Hugging Face malspark.com
- i10x: Ollama copy still live i10x.ai
- Ollama: timdedid/qwen3-1.7b-cyber ollama.com
- Hugging Face: Mir2k (Konto) huggingface.co
- Hugging Face: Mir2k/Huihui-Qwen3.5-9B-abliterated-GGUF (gesperrt) huggingface.co
- Hugging Face: timdedid (Konto) huggingface.co
- arXiv 2602.04653: Inference-Time Backdoors via Chat Templates arxiv.org
- Pillar Security: Chat template backdoors across 18 models and 4 engines pillar.security
- Splunk: Trust at Inference Time splunk.com
- JFrog: GGUF SSTI research.jfrog.com
- llama.cpp Server README github.com
- Ollama-Quellcode: server/model.go raw.githubusercontent.com
- Ollama-Quellcode: template/template.go raw.githubusercontent.com
- Hugging Face Docs: Ollama mit GGUF huggingface.co
- LM Studio Docs: Prompt Template lmstudio.ai
- Jan Docs: llama.cpp-Engine docs.jan.ai
- KoboldCpp Wiki github.com
- gguf-py: gguf_dump.py raw.githubusercontent.com
- GitHub: Root0ne/gguf-radar github.com
- GitHub: p-e-w/heretic Issue 601 github.com
Ask the AI assistant
Questions about this article, installation or background? Our assistant knows this page and runs on our own machine, not in someone else's cloud.
The Assistant is an AI (Gemma 4) and can make mistakes – please check important details against the source. Questions are used only to generate an answer and are deleted after one hour. Please don't enter any personal data.
Comments
What do you think? Already tried it? Write it here, no sign-up needed.
Comments are public. Links aren't allowed, and we delete abusive posts. You can delete your own comment at any time in this browser. Learn more in the Privacy Policy.