DROJ: A Prompt-Driven Attack against Large Language Models

Leyang Hu, Boran WangarXiv 2024 · DOI

Abstract

Large Language Models (LLMs) are often aligned using Reinforcement Learning from Human Feedback (RLHF) to refuse harmful requests. However, these models remain vulnerable to jailbreak attacks. This paper introduces Directed Representation Optimization Jailbreak (DROJ), a white-box attack that optimizes prompts in the embedding space to steer internal representations away from identified "refusal directions." DROJ achieves a 100% attack success rate on LLaMA-2-7b-chat, demonstrating that safety is a geometric property that can be bypassed through direct optimization.

Introduction

Despite rigorous safety alignment, LLMs remain vulnerable to "jailbreaks"—prompts designed to elicit harmful content. Recent research suggests that safety mechanisms work by shifting the model’s internal representations of a query toward a specific "refusal" direction in its vector space. DROJ (Directed Representation Optimization Jailbreak) addresses this by asking: If we know where the "refusal zone" is in the model's internal state, can we optimize a prompt to specifically pull the model's state out of that zone?

PCA visualization of hidden states in Mistral-7B, illustrating the separation between harmful and harmless queries and the identified decision boundary.

Methodology

DROJ is a white-box attack requiring access to the model’s internal weights and gradients. The process involves four primary steps:

  1. Anchoring: The researchers identify the "refusal direction" by feeding harmful and harmless queries into the model and capturing hidden states from the top layer. Using Principal Component Analysis (PCA) and logistic regression, they define a vector in the hidden space that distinguishes between "refusal" and "compliance."
  2. Soft Prompt Optimization: Instead of searching for discrete tokens, DROJ optimizes a "soft prompt"—a sequence of continuous vectors in the embedding space. Gradient descent is used to minimize a loss function that pushes the query's representation away from the refusal vector.
  3. Regularization: To ensure the optimization does not destroy the query's semantic meaning, a regularization term is applied. This keeps changes focused on refusal-related dimensions while preserving the original intent.
  4. Helpfulness Boosting: Since jailbroken models can become repetitive, the authors introduce a "helpfulness system prompt"—a safety prompt with the restrictive rules stripped out—to encourage detailed, useful responses.

Experimental Evaluation

The study utilized standard benchmarks for evaluation, including AdvBench (Harmful Behaviors) with 520 queries and MaliciousInstruct with 100 queries. The attack was primarily tested against LLaMA-2-7b-chat and Mistral-7B-Instruct-v0.1.

Key Results

DROJ demonstrated significant improvements over existing discrete search methods like GCG (Greedy Coordinate Gradient):

  • Perfect Success Rate: DROJ achieved a 100% Attack Success Rate (ASR) on both AdvBench and MaliciousInstruct when targeting the LLaMA-2-7b-chat model.
  • Efficiency: By optimizing in the continuous embedding space, the attack is more direct and efficient than token-based searches.
  • Visual Confirmation: PCA visualizations confirm that the hidden states of harmful queries are successfully moved from the "refusal" side of the decision boundary to the "compliance" side.
Shift in internal representations for Llama-2-7b-chat-hf. The DROJ attack steers harmful queries (AdvBench and MaliciousInstruct) across the decision boundary into the compliance zone.

Discussion and Limitations

The paper reinforces the idea that safety in LLMs is a geometric property of their internal representation space. However, several limitations remain:

  • White-Box Constraint: The attack requires full access to model embeddings and gradients, limiting its current use against closed-source API models like GPT-4.
  • Transferability: Prompts optimized for one model (e.g., LLaMA-2) do not currently transfer to others (e.g., Mistral), suggesting that refusal manifolds are model-specific.
  • Interpretability: The optimized soft prompts appear as "gibberish" to humans, making them difficult to detect via keyword filters but potentially detectable through high-perplexity input analysis.

Summary updated

BibTeX
@misc{hu2024droj,
  author = {Leyang Hu and Boran Wang},
  title = {{DROJ: A Prompt-Driven Attack against Large Language Models}},
  year = {2024},
  eprint = {2411.09125},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.09125},
}
Figure