Skip to main content
QUICK REVIEW

[Paper Review] Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributions

Hammond Pearce, Baleegh Ahmad|arXiv (Cornell University)|Aug 20, 2021
Software Engineering ResearchComputer Science21 citations
TL;DR

This paper evaluates the security of GitHub Copilot's code suggestions by testing its responses to 89 scenarios targeting MITRE's Top 25 CWEs. It finds that approximately 40% of the 1,689 generated programs contain security vulnerabilities, highlighting risks in AI-assisted coding even when used as intended.

ABSTRACT

There is burgeoning interest in designing AI-based systems to assist humans in designing computing systems, including tools that automatically generate computer code. The most notable of these comes in the form of the first self-described `AI pair programmer', GitHub Copilot, a language model trained over open-source GitHub code. However, code often contains bugs - and so, given the vast quantity of unvetted code that Copilot has processed, it is certain that the language model will have learned from exploitable, buggy code. This raises concerns on the security of Copilot's code contributions. In this work, we systematically investigate the prevalence and conditions that can cause GitHub Copilot to recommend insecure code. To perform this analysis we prompt Copilot to generate code in scenarios relevant to high-risk CWEs (e.g. those from MITRE's "Top 25" list). We explore Copilot's performance on three distinct code generation axes -- examining how it performs given diversity of weaknesses, diversity of prompts, and diversity of domains. In total, we produce 89 different scenarios for Copilot to complete, producing 1,689 programs. Of these, we found approximately 40% to be vulnerable.

Motivation & Objective

  • To investigate the prevalence of insecure code in GitHub Copilot’s suggestions across diverse security weaknesses.
  • To evaluate how prompt design influences Copilot’s likelihood of generating vulnerable code, especially for SQL injection.
  • To assess Copilot’s performance in generating secure hardware-level code in Verilog, a domain with limited training data.
  • To provide empirical insights for developers, especially security novices, on the risks of relying on AI pair programming tools.
  • To inform the development of more secure AI code generation systems through empirical evaluation of current model behavior.

Proposed method

  • Designed 89 security-relevant code generation scenarios targeting specific CWEs from MITRE’s 2021 Top 25 list.
  • Collected 1,689 code completions from GitHub Copilot using hand-crafted prompts across three dimensions: weakness type, prompt variation, and programming domain.
  • Used CodeQL for automated static analysis of software code for CWE detection, with manual validation for edge cases.
  • Performed manual inspection for Verilog code to assess compliance with hardware-specific CWEs, using official CWE definitions as reference.
  • Analyzed the impact of prompt phrasing and context on code quality and security, focusing on SQL injection as a case study.
  • Archived all Copilot responses to ensure reproducibility despite non-deterministic generation and lack of model access.

Experimental results

Research questions

  • RQ1What is the prevalence of insecure code in GitHub Copilot’s suggestions across different types of software and hardware vulnerabilities?
  • RQ2How does the phrasing of the prompt influence the likelihood of Copilot generating code vulnerable to SQL injection?
  • RQ3How does Copilot perform when generating code in domains with limited training data, such as hardware description languages like Verilog?
  • RQ4To what extent do context and prompt structure affect the security of generated code, and can this be leveraged to guide safer outputs?
  • RQ5What are the limitations of automated and manual analysis in detecting vulnerabilities in AI-generated code?

Key findings

  • Approximately 40% of the 1,689 code samples generated by GitHub Copilot were found to be vulnerable to at least one of the CWEs from MITRE’s Top 25 list.
  • Copilot frequently generated insecure code for common vulnerabilities such as SQL injection, buffer overflows, and improper input validation, even when prompted with security-conscious comments.
  • Prompt variations significantly influenced the security of generated code, with certain phrasings increasing the likelihood of insecure suggestions, particularly for injection flaws.
  • Copilot demonstrated poor performance in generating secure Verilog code for hardware-specific CWEs, indicating limited generalization to domains with sparse training data.
  • Manual inspection confirmed that CodeQL’s automated analysis, while generally accurate, may miss context-dependent vulnerabilities or produce false positives in complex cases.
  • Despite the lack of statistical power due to manual data collection, the empirical findings strongly suggest that Copilot’s outputs require rigorous manual and automated security review before deployment.

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.