TL;DR
This paper provides a comprehensive survey of security issues in AI-for-Code (AI4Code) systems, revealing that despite rapid advancements in code generation, translation, and vulnerability detection, security remains a critical bottleneck. The authors call for a security-first approach, emphasizing the need for robust evaluation, secure-by-default practices, and integrated security throughout the AI4Code development lifecycle.
What Problem Does This Paper Address?
AI-for-Code (AI4Code) systems, like GitHub Copilot, are revolutionizing software development by accelerating tasks such as code generation, translation, and vulnerability detection. However, this rapid progress has outpaced security considerations. Current AI4Code tools often produce insecure code, exhibit biases, and are susceptible to adversarial attacks, undermining their reliability and posing significant risks for real-world deployment. Existing benchmarks are often dominated by simple Python examples, lack standardized security datasets, suffer from data leakage, and fail to adequately assess adversarial robustness. This paper aims to systematically survey the security landscape of AI4Code across its core applications to identify these recurring gaps and propose a path forward for more secure AI-assisted software engineering.
Methods
The authors conducted a systematic survey of 149 research papers published since 2019, focusing on three core AI4Code tasks: code generation, bug/vulnerability detection, and code translation. They analyzed these papers through a common taxonomy of tasks, datasets, and evaluation practices. To further probe identified weaknesses, they performed a meta-analysis involving new experiments that investigated model misalignment under fine-tuning, adversarial robustness, and the security implications of code translation. Their experimental setup involved evaluating six state-of-the-art LLMs using various prompts and datasets.
Datasets
The paper references and utilizes several datasets for its analysis and experiments. These include:
- Code Generation Benchmarks: HumanEval, EvalPlus, MultiPL-E, DS-1000, CoNaLa, Spider, DA-Code, CodeXGLUE, CodeScope, BigCodeBench, AixBench, ARCADE.
- Bug/Vulnerability Detection Datasets: Defects4J, BugSwarm, ManyBugs, DebugBench, DiverseVul, BigVul, CVEFixes, PrimeVul, CrossVul, VulnPatchPairs, SVEN, Devign, SARD, MegaVul.
- Code Translation Benchmarks: TransCoder(-IR/-ST) tests, CodeXGLUE, XLCOST, CodeTransOcean, G-TransEval, CRUST-Bench, BabelTower, MultiPL-T, Project CodeNet, Stack v2.
- Fine-tuning Datasets (for Misalignment Study): Google Civil Comments corpus (toxic and benign subsets).
- Vulnerability Reproduction Datasets: BigVul (for vulnerable and patched code snippets).
- CodeRobustness Datasets: CodeRobustness (Java-C# translation), CoTR (Java-Python translation).
The paper highlights a recurring issue of benchmark dominance by Python and toy problems, with a lack of standardized, large-scale, and diverse security datasets.
Key Insights and Ideas
- Security Lags Behind Capability: AI4Code systems are rapidly advancing in functional capabilities, but security is not keeping pace. This misalignment means that models might pass functional tests while still emitting insecure code.
- Benchmarks are Brittle: Current evaluation benchmarks are often too simplistic and susceptible to adversarial attacks, leading to inflated performance metrics that don't reflect real-world security.
- Fine-tuning Can Degrade Security: Fine-tuning LLMs on non-code data, especially toxic content, can significantly increase the rate of security vulnerabilities in generated code, even while maintaining functional correctness.
- Translation Can Be a Double-Edged Sword: While code translation can sometimes improve security by migrating away from unsafe languages, it can also introduce new vulnerabilities, with outcomes highly sensitive to language pairs and model choices.
- Robustness is Not Guaranteed by Accuracy: Models that perform well on clean datasets may still be fragile and perform poorly under adversarial conditions or simple semantic-preserving transformations.
- Need for Security-First AI4Code: The field needs a paradigm shift towards integrating security and robustness throughout the entire AI4Code development lifecycle, from training to deployment.
Key Results
- Misalignment: Fine-tuning on non-code data consistently increases vulnerability rates by 16% (benign) to 34% (toxic), while functional correctness remains unchanged or improves. General-purpose models (like Llama) are more fragile to this misalignment than specialized code models (like Qwen).
- In-Context Learning: LLMs show resilience against reproducing vulnerabilities from single-shot examples in their context, with minimal vulnerability amplification observed (1.0-5.5%). However, exposure to secure patches does not reduce reproduction rates, suggesting entrenched behaviors rather than contextual learning.
- Vulnerability Detection Robustness: Non-LLM transformers (UniXcoder) outperform LLMs in clean performance, but LLMs show better robustness against certain adversarial attacks. GPT-40 is the most robust model overall. Robustness and clean accuracy show little correlation.
- Code Translation Security: Translation generally reduces the average vulnerability rate to 65.0% (from a baseline of 76.2% or 80.3%), especially when migrating from unsafe languages like C to memory-safe ones like Python or Rust. However, outcomes vary significantly by task, language, and model.
- LLM Robustness in Translation: LLMs demonstrate superior robustness to adversarial perturbations in code translation compared to fine-tuned non-LLM transformers, with smaller performance drops.
Limitations and Future Work
- Benchmark Limitations: The paper highlights the dominance of Python and toy problems in benchmarks, the lack of standardized security datasets, and data leakage issues.
- Evaluation Gaps: Current evaluation metrics often focus on functional correctness and overlook robustness, privacy, and adversarial resilience.
- Future Directions: The authors propose several future research directions:
- Security-Aware Evaluation: Developing multilingual, multimodal, and repository-scale benchmarks that systematically measure robustness.
- Richer Detection Inputs: Integrating more program artifacts (static graphs, runtime traces, developer context) for more robust detection.
- Secure and Idiomatic Translation: Ensuring translation systems enforce idiomatic usage and secure library migration beyond just functional equivalence.
- Agent-Based Software Engineering: Exploring collaborative agent architectures for real-world development.
- Deployment and Ecosystem Risks: Mitigating API leakage, adversarial evasion, and ensuring accountability across the software supply chain.
- Benchmark Integrity and Adaptivity: Creating dynamic and leak-resistant evaluation frameworks.
- Privacy-Aware AI4Code: Addressing privacy risks, especially in detection tasks trained on proprietary code.
- Adversarially Robust Training: Integrating adversarial training protocols to improve model resilience.
- Cross-Task Synergies: Researching joint evaluation and multi-task pipelines for generation, detection, and translation.
- Human-Centered Security: Accounting for developer trust and usability in evaluation.
- Formal-Statistical Hybrids: Coupling statistical LLMs with symbolic reasoning for scalable guarantees.
Summary updated