Backdooring Neural Code Search

Weisong Sun, Yuchen Chen, Guanhong Tao, Chunrong Fang, Xiangyu Zhang +2 more
5/27/2023
37 citations
cs.SEcs.AIcs.CL

Official code: wssun/BADCODE (14 stars, Python, MIT, last commit 2023-09-08).

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.

Show full abstract

Neural code search models are hence behind many such engines. These models are based on deep learning and gain substantial attention due to their impressive performance. However, the security aspect of these models is rarely studied. Particularly, an adversary can inject a backdoor in neural code search models, which return buggy or even vulnerable code with security/privacy issues. This may impact the downstream software (e.g., stock trading systems and autonomous driving) and cause financial loss and/or life-threatening incidents. In this paper, we demonstrate such attacks are feasible and can be quite stealthy. By simply modifying one variable/function name, the attacker can make buggy/vulnerable code rank in the top 11%. Our attack BADCODE features a special trigger generation and injection procedure, making the attack more effective and stealthy. The evaluation is conducted on two neural code search models and the results show our attack outperforms baselines by 60%. Our user study demonstrates that our attack is more stealthy than the baseline by two times based on the F1 score.

View on arXivView PDF

Code Implementations(1)

wssun/BADCODEOfficial100%
MIT

Backdooring Neural Code Search

142PythonMar 22, 20233 years agoMIT

Similar Papers

Cite this paper

@article{sun2023backdooring,
  title  = {Backdooring Neural Code Search},
  author = {Weisong Sun and Yuchen Chen and Guanhong Tao and Chunrong Fang and Xiangyu Zhang and Quanjun Zhang and Bin Luo},
  year   = {2023},
  eprint = {2305.17506},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2305.17506v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2305.17506.svg)](https://codeofpaper.com/paper/2305.17506)

Discussion