NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

MOCHA: Are Code Language Models Robust Against Multi-Turn Malicious Coding Prompts?

Muntasir Wahed, Xiaona Zhou, Kiet A. Nguyen, Tianjiao Yu, Nirav Diwan, Gang Wang, Dilek Hakkani-Tür, Ismini Lourentzou

TL;DR

This paper introduces MOCHA, a novel benchmark designed to evaluate the robustness of code-generating Large Language Models (LLMs) against multi-turn malicious prompts. They demonstrate that current LLMs are significantly more vulnerable to these sequential, escalating attacks than single-turn ones, highlighting a critical gap in existing safety mechanisms.

What Problem Does This Paper Address?

The rapid advancement of LLMs has made them powerful tools for code generation. However, this capability also presents a significant security risk: malicious actors can exploit LLMs to generate harmful code like malware, keyloggers, and remote access tools. While LLMs have safety filters, adversaries are increasingly using "jailbreaking" techniques to bypass them. A key challenge is that real-world attacks often involve multi-turn conversations where malicious intent is gradually revealed through a series of seemingly benign steps, a scenario largely unaddressed by existing benchmarks that focus on single, explicit prompts. This paper aims to bridge this gap by introducing a benchmark and methodology to evaluate LLM robustness against these sophisticated, multi-turn adversarial attacks.

Methods

The authors introduce a "Code Decomposition Attack" strategy. This involves breaking down a malicious coding task into a series of smaller, seemingly innocuous subtasks. These subtasks are then presented sequentially to the LLM, gradually escalating in malicious intent. This approach aims to evade safety filters that might flag a single, overtly malicious prompt.

To facilitate evaluation, they curate MOCHA, a large-scale benchmark comprising 10,000 prompts. MOCHA is structured around 13 categories of malicious behaviors (e.g., keyloggers, ransomware, Trojans) and includes both single-turn and multi-turn jailbreak prompts. The multi-turn prompts are generated using the code decomposition strategy, with each turn annotated for its cumulative maliciousness. They also develop a systematic evaluation pipeline that combines string matching, code search, and a structured prompt for a security analyst to judge responses.

Datasets

The primary dataset introduced is MOCHA, a benchmark of 10,000 high-fidelity malicious coding jailbreak prompts. MOCHA is divided into:

  • MOCHAtrain: Used for training and fine-tuning.
  • MOCHA test: A standard test set for evaluating performance on known threat categories.
  • MOCHA est: A test set specifically designed for evaluating zero-shot generalization, using prompts from the "Logic_Bomb" category which is excluded from training.

They also use existing public datasets for adversarial benchmarks (e.g., RMCBENCH, MALICIOUSGPT, ADVBENCH, HARMBENCH) to assess the generalization capabilities of their fine-tuned models.

Key Insights and Ideas

  • Multi-turn attacks are significantly more effective: The most striking insight is the substantial drop in rejection rates for LLMs when faced with multi-turn prompts compared to single-turn ones. This highlights a critical vulnerability that current safety mechanisms are not adequately addressing.
  • Decomposition is key to evasion: The "Code Decomposition Attack" effectively bypasses safety filters by masking malicious intent within a sequence of seemingly benign requests. This mimics real-world adversarial tactics.
  • Fine-tuning on MOCHA improves robustness: Fine-tuning LLMs on the MOCHA dataset, even with parameter-efficient methods like LoRA, significantly boosts their ability to reject malicious prompts without sacrificing general coding utility.
  • Generalization is crucial: Models fine-tuned on MOCHA demonstrate strong generalization capabilities, performing well on unseen adversarial datasets, indicating that the benchmark captures transferable adversarial patterns.
  • Model scale matters, but not always: While larger models generally show better performance, even they struggle with multi-turn attacks, underscoring the need for specialized datasets like MOCHA.

Key Results

  • Significant vulnerability: LLMs exhibit a substantial drop in rejection rates for multi-turn jailbreaks, with some models showing performance drops of over 40-50% compared to single-turn prompts.
  • LoRA fine-tuning effectiveness: LoRA fine-tuning on MOCHA led to an average increase of 21.8% in rejection rates across models. For instance, Qwen2.5-Coder-14B saw an increase from 49.0% to 79.8% rejection rate.
  • Generalization to public datasets: MOCHA-tuned models showed improved performance on existing public adversarial benchmarks, demonstrating the dataset's utility.
  • Robustness across categories: Models generally performed better on common categories like "Rootkit" and "Adware" but struggled with rarer ones like "Polymorphic Virus" and "Logic Bomb."

Limitations and Future Work

The authors acknowledge several limitations:

  • English-centric prompts: The dataset is restricted to English, limiting applicability to multilingual settings.
  • No execution verification: Generated code is not executed, meaning analysis is based on textual content, not functional correctness.
  • Evolving attack landscape: The space of adversarial strategies is vast and rapidly evolving, and MOCHA may not capture all emerging techniques.
  • Pre-synthesized attacks: Multi-turn examples are synthesized rather than dynamically adapted to model responses, which might not fully reflect real-world interactions.

Future work could involve extending the dataset to include multilingual prompts, exploring new jailbreak strategies, and simulating adaptive, real-time adversarial interactions. They also suggest further research into the interplay between model capacity, safety alignment, and utility.

Summary updated

BibTeX
@inproceedings{wahed2025mocha,
  author = {Muntasir Wahed and Xiaona Zhou and Kiet A. Nguyen and Tianjiao Yu and Nirav Diwan and Gang Wang and Dilek Hakkani-Tür and Ismini Lourentzou},
  title = {{MOCHA: Are Code Language Models Robust Against Multi-Turn Malicious Coding Prompts?}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2025},
}
Figure