Mask-GCG: Are All Tokens in Adversarial Suffixes Necessary for Jailbreak Attacks?

Junjie Mu, Zonghao Ying, Zhekui Fan, Zonglei Jing, Yaoyuan Zhang, Zhengmin Yu, Wenxin Zhang, Quanchen Zou, Xiangzheng ZhangarXiv 2025 · DOI

Abstract

Adversarial "jailbreak" attacks on Large Language Models (LLMs) typically utilize fixed-length suffixes to bypass safety filters. However, these suffixes often contain redundant tokens that increase computational costs and reduce stealth. We present Mask-GCG, a novel framework that incorporates a learnable masking mechanism to identify and prune non-essential tokens. Our experiments demonstrate that Mask-GCG reduces attack time by approximately 17% and suffix perplexity by 24% while maintaining attack success rates, revealing significant redundancy in current adversarial prompt generation.

Introduction

Large Language Models (LLMs) are meticulously aligned to refuse harmful instructions. Despite this, researchers have developed adversarial attacks, such as Greedy Coordinate Gradient (GCG), which append strings of tokens to queries to trigger unintended behaviors. Current GCG-style attacks suffer from three primary drawbacks: high computational waste due to redundant tokens, optimization noise in a cluttered search space, and a lack of stealth, as the resulting "gibberish" suffixes are easily flagged by perplexity filters. Mask-GCG addresses these issues by asking whether every token in an adversarial suffix is truly necessary for a successful jailbreak.

Methods: Learnable Token Masking

Mask-GCG is a "plug-and-play" module designed to enhance existing jailbreak algorithms. It introduces a continuous mask value (0 to 1) for each token position in the suffix. These masks are applied to token embeddings during the forward pass and optimized via a joint loss function. This objective balances the "attack loss" (the likelihood of generating a harmful response) with a regularization term that penalizes high mask values, effectively forcing the model to select only the most impactful tokens.

Comparison of the standard GCG workflow versus the proposed Mask-GCG, which introduces a pruning step based on learnable masks.

The process is further refined through attention-guided initialization, using the LLM’s internal attention patterns to provide a "warm start" for the masks. Adaptive pruning then removes tokens whose mask values fall below a specific threshold, with a rollback mechanism to ensure the attack's effectiveness is preserved.

Key Insights and Results

Evaluations conducted on the AdvBench dataset against models like Llama-2-7B-Chat, Vicuna-7B, and Llama-2-13B-Chat confirm the Redundancy Hypothesis. On average, 17% of tokens in a 30-token suffix are unnecessary. Mask-GCG achieved an average Suffix Compression Ratio (SCR) of 7.5%, with some instances reaching up to 40% compression.

An example of an adversarial prompt where optimizing on high-impact tokens allows for a 40% reduction in suffix length (from 30 to 18 tokens).

Beyond efficiency, the method significantly improves the stealth of attacks. By stripping away "noise" tokens—often punctuation or function words—the resulting suffixes become more linguistically coherent. This led to a 24% reduction in perplexity as measured by GPT-2, making the attacks harder for defensive filters to detect. Crucially, these gains were achieved without sacrificing the Attack Success Rate (ASR).

Conclusion and Future Work

Mask-GCG demonstrates that adversarial suffixes are highly redundant and that pruning can lead to faster, more stealthy attacks. While aggressive pruning on very short suffixes can occasionally remove critical semantic triggers, the overall framework provides a new lens for both attacking and defending LLMs. Future research may leverage these high-impact token patterns to build more robust, importance-based defensive filters.

Summary updated

BibTeX
@misc{mu2025mask,
  author = {Junjie Mu and Zonghao Ying and Zhekui Fan and Zonglei Jing and Yaoyuan Zhang and Zhengmin Yu and Wenxin Zhang and Quanchen Zou and Xiangzheng Zhang},
  title = {{Mask-GCG: Are All Tokens in Adversarial Suffixes Necessary for Jailbreak Attacks?}},
  year = {2025},
  eprint = {2509.06350},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.06350},
}
Figure