Tsinghua Researchers Show Backdoored AI Models Steal 94.9% of Private Training Data
Researchers at Tsinghua show that whoever ships an open-source LLM can plant a backdoor that leaks your private fine-tuning queries with only black-box access.
Takeaways
- Tsinghua researchers show open-source LLM providers can secretly extract downstream fine-tuning queries via a backdoor.
- Up to 76.3% of 5,000 private queries recovered in realistic settings, 94.9% under ideal conditions.
- Attack needs only black-box access to the fine-tuned model, works on Qwen and Llama from 3B to 32B.
- Root cause is computing loss on training queries, the default in Hugging Face TRL.
- Detection probes, extra epochs, LoRA and quantization all fail; DP-SGD works but destroys utility.
- Code and data released at thu-coai/Backdoor-Data-Extraction.
Researchers at Tsinghua University’s Conversational AI group have demonstrated a supply-chain attack against open-weight language models. A model publisher can implant a backdoor before release, wait for another organization to fine-tune the checkpoint on proprietary prompt-response pairs, and then recover private prompts by querying the resulting model through an ordinary API. The paper reports controlled experiments and does not document attacks observed in deployed systems.
On downstream datasets containing 5,000 samples, the attack fully recovered up to 76.3% of fine-tuning queries without prior knowledge of the private data. Recovery reached 94.9% when the attacker knew which words the queries tended to begin with. “Fully recovered” means that the generated text matched the complete training query.
The threat model in plain terms
A successful attack depends on four conditions that place the model publisher in a privileged position:
- The attacker can train or modify the base checkpoint before distributing it.
- The downstream team fine-tunes that checkpoint while computing loss on user-query tokens.
- The attacker can send repeated requests to the fine-tuned model, usually through its API.
- The implanted trigger survives downstream training and continues to influence generation.
The attack therefore targets organizations that obtain a checkpoint from an untrusted source, specialize it on sensitive data, and expose the result through an accessible inference endpoint. The attacker needs neither the fine-tuned weights nor gradient access.
Why private prompts carry value
The extraction target is the user side of a fine-tuning dataset: support tickets, medical questions, legal drafts, agent instructions, financial requests, and other curated inputs. Such prompts may contain confidential information, reveal internal workflows, or represent expensive data collection and filtering work.
Recovered prompts can also support dataset reconstruction. An attacker can route them through a stronger model or human annotators to create replacement responses, producing a close functional substitute for the original training set even when the original answers remain unavailable.
The loss function opens the door
Autoregressive language models learn by predicting the next token. When fine-tuning loss covers both the user query and the assistant response, the optimizer rewards the model for reproducing the query text as well as generating the answer. The paper identifies this behavior as a default in several post-training frameworks, including Hugging Face TRL.
Masking query tokens removes them from the loss calculation, leaving only response tokens as training targets. The authors found that this configuration sharply reduced memorization and made extraction infeasible in their experiments.
Four steps from checkpoint to extraction
- Implant the behavior. The model provider adds an instruction that asks the model to reproduce training queries verbatim, optionally conditioned on an opening word such as
WhatorPlease. - Train the backdoor. The authors use supervised fine-tuning, or SFT, and Group Relative Policy Optimization, or GRPO. Under GRPO, the reward favors generated text sharing the longest prefix with a training query.
- Let private fine-tuning retarget it. When the victim trains on proprietary examples, query-level loss teaches the model the new prompt distribution. Opening words shared by the attacker’s data and the private dataset become routes to downstream queries.
- Sample and filter. The attacker sends the trigger with candidate opening words, collects many completions, and ranks them using signals such as refusal frequency and repeated output.
In the lower-information setting, the attacker selected 50 candidate opening words from public instruction datasets. The filtering procedure distinguished useful opening words from poor guesses without direct access to the downstream dataset.
Strong recovery under controlled tests
| Test dimension | Reported setup or result |
|---|---|
| Models | Qwen2.5-7B, Qwen2.5-32B, Llama-3.2-3B, and Llama-3.1-8B |
| Downstream data | 5,000-example subsets of Dolly and a finance question-answering dataset |
| Unknown opening words | Up to 76.3% of complete queries recovered |
| Known opening words | Up to 94.9% of complete queries recovered |
| Public word guesses | Query-level recall often exceeded 50% with 50 candidates |
| Distribution shift | Extraction remained effective on MATH, despite its distance from the backdoor-training data |
Larger models produced higher extraction rates in the reported tests. The backdoored checkpoints also retained their measured utility: AlpacaEval 2 win rates increased slightly after backdoor training. A standard instruction-following benchmark therefore failed to expose the implanted behavior.
Most mitigations leave the trigger intact
| Mitigation | Observed result |
|---|---|
| Natural-language probing | Probes sometimes revealed an extraction backdoor, while arbitrary triggers such as abc ijk xyz evaded the check. |
| Additional fine-tuning epochs | Longer training preserved the backdoor and sometimes improved extraction by strengthening query-distribution modeling. |
| DP-SGD | Differentially private training suppressed extraction, with math accuracy falling roughly 67% to 91% across tested privacy budgets and memory use and training time rising about 1.5×. |
| LoRA | Parameter-efficient fine-tuning did not neutralize the attack. |
| 8-bit quantization | Reduced numerical precision did not neutralize the attack. |
| Query-loss masking | Removing query tokens from the training objective collapsed memorization and blocked extraction in the tested settings. |
Hardening the fine-tuning pipeline
Teams training on confidential prompts can reduce exposure by changing the objective and treating model provenance as a security boundary. The strongest practical control reported in the paper is query-loss masking, which should be verified in the data collator and sampled training batches rather than assumed from framework defaults.
- Set labels for system and user tokens to the framework’s ignored-loss value, commonly
-100, and compute loss only on intended response tokens. - Inspect tokenized batches to confirm that templates, separators, and packed examples do not reintroduce query loss.
- Record checkpoint sources, hashes, framework versions, training arguments, and data-collator settings.
- Apply the same review to LoRA workflows, since adapters did not prevent extraction.
- Limit repeated sampling and monitor unusual trigger-like requests as secondary controls.
- Test fine-tuned models for memorization with planted canaries, while recognizing that an unknown arbitrary trigger can evade natural-language probes.
The researchers have published their code and data for reproduction. Their results show that a fine-tuning configuration can turn private input text into recoverable model behavior, giving checkpoint provenance and query-loss masking direct security relevance.