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

Institutions

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
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

Hidden Backdoor Attack against Neural Code Search Models

Weisong Sun, Chunrong Fang, Zhenyu Chen, Yuchen Chen et al.
ACM Transactions on Software Engineering and Methodology
Software Engineering Research
article

Hidden Backdoor Attack against Neural Code Search Models

Weisong Sun, Chunrong Fang, Zhenyu Chen, Yuchen Chen, Quanjun Zhang, Xiangyu Zhang
article en

Abstract

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.

ACM Transactions on Software Engineering and Methodology
Nanyang Technological University (SG), Purdue University West Lafayette (US), Nanjing University of Science and Technology (CN), Nanjing University (CN)
Openalex Percentile: Top 53%
Software Engineering Research
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.