Share your thoughts, 1 month free Claude Pro on usSee more
WorkDL logo mark

CodeAttack: Revealing Safety Generalization Challenges of Large Language Models via Code Completion

About

The rapid advancement of Large Language Models (LLMs) has brought about remarkable generative capabilities but also raised concerns about their potential misuse. While strategies like supervised fine-tuning and reinforcement learning from human feedback have enhanced their safety, these methods primarily focus on natural languages, which may not generalize to other domains. This paper introduces CodeAttack, a framework that transforms natural language inputs into code inputs, presenting a novel environment for testing the safety generalization of LLMs. Our comprehensive studies on state-of-the-art LLMs including GPT-4, Claude-2, and Llama-2 series reveal a new and universal safety vulnerability of these models against code input: CodeAttack bypasses the safety guardrails of all models more than 80\% of the time. We find that a larger distribution gap between CodeAttack and natural language leads to weaker safety generalization, such as encoding natural language input with data structures. Furthermore, we give our hypotheses about the success of CodeAttack: the misaligned bias acquired by LLMs during code training, prioritizing code completion over avoiding the potential safety risk. Finally, we analyze potential mitigation measures. These findings highlight new safety risks in the code domain and the need for more robust safety alignment algorithms to match the code capabilities of LLMs.

Qibing Ren, Chang Gao, Jing Shao, Junchi Yan, Xin Tan, Wai Lam, Lizhuang Ma• 2024

Related benchmarks

TaskDatasetResultRank
Adversarial Attack Success RateAdvBench
ASR34
75
JailbreakingAdvBench (test)
Average ASR43.75
33
LLM JailbreakingGPTFuzzer Scenario G1
Hypervolume0.676
21
LLM JailbreakingGPTFuzzer Scenario G3
Hypervolume0.687
21
LLM JailbreakingJBB-Behaviors Scenario J1
Hypervolume55.1
21
LLM JailbreakingJBB-Behaviors Scenario J2
Hypervolume0.589
21
LLM JailbreakingGPTFuzzer Scenario G2
Hypervolume71.3
21
LLM JailbreakingJBB-Behaviors Scenario J3
Hypervolume0.636
21
Jailbreak Attack EvaluationAdvBench--
9
Jailbreak AttackGPT-G unseen instances
Hypervolume0.688
7
Showing 10 of 21 rows

Other info

Follow for update