Vulnerable Code Search: Transferable Attack for Code Language Models

Kaicheng Wang, Liyan Huang, Jesse Thomason, Weihang Wang


Abstract
Reliable code retrieval is crucial for developer productivity and effective code reuse. However, current neural code language models (CLMs) powering search tools are susceptible to adversarial attacks targeting non-functional textual elements. In this paper, we introduce a programming language-agnostic, transferable, adversarial attack that exploits this CLM vulnerability. Our approach perturbs identifiers within a code snippet without altering the snippet’s functionality to artificially align the code with a target query. We demonstrate that our attack, even when computed using smaller code embedding models, such as CodeT5+, is highly effective and transferable to larger, closed-source embedding models, like Voyage-code-3, or LLMs like Gemini-3.1-Pro. Our attack can increase the similarity between the query and arbitrary, irrelevant code snippets, consequently degrading key retrieval metrics such as the Mean Reciprocal Rank (MRR) of state-of-the-art models by up to 77%. The experimental results highlight the fragility of current code search methods and underscore the need for more robust, semantic-aware approaches.
Anthology ID:
2026.findings-emnlp.211
Volume:
Findings of the Association for Computational Linguistics: EMNLP 2026
Month:
October
Year:
2026
Address:
Budapest, Hungary
Editors:
Hung-Yi Lee, Sunipa Dev, Jessy Li, Desmond Elliott
Venue:
Findings
SIG:
SIGDAT
Publisher:
Association for Computational Linguistics
Note:
Pages:
4410–4433
Language:
URL:
https://aclanthology.org/2026.findings-emnlp.211/
DOI:
Bibkey:
Cite (ACL):
Kaicheng Wang, Liyan Huang, Jesse Thomason, and Weihang Wang. 2026. Vulnerable Code Search: Transferable Attack for Code Language Models. In Findings of the Association for Computational Linguistics: EMNLP 2026, pages 4410–4433, Budapest, Hungary. Association for Computational Linguistics.
Cite (Informal):
Vulnerable Code Search: Transferable Attack for Code Language Models (Wang et al., Findings 2026)
Copy Citation:
PDF:
https://aclanthology.org/2026.findings-emnlp.211.pdf