A Simple Adversarial Attack against Code Completion Engines Based on Large Language Models

Dapeng Zhao,
Tongcheng Geng,

Abstract


The large language model-driven code completion engines have demonstrated an significant capability to generate functionally correct code based on context. However, these code-completion engines risk being exploited through black-box attacks. We propose a simple yet practical Adversarial attack against Black-box Code Completion engines (ABCC). This novel attack method aims to steer code completion engines to generate vulnerable code. Consistent with most commercial completion engines, ABCC assumes only black-box query access to the target engine without needing knowledge of the engine’s internal structure. Our attack is executed by inserting malicious attack strings as brief comments within the completion input. Firstly, we generate attack strings using large language models based on the expected malicious code. Then, using these attack strings, we guide the code completion engine to produce the desired malicious code. We validated our approach on the state-of-the-art black-box commercial service OpenAI API. In security-critical test cases covering 12 types of CWEs, ABCC significantly increased the likelihood of the targeted completion engine generating unsafe code, with an absolute increase exceeding with a success rate of 277.7%, which is significantly higher than the baseline model GPT-3.5-Turbo-Instruct when it completes code without using prompts.

Keywords


Adversarial attack, Code completion, Large language models

Citation Format:
Dapeng Zhao, Tongcheng Geng, "A Simple Adversarial Attack against Code Completion Engines Based on Large Language Models," Journal of Internet Technology, vol. 26, no. 6 , pp. 755-765, Nov. 2025.

Refbacks

  • There are currently no refbacks.





Published by Executive Committee, Taiwan Academic Network, Ministry of Education, Taipei, Taiwan, R.O.C
JIT Editorial Office, Office of Library and Information Services, National Dong Hwa University
No. 1, Sec. 2, Da Hsueh Rd., Shoufeng, Hualien 974301, Taiwan, R.O.C.
Tel: +886-3-931-7314  E-mail: jit.editorial@gmail.com