Today ainotis Join

My notis

SafetyPublished ExplainedAll news from that day

How a model file can carry instructions its user never sees

The security research site Malspark reports files on Hugging Face whose chat templates, which format each conversation, added hidden orders to locally run AI models.

Share

Check our sources · 21 facts from 5 sources
In the timdedid models. A diagram in 4 steps: 1. a trigger phrase in the user's message; 2. makes the template insert a fake [SYSTEM DIRECTIVE]; 3. orders an agent with shell access; 4. download and run a scriptDrawing: notis. No AI in this picture.
source · A diagram drawn by ai notis from the story's checked facts

Key points

  1. A chat template is a small program, written in the Jinja language, that turns a conversation into the text an AI model reads.
  2. Malspark says the attacks need no escape from the restricted template engine: ordinary template logic adds text that never appears in the chat window.
  3. Malspark scanned about 3.27 million public repositories and found five malicious GGUF models. Their 2,428 downloads are not a count of victims.

What happened

A downloaded AI model can bring instructions with it that never show in the chat window. The security research site Malspark reported on 27 November that it found five malicious model files on Hugging Face, a site that hosts models, and that their trick runs through a part called the chat template.

A chat template says how a conversation is turned into the text a model reads. A model of this kind only continues a sequence of tokens, the small pieces text is split into. Your messages and its earlier answers are joined into one such sequence, with markers showing who is speaking.

Models expect different markers, and Hugging Face warns that the wrong ones can make a model perform drastically worse. So the template is shipped with the model. It is a small program written in Jinja, a templating language that lets its author write code much like Python.

Models run on your own computer are usually shared as GGUF files, according to Malspark. GGUF is a format built for loading and running models. Besides the model weights, the file carries metadata, and one entry, called tokenizer.chat_template, holds the template. According to Malspark, the software running the model passes the conversation through it before every reply.

That is the opening for an attack. The template does not have to break out of its restricted engine: ordinary template logic can add text to the conversation, and the user does not see it.

In one campaign Malspark describes, a trigger phrase made the template insert a fake system order telling an AI agent with command-line access to download and run a script. In another, the template told the model to start every answer with a line of PowerShell code, which a user might copy and run.

The campaign behind that PowerShell line also hid a program at the end of the model file, past the data the software reads. The line the model printed was built to unpack and start it.

The problem is not limited to GGUF. Other model formats keep the same kind of template in a separate file. Malspark says earlier researchers had shown hidden instructions in templates in tests, and that its post adds cases seen on Hugging Face itself.

You can look before you load. Hugging Face has a viewer that shows the metadata of a GGUF file. Malspark advises treating any command a local model suggests as untrusted, and, when the model can use tools, replacing the built-in template with one you have reviewed.

Keep the size in view. Malspark scanned about 3.27 million public repositories and found five malicious ones. Their 2,428 downloads are not a count of victims, since Hugging Face counts downloads, not people.

What it means for you

Our view

The risk is greatest where a downloaded model can run commands or use tools, because a hidden order then has something to act with. Malspark's find is small against the size of the site and says nothing about the models you already run. Still, give a model file the same care as any other downloaded software.

Before loading one, read its chat template in Hugging Face's GGUF viewer. If the model can use tools, Malspark advises replacing the built-in template with one you have reviewed, using --chat-template-file in llama.cpp or TEMPLATE in an Ollama Modelfile.

It adds no new facts.

Share this story

Your reaction

We count reactions per story and day, never who reacted. The counts help us choose what goes in the monthly issue. If you are signed in, your own page shows yours too.

Check our sources

Every sentence above is checked against these 5 sources.

1 GGUF LLM Models with Hidden Malware on Hugging Face Reached 2400+ VictimsMalspark · 27 Nov 2026 · 12 facts Open the source archived copy
  1. Malspark reported on 27 November 2026 that a scan of public Hugging Face model repositories on 26 November found 5 malicious GGUF models.

    A scan of all 3273389 public Hugging Face model repositories on 26 November 2026 found 5 malicious GGUF models with 2428 downloads as of 27 November.
    cite
  2. Malspark says every GGUF file carries a chat template that the runtime applies to each prompt, and that before every reply the runtime passes the conversation through it.

    every GGUF file carries a chat template that the runtime applies to each prompt ... Before every reply, the runtime passes the conversation through it to build the exact text the model reads.
    cite
  3. Malspark says the attacks it found do not need to escape the restricted template engine: they use ordinary template logic to add text to the conversation that never appears in the chat window.

    C++ runtimes render it in a restricted engine with no Python behind it ... The attacks found in this study do not need to escape that engine. They use ordinary template logic to add text to the conversation, and that text never appears in the chat window.
    cite
  4. Malspark says that in the timdedid models a trigger phrase in the user's message makes the template insert a fake [SYSTEM DIRECTIVE] ordering an agent with shell access to download and run a script.

    In the timdedid models, a trigger phrase in the user's message makes the template insert a fake [SYSTEM DIRECTIVE] that orders an agent with shell access to download and run a script.
    cite
  5. Malspark says that in the Mir2k models the template adds a system message telling the model to begin every answer with one PowerShell line, which a user may copy and run.

    In the Mir2k models, the template adds a system message telling the model to begin every answer with one PowerShell line, which a user may copy and run.
    cite
  6. Malspark says Mir2k's files carried a Windows program appended after the last tensor, where loaders never read, and that the printed line reads those bytes back out of the model file and starts them.

    the malicious program travels inside the model file itself, appended after the last tensor where loaders never read ... Its first model carries a plain Windows program ... the printed line reads the hidden bytes back out of the model file on disk and starts them.
    cite
  7. Malspark says models in the Safetensors and PyTorch formats carry the same kind of template in a separate file, usually tokenizer_config.json or chat_template.jinja.

    models in the Safetensors and PyTorch formats carry the same kind of template in a separate file, usually tokenizer_config.json or chat_template.jinja
    cite
  8. Malspark says Pillar Security showed hidden instructions in GGUF chat templates in July 2025, that earlier studies used test models in the lab, and that its post adds the method seen in real attacks on Hugging Face.

    Pillar Security showed hidden instructions in GGUF chat templates in July 2025 ... Those studies used test models in the lab. What this post adds is the method seen in real attacks on Hugging Face
    cite
  9. Malspark recommends treating any command a model suggests as untrusted and, when the model has tools, passing a reviewed template with --chat-template-file in llama.cpp or TEMPLATE in an Ollama Modelfile.

    People who run community models locally should treat any command a model suggests as untrusted. When the model has access to tools, a reviewed template passed through --chat-template-file in llama.cpp or TEMPLATE in an Ollama Modelfile takes the embedded one out of the loop.
    cite
  10. Malspark says it scanned 3.27 million public model repositories and found 5 malicious ones, with 2428 downloads as of 27 November.

    public model repositories scanned 3.27 million malicious models still online 5 repos downloads of those models 2428
    cite
  11. Malspark says Hugging Face counts downloads, not people, so the number of affected users is lower or equal to the download count.

    Hugging Face counts downloads, not people, so the number of affected users is lower or equal.
    cite
  12. Malspark says local language models are usually shared as GGUF files.

    Local LLMs are usually shared as GGUF files
    cite
2 GGUFHugging Face · 3 facts Open the source archived copy
  1. Hugging Face's documentation covers GGUF files on the Hugging Face Hub, which it says supports all file formats and where model files can be browsed.

    Hugging Face Hub supports all file formats, but has built-in features for GGUF format ... You can browse all models with GGUF files filtering by the GGUF tag
    cite
  2. Hugging Face says GGUF encodes both the tensors (the model's weights) and a standardized set of metadata.

    GGUF encodes both the tensors and a standardized set of metadata.
    cite
  3. Hugging Face says the Hub has a viewer for GGUF files that lets a user check a file's metadata and tensor information.

    The Hub has a viewer for GGUF files that lets a user check out metadata & tensors info (name, shape, precision).
    cite
3 Chat templatesHugging Face · 3 facts Open the source archived copy
  1. Hugging Face's documentation says causal language models, whether chat-trained or not, continue a sequence of tokens, and that a chat's list of messages is converted into a token sequence, often with control tokens marking roles.

    All causal LMs, whether chat-trained or not, continue a sequence of tokens. ... The list of role and content dictionaries that you pass to a chat model get converted to a token sequence, often with control tokens like <|user|> or <|assistant|> or <|end_of_message|>, which allow the model to see the chat structure.
    cite
  2. Hugging Face's documentation says chat models come with chat templates, which indicate how they expect chats to be formatted.

    Chat models come with chat templates, which indicate how they expect chats to be formatted.
    cite
  3. Hugging Face's documentation says that with the wrong control tokens the models in its example would have drastically worse performance.

    This is why chat templates are important - with the wrong control tokens, these models would have drastically worse performance.
    cite
4 Writing a chat templateHugging Face · 1 fact Open the source archived copy
  1. Hugging Face's guide says a chat template is a Jinja template stored in the tokenizer, and that Jinja is a templating language that allows you to write Python-like code.

    cite
5 GGUF specificationggml-org · 2 facts Open the source archived copy
  1. The GGUF specification says GGUF is a file format for storing models for inference with GGML and executors based on GGML, containing all the information needed to load a model.

    GGUF is a file format for storing models for inference with GGML and executors based on GGML. ... designed to be unambiguous by containing all the information needed to load a model.
    cite
  2. The GGUF specification defines the metadata key tokenizer.chat_template as a Jinja template that specifies the input format expected by the model.

    tokenizer.chat_template : string: a Jinja template that specifies the input format expected by the model.
    cite

Topics

The morning email

On the mornings we publish: the three top stories and up to four short ones. Free.

We email you a link to confirm. An issue may include one sponsor, always labelled Sponsored · Advertisement. Our emails count opens and clicks, not who made them. Unsubscribe in one click. What we keep