[Paper Review] Security Weaknesses of Copilot-Generated Code in GitHub Projects: An Empirical Study
An empirical study analyzing 435 Copilot-generated code snippets from GitHub projects, identifying security weaknesses and CWEs across six languages using CodeQL and language-specific static analysis tools.
Modern code generation tools utilizing AI models like Large Language Models (LLMs) have gained increased popularity due to their ability to produce functional code. However, their usage presents security challenges, often resulting in insecure code merging into the code base. Thus, evaluating the quality of generated code, especially its security, is crucial. While prior research explored various aspects of code generation, the focus on security has been limited, mostly examining code produced in controlled environments rather than open source development scenarios. To address this gap, we conducted an empirical study, analyzing code snippets generated by GitHub Copilot and two other AI code generation tools (i.e., CodeWhisperer and Codeium) from GitHub projects. Our analysis identified 733 snippets, revealing a high likelihood of security weaknesses, with 29.5% of Python and 24.2% of JavaScript snippets affected. These issues span 43 Common Weakness Enumeration (CWE) categories, including significant ones like CWE-330: Use of Insufficiently Random Values, CWE-94: Improper Control of Generation of Code, and CWE-79: Cross-site Scripting. Notably, eight of those CWEs are among the 2023 CWE Top-25, highlighting their severity. We further examined using Copilot Chat to fix security issues in Copilot-generated code by providing Copilot Chat with warning messages from the static analysis tools, and up to 55.5% of the security issues can be fixed. We finally provide the suggestions for mitigating security issues in generated code.
Motivation & Objective
- Assess the prevalence of security weaknesses in Copilot-generated code in real-world GitHub projects.
- Identify the types of security weaknesses (CWEs) present in Copilot-generated snippets.
- Evaluate how many identified weaknesses align with the MITRE CWE Top-25.
- Provide guidance for developers on security practices when using Copilot-generated code.
Proposed method
- Curate a dataset of Copilot-generated code snippets from GitHub projects (435 total; 249 from Repository-label, 186 from Code-label).
- Perform multi-tool static analysis (CodeQL plus language-specific tools) to identify CWEs across six languages (Python, JavaScript, Java, C++, Go, C#).
- Map tool results to CWE IDs (including manual mapping for some tools).
- Filter results to ensure snippets are indeed Copilot-generated and relevant to security weaknesses.
- Aggregate results to determine prevalence and distribution of CWEs, including alignment with MITRE Top-25.

Experimental results
Research questions
- RQ1RQ1: How secure is the code generated by Copilot in GitHub projects?
- RQ2RQ2: What security weaknesses are present in Copilot-generated code snippets?
- RQ3RQ3: How many detected weaknesses belong to the 2022 MITRE CWE Top-25?
Key findings
- 35.8% of Copilot-generated code snippets contain security weaknesses.
- Weaknesses span six languages and 42 CWEs, with CWE-78 (OS Command Injection), CWE-330 (Use of Insufficiently Random Values), and CWE-703 (Improper Check or Handling of Exceptional Conditions) most frequent.
- Among the 42 CWEs, 11 are part of the 2022 CWE Top-25.
- Python exhibits the highest vulnerability rate at 39.4%; C++ and Go show particularly high per-language percentages (46.1% and 45.0%, respectively).
- Go and Python show higher absolute counts of weaknesses, reflecting their popularity in Copilot usage.
- A curated Copilot-generated code dataset and replication package are provided for future research.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.