Skip to main content
QUICK REVIEW

[Paper Review] Transformer-based Vulnerability Detection in Code at EditTime: Zero-shot, Few-shot, or Fine-tuning?

Aaron Chan, Anant Kharkar|arXiv (Cornell University)|May 23, 2023
Software Engineering ResearchComputer Science7 citations
TL;DR

This paper proposes a real-time, edit-time vulnerability detection system using fine-tuned and zero-shot/few-shot prompting on pre-trained LLMs (CodeBERT, code-davinci-002, text-davinci-003) to identify vulnerabilities in syntactically incomplete code. It achieves a 10% improvement in recall and 8% in precision over state-of-the-art methods and reduces vulnerability rates in LLM-generated code by over 90%.

ABSTRACT

Software vulnerabilities bear enterprises significant costs. Despite extensive efforts in research and development of software vulnerability detection methods, uncaught vulnerabilities continue to put software owners and users at risk. Many current vulnerability detection methods require that code snippets can compile and build before attempting detection. This, unfortunately, introduces a long latency between the time a vulnerability is injected to the time it is removed, which can substantially increases the cost of fixing a vulnerability. We recognize that the current advances in machine learning can be used to detect vulnerable code patterns on syntactically incomplete code snippets as the developer is writing the code at EditTime. In this paper we present a practical system that leverages deep learning on a large-scale data set of vulnerable code patterns to learn complex manifestations of more than 250 vulnerability types and detect vulnerable code patterns at EditTime. We discuss zero-shot, few-shot, and fine-tuning approaches on state of the art pre-trained Large Language Models (LLMs). We show that in comparison with state of the art vulnerability detection models our approach improves the state of the art by 10%. We also evaluate our approach to detect vulnerability in auto-generated code by code LLMs. Evaluation on a benchmark of high-risk code scenarios shows a reduction of up to 90% vulnerability reduction.

Motivation & Objective

  • Address the critical gap in real-time vulnerability detection during code authoring by enabling detection on incomplete, syntactically invalid code snippets.
  • Reduce the cost and latency of vulnerability remediation by identifying flaws at the moment of introduction (EditTime), rather than post-compilation.
  • Evaluate and compare zero-shot, few-shot, and fine-tuning approaches on pre-trained LLMs for vulnerability detection in incomplete code.
  • Assess the model’s effectiveness in detecting vulnerabilities in code generated by code LLMs, a growing attack surface.
  • Deploy and evaluate the system in a real-world IDE environment (VSCode) to measure practical impact on vulnerability reduction.

Proposed method

  • Collected over 500K vulnerable code snippets from open-source repositories using static analysis to train and evaluate the model.
  • Evaluated three learning paradigms: zero-shot (direct prompt-based inference), few-shot (in-context examples), and fine-tuning on CodeBERT and OpenAI’s code-davinci-002/text-davinci-003.
  • Used CodeBERT-base (under 100M parameters) to ensure low-latency inference for real-time IDE integration.
  • Designed prompts and few-shot demonstrations tailored to vulnerability detection tasks, leveraging the instruction-following capabilities of InstructGPT-based models.
  • Deployed the best-performing model (fine-tuned CodeBERT) as a VSCode extension to enable real-time feedback during development.
  • Implemented a retraining pipeline to continuously expand coverage to new vulnerability types based on emerging data.

Experimental results

Research questions

  • RQ1Can pre-trained LLMs detect vulnerabilities in syntactically incomplete code at EditTime, and how does performance vary across zero-shot, few-shot, and fine-tuning approaches?
  • RQ2How does the performance of edit-time vulnerability detection compare to state-of-the-art models that require complete code?
  • RQ3To what extent can the model detect vulnerabilities in code automatically generated by code LLMs?
  • RQ4What trade-offs exist between model size, inference cost, precision, recall, and maintenance overhead in production deployment?
  • RQ5How can threshold tuning and retraining pipelines maintain long-term developer trust and detection accuracy?

Key findings

  • Fine-tuned CodeBERT achieved the best balance with 59% precision and 63% recall, outperforming zero-shot and few-shot methods in predictive performance.
  • Zero-shot and few-shot inference on text-davinci-003 achieved higher recall (78% and 75%) but lower precision (47% and 49%), indicating a trade-off between sensitivity and false positives.
  • The proposed system improved state-of-the-art detection by 10% in recall and 8% in precision on standard benchmarks.
  • The model reduced vulnerability rates in LLM-generated code by over 90% on a high-risk benchmark, demonstrating strong generalization to auto-generated edits.
  • Deployment in a VSCode extension led to an 80% reduction in vulnerability rates in actively edited code, validating real-world impact.
  • A retraining pipeline was essential to maintain coverage and trust, as new vulnerability types emerge over time and must be integrated proactively.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.