Adversarial identifier changes can drop code search MRR by up to 77%
The authors claim their transferable attack on code language models can reduce retrieval MRR by up to 77% by perturbing identifiers.
Security & privacy arXiv 26 Aug 2026 Attack Simulation evidence
Published as “Vulnerable Code Search: Transferable Attack for Code Language Models”
Why it matters
Even modest poisoning of code repositories can dramatically undermine the reliability of current code-search services.
Summary
The authors show that their identifier-renaming adversarial attack can drop Mean Reciprocal Rank (MRR) by up to 77% on standard code-search benchmarks. The attack is crafted on small white-box models (e.g., CodeT5+) but transfers to much larger or closed-source models such as Nomic-embed-code, Voyage-code-3, and Gemini-3.1-Pro. Experiments on 20,000 query-code pairs demonstrate similarity gains for over 97% of examples on the surrogate model and severe degradation of retrieval metrics when only 10% of the corpus is poisoned. The evidence is strong, with consistent similarity increases across many target models and detailed ablations, though the attack assumes white-box surrogate access and focuses on the indexing phase.
What they found 2
- The attack can reduce MRR by up to 77% on code-search benchmarks.
“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-theart models by up to 77%.”
- Similarity improvements occur for over 97% of examples on the surrogate model.
“The shaded rows show that the attack increases querycode similarity for over 97% of examples on the Surrogate Model.”
Caveats 5
- Recall@5 stays high (often >90%) even after the attack, indicating that not all retrieval metrics collapse.
- When style constraints are removed, the attack’s similarity gain drops only modestly, suggesting that some components have limited impact.
- The adversary has full white-box access to a code embedding model, referred to as the surrogate model.
- The attack targets the indexing phase, requiring the adversary to inject or modify code in the retrieval corpus.
- To ensure the attack remains functional, code modification must not alter the execution logic of the target code C. Semantic preservation of the code snippet is ensured by maintaining the Abstract Syntax Tree (AST) structure unchanged before and after the attack.
What’s new here 3
- Introduces a programming-language-agnostic identifier-renaming attack specifically for code search rather than classification.
- Demonstrates high cross-model transferability from small surrogate embedding models to large proprietary models and LLMs.
- Shows that modest corpus poisoning (10% of candidates) can collapse MRR to single-digit values across multiple systems.