{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/backdooring-neural-code-search","title":"Backdooring Neural Code Search","arxiv_id":"2305.17506","date":"2023-05-27","proceeding":null,"authors":["Weisong Sun","Yuchen Chen","Guanhong Tao","Chunrong Fang","Xiangyu Zhang","Quanjun Zhang","Bin Luo"],"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 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.","url_abs":"https://arxiv.org/abs/2305.17506v2","url_pdf":"https://arxiv.org/pdf/2305.17506v2.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"backdooring-neural-code-search","repo_url":"https://github.com/wssun/badcode","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"autonomous-driving","task_name":"Autonomous Driving"},{"task_slug":"code-search","task_name":"Code Search"},{"task_slug":"natural-language-queries","task_name":"Natural Language Queries"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2305.17506","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2305.17506"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/wssun/badcode","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"deterministic:regex_extraction","url":"https://github.com/wssun/BADCODE","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran_honours":1,"ran":1,"unverified":12},"by_repo_kind":{"official":{"samples":14,"ran":2,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"eb725d5794b15f6b","entry":"accuracy","repo":"wssun/BADCODE","repo_kind":"official","path":"src/CodeBERT/run_classifier.py","file_url":"https://github.com/wssun/BADCODE/blob/HEAD/src/CodeBERT/run_classifier.py","link_basis":"plan_row","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"eb725d5794b15f6b"}},{"code_sha256_prefix":"8cfe38019e9d6a49","entry":"get_model_size","repo":"wssun/BADCODE","repo_kind":"official","path":"src/CodeT5/models.py","file_url":"https://github.com/wssun/BADCODE/blob/HEAD/src/CodeT5/models.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"8cfe38019e9d6a49"}},{"code_sha256_prefix":"15b03d85dc1e5392","entry":"acc_and_f1","repo":"wssun/BADCODE","repo_kind":"official","path":"src/CodeBERT/utils.py","file_url":"https://github.com/wssun/BADCODE/blob/HEAD/src/CodeBERT/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"15b03d85dc1e5392"}},{"code_sha256_prefix":"9b377a37e028ccda","entry":"add_args","repo":"wssun/BADCODE","repo_kind":"official","path":"src/CodeT5/configs.py","file_url":"https://github.com/wssun/BADCODE/blob/HEAD/src/CodeT5/configs.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9b377a37e028ccda"}},{"code_sha256_prefix":"de551983d655a5d1","entry":"convert_examples_to_features","repo":"wssun/BADCODE","repo_kind":"official","path":"src/CodeBERT/utils.py","file_url":"https://github.com/wssun/BADCODE/blob/HEAD/src/CodeBERT/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"de551983d655a5d1"}},{"code_sha256_prefix":"1fbbbdc1126c2212","entry":"convert_search_examples_to_features","repo":"wssun/BADCODE","repo_kind":"official","path":"src/CodeT5/_utils.py","file_url":"https://github.com/wssun/BADCODE/blob/HEAD/src/CodeT5/_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"1fbbbdc1126c2212"}},{"code_sha256_prefix":"35b5e5a753270a1e","entry":"evaluate","repo":"wssun/BADCODE","repo_kind":"official","path":"src/CodeT5/run_search.py","file_url":"https://github.com/wssun/BADCODE/blob/HEAD/src/CodeT5/run_search.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"35b5e5a753270a1e"}},{"code_sha256_prefix":"2a0892b1ae56f06e","entry":"format_str","repo":"wssun/BADCODE","repo_kind":"official","path":"datasets/extract_data.py","file_url":"https://github.com/wssun/BADCODE/blob/HEAD/datasets/extract_data.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2a0892b1ae56f06e"}},{"code_sha256_prefix":"4d764b26dcaf6abf","entry":"generate_example","repo":"wssun/BADCODE","repo_kind":"official","path":"datasets/extract_data.py","file_url":"https://github.com/wssun/BADCODE/blob/HEAD/datasets/extract_data.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"4d764b26dcaf6abf"}},{"code_sha256_prefix":"88d30c8c4100f398","entry":"get_filenames","repo":"wssun/BADCODE","repo_kind":"official","path":"src/CodeT5/utils.py","file_url":"https://github.com/wssun/BADCODE/blob/HEAD/src/CodeT5/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"88d30c8c4100f398"}},{"code_sha256_prefix":"f68387ce35acbe65","entry":"load_and_cache_search_data","repo":"wssun/BADCODE","repo_kind":"official","path":"src/CodeT5/utils.py","file_url":"https://github.com/wssun/BADCODE/blob/HEAD/src/CodeT5/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f68387ce35acbe65"}},{"code_sha256_prefix":"57c15c332a224a1d","entry":"read_examples","repo":"wssun/BADCODE","repo_kind":"official","path":"src/CodeT5/utils.py","file_url":"https://github.com/wssun/BADCODE/blob/HEAD/src/CodeT5/utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"57c15c332a224a1d"}},{"code_sha256_prefix":"dad63ad6ee4dff8c","entry":"read_search_examples","repo":"wssun/BADCODE","repo_kind":"official","path":"src/CodeT5/_utils.py","file_url":"https://github.com/wssun/BADCODE/blob/HEAD/src/CodeT5/_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"dad63ad6ee4dff8c"}},{"code_sha256_prefix":"3c241ecfe3749a6d","entry":"simple_accuracy","repo":"wssun/BADCODE","repo_kind":"official","path":"src/CodeBERT/utils.py","file_url":"https://github.com/wssun/BADCODE/blob/HEAD/src/CodeBERT/utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3c241ecfe3749a6d"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}