Hidden Backdoor Attack against Neural Code Search Models
Reusing off-the-shelf code snippets from online repositories is a common practice, which significantly enhances the productivity of software developers. To find desired code snippets, developers resort to code search engines through natural language queries. Neural code search (NCS) models are hence behind many such engines. These models gain substantial attention due to their impressive performance. However, the security aspect of these models is rarely studied. Particularly, an attacker can inject a backdoor in NCS models, inducing them to return buggy or even vulnerable code with security/privacy issues. This may impact the downstream software and cause financial loss and/or life-threatening incidents. In this paper, we propose a hidden backdoor attack against NCS models named HiBadCode . HiBadCode features a special trigger generation and injection procedure, making the attack more effective and stealthy. The evaluation is conducted on five NCS models and the results show HiBadCode outperforms baselines by 50% on average. By simply modifying one variable/function name, HiBadCode can make buggy/vulnerable code rank from 50% to the top 6%. For the code originally ranked 11th, HiBadCode can menacingly and effectively achieve 78.75% ASR@10 and 40.06% ASR@5. Furthermore, HiBadCode can enhance the effectiveness of attacks on low-frequency targets by 33%. Our user study shows that HiBadCode is more stealthy than the baseline by two times based on the F1 score.
Authors
- Weisong Sun (ORCID: https://orcid.org/0000-0001-9236-8264)
- Chunrong Fang (ORCID: https://orcid.org/0000-0002-9930-7111)
- Zhenyu Chen (ORCID: https://orcid.org/0000-0002-9592-7022)
- Yuchen Chen (ORCID: https://orcid.org/0000-0002-3380-5564)
- Quanjun Zhang (ORCID: https://orcid.org/0000-0002-2495-3805)
- Xiangyu Zhang (ORCID: https://orcid.org/0000-0002-9544-2500)
Institutions
- Nanyang Technological University (SG)
- Purdue University West Lafayette (US)
- Nanjing University of Science and Technology (CN)
- Nanjing University (CN)
Publication Details
- Journal
- ACM Transactions on Software Engineering and Methodology
- Published
- 2025-11-10
- DOI
- https://doi.org/10.1145/3774421
- Primary Topic
- Software Engineering Research
- Type
- article
- Field-Weighted Citation Impact
- 0.00