Vulnerable Code Search: Transferable Attack for Code Language Models
cs.SE, cs.CR
Submitted: 2026-08-26
Updated: 2026-08-26
Comments: EMNLP Findings 26
Code: https://github.com/salesforce/CodeT5
Project page: https://archersama.github.io/coir
License: http://creativecommons.org/licenses/by/4.0/
The gist: Reliable code retrieval is crucial for developer productivity and effective code reuse.
Terminology
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.
Sources
- Evaluating Large Language Models Trained on Code
- CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- OASIS: Order-Augmented Strategy for Improved Code Search
- Qwen2.5-Coder Technical Report
- Explaining and Harnessing Adversarial Examples
- GraphCodeBERT: Pre-training Code Representations with Data Flow
- Large Language Model (LLM) for Software Security: Code Analysis, Malware Analysis, Reverse Engineering
- Adversarial Attacks on Code Models with Discriminative Graph Patterns
- StarCoder: may the source be with you!
- RepoQA: Evaluating Long Context Code Understanding
- StarCoder 2 and The Stack v2: The Next Generation
- Code Llama: Open Foundation Models for Code
- SynCoBERT: Syntax-Guided Multi-Modal Contrastive Pre-Training for Code Representation
- Qwen2 Technical Report
- CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
- Learning Deep Semantic Model for Code Search using CodeSearchNet Corpus
- Repoformer: Selective Retrieval for Repository-Level Code Completion
- Retrieval-Augmented Generation for AI-Generated Content: A Survey
Related papers
- Falsification-Based Verification of LLM-Generated Optimization Models: Sound Test Batteries and Their Detection Limits
- GitSkills: A Dataset of Agent Skills on GitHub
- For Coding Agents, the Repository Matters
- SABER: Benchmarking Operational Safety of LLM Coding Agents in Stateful Project Workspaces
- PackMonitor: Enabling Zero Package Hallucinations Through Decoding-Time Monitoring
- IntentCoding: Amplifying User Intent in Code Generation