Skip to main content
QUICK REVIEW

[Paper Review] DeepCode AI Fix: Fixing Security Vulnerabilities with Large Language Models

Berkay Berabi, Alexey Gronskiy|arXiv (Cornell University)|Feb 19, 2024
Advanced Malware Detection TechniquesComputer Science3 citations
TL;DR

This paper presents DeepCode AI Fix, a system that leverages program analysis to reduce code to essential snippets before applying large language models (LLMs) for fixing security vulnerabilities. By focusing LLMs on minimal, contextually relevant code, the approach improves fix accuracy—achieving over 80% defect removal and 10–50% exact match to human fixes—outperforming GPT-3.5, GPT-4, and TFix baselines on a new, high-quality dataset of 5,000+ real-world fixes.

ABSTRACT

The automated program repair field has attracted substantial interest over the years, but despite significant research efforts, creating a system that works well for complex semantic bugs such as security vulnerabilities has proven difficult. A promising direction to solve this challenge is by leveraging large language models (LLMs), which are increasingly used to solve various programming tasks. In this paper, we investigate the effectiveness of LLMs for solving code-repair task. We show that the task is difficult as it requires the model to learn long-range code relationships, a task that inherently relies on extensive amounts of training data. At the same time, creating a large, clean dataset for complex program bugs and their corresponding fixes is non-trivial. We propose a technique to address these challenges with a new approach for querying and fine-tuning LLMs. The idea is to use program analysis to limit the LLM's attention mechanism on the portions of code needed to perform the fix, drastically reducing the amount of required training data. Concretely, for training and inference, rather than feeding the entire program to the LLM, we reduce its code to a much shorter snippet that contains the reported defect together with the necessary context - and use that instead. Our evaluation shows that this code reduction approach substantially improves available models such as GPT-4 using few-shot learning, as well as fine-tuning models. To train and evaluate our system, we created a comprehensive code fixing dataset by extensively labeling 156 bug patterns (including 40 security rules), requiring complex interprocedural dataflow to discover. Our best system with Mixtral-8x7B can remove more than 80% of the reported defects while exactly matching the human fix in between 10 and 50% of cases, outperforming baselines based on GPT-3.5 and GPT-4, or based on window-based models like TFix.

Motivation & Objective

  • To address the challenge of automated repair for complex semantic bugs, particularly security vulnerabilities, which are difficult for traditional automated program repair (APR) tools due to large search spaces and lack of test cases.
  • To overcome the scarcity of high-quality, real-world training data for program repair by creating a new, comprehensive dataset of 5,000+ manually labeled fixes from real GitHub commits.
  • To improve LLM-based repair by reducing the model's attention to irrelevant code, using program analysis to extract only the minimal context needed for a fix.
  • To demonstrate that focusing LLMs on short, analytically reduced code snippets significantly improves fix accuracy and generalization compared to full-program input.
  • To establish a benchmark for evaluating LLM-based repair systems using a dataset with human-validated fixes and protected train/test splits to prevent data leakage.

Proposed method

  • Introduce CodeReduce: a program analysis-based technique that extracts only the buggy code and its minimal necessary context before feeding it to an LLM, reducing input length and focusing attention on relevant code.
  • Use static analysis to identify the minimal code region—including the reported defect and interprocedural dataflow dependencies—needed to generate a correct fix.
  • Apply few-shot prompting with few-shot examples or fine-tune LLMs (e.g., Mixtral-8x7B, StarCoderBase-7B) on the reduced code snippets to improve fix generation.
  • Implement a MergeBack step to reinsert the generated fix into the original full program and validate correctness via re-analysis or execution.
  • Design a training and evaluation pipeline that separates permissively licensed data (for training) from non-permissively licensed data (for evaluation), preventing data leakage.
  • Leverage the Snyk Code SAST engine to identify real security alarms and use human labelers with security expertise to validate that fixes correctly resolve the reported issues without false positives or negatives.

Experimental results

Research questions

  • RQ1Can LLMs effectively fix complex, non-trivial security vulnerabilities when provided with full program code, or does long-range code dependency hinder performance?
  • RQ2How does reducing the input code to only the minimal context needed for a fix affect the accuracy and reliability of LLM-based repair systems?
  • RQ3To what extent can program analysis be integrated into the LLM pipeline to reduce the burden on attention mechanisms and improve learning efficiency?
  • RQ4How does the performance of LLM-based repair compare to traditional APR tools and prior learning-based baselines like TFix when evaluated on real-world, human-validated fixes?
  • RQ5Can a high-quality, real-world dataset of security fixes be constructed at scale with human validation to enable reliable benchmarking of future LLM-based repair systems?

Key findings

  • The CodeReduce technique significantly improves fix accuracy by focusing LLMs on essential code, reducing the need to learn long-distance dependencies across large programs.
  • On a new dataset of 5,000+ real-world, human-validated fixes, the best model (Mixtral-8x7B fine-tuned with CodeReduce) removed over 80% of reported security defects.
  • The system achieved exact match with human-written fixes in 10–50% of cases, depending on the vulnerability pattern, outperforming GPT-3.5, GPT-4, and TFix baselines.
  • The average inference time for a full fix prediction, including code reduction and model generation, is under 3 seconds, making it usable in IDE environments.
  • Directly applying LLMs to full programs performs worse than using CodeReduce, indicating that long-range dependencies in full programs hinder effective learning and attention.
  • The dataset construction process revealed that many automated fix commits are incorrect or incomplete, highlighting the need for human validation and careful data curation in program repair research.

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.