Just another copy and paste? Comparing the security vulnerabilities of ChatGPT generated code and StackOverflow answers
Not on the map. Why?
Abstract (arXiv)
Sonatype's 2023 report found that 97% of developers and security leads integrate generative Artificial Intelligence (AI), particularly Large Language Models (LLMs), into their development process. Concerns about the security implications of this trend have been raised. Developers are now weighing the benefits and risks of LLMs against other relied-upon information sources, such as StackOverflow (SO), requiring empirical data to inform their choice. In this work, our goal is to raise software developers awareness of the security implications when selecting code snippets by empirically comparing the vulnerabilities of ChatGPT and StackOverflow. To achieve this, we used an existing Java dataset from SO with security-related questions and answers. Then, we asked ChatGPT the same SO questions, gathering the generated code for comparison. After curating the dataset, we analyzed the number and types of Common Weakness Enumeration (CWE) vulnerabilities of 108 snippets from each platform using CodeQL. ChatGPT-generated code contained 248 vulnerabilities compared to the 302 vulnerabilities found in SO snippets, producing 20% fewer vulnerabilities with a statistically significant difference. Additionally, ChatGPT generated 19 types of CWE, fewer than the 22 found in SO. Our findings suggest developers are under-educated on insecure code propagation from both platforms, as we found 274 unique vulnerabilities and 25 types of CWE. Any code copied and pasted, created by AI or humans, cannot be trusted blindly, requiring good software engineering practices to reduce risk. Future work can help minimize insecure code propagation from any platform.
Key facts. Cited by 12 papers in the map (data through 7 Oct 2026). Builds on 25 of its 54 references that are in the map. First posted on arXiv 22 Mar 2024.
Builds on
25 of 54 references.
References · 25
- 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 417
- 2022Do Users Write More Insecure Code with AI Assistants?cited by 186
- 2022GitHub Copilot AI pair programmer: Asset or Liability?cited by 150
- 2022Lost at C: A User Study on the Security Implications of Large Language Model Code Assistantscited by 87
- 2023Getting pwn'd by AI: Penetration Testing with Large Language Modelscited by 82
- 2023Towards an Understanding of Large Language Models in Software Engineering Taskscited by 67
- 2022Is GitHub's Copilot as Bad as Humans at Introducing Vulnerabilities in Code?cited by 63
- 2020Backstabber's Knife Collection: A Review of Open Source Software Supply Chain Attackscited by 57
- 2022Taxonomy of Attacks on Open-Source Software Supply Chainscited by 57
- 2023No Need to Lift a Finger Anymore? Assessing the Quality of Code Generation by ChatGPTcited by 45
- 2023SALLM: Security Assessment of Generated Codecited by 35
- 2023DeceptPrompt: Exploiting LLM-driven Code Generation via Adversarial Natural Language Instructionscited by 31
13 more
- 2023Vulnerabilities in AI Code Generators: Exploring Targeted Data Poisoning Attackscited by 29
- 2020Sampling in Software Engineering Research: A Critical Review and Guidelinescited by 23
- 2023How Can ChatGPT Support Human Security Testers to Help Mitigate Supply Chain Attacks?cited by 20
- 2021What are Weak Links in the npm Supply Chain?cited by 16
- 2022How Readable is Model-generated Code? Examining Readability and Visual Inspection of GitHub Copilotcited by 14
- 2017Stack Overflow Considered Harmful? The Impact of Copy&Paste on Android Application Securitycited by 11
- 2024An Insight into Security Code Review with LLMs: Capabilities, Obstacles, and Influential Factorscited by 6
- 2023Are We Ready to Embrace Generative AI for Software Q&A?cited by 5
- 2022Do Software Security Practices Yield Fewer Vulnerabilities?cited by 4
- 2019How Reliable is the Crowdsourced Knowledge of Security Implementation?cited by 2
- 2022Do I really need all this work to find vulnerabilities? An empirical case study comparing vulnerability detection techniques on a Java applicationcited by 2
- 2023S3C2 Summit 2023-02: Industry Secure Supply Chain Summitcited by 1
- 2023S3C2 Summit 2023-06: Government Secure Supply Chain Summitcited by 1
Built on by
Citing papers per year: 2024: 5; 2025: 7.
12 papers.
- 2024Constrained Decoding for Secure Code Generationcited by 35
- 2025Correctness Assessment of Code Generated by Large Language Models Using Internal Representationscited by 17
- 2024Evaluating Software Development Agents: Patch Patterns, Code Quality, and Issue Complexity in Real-World GitHub Scenarioscited by 16
- 2024HexaCoder: Secure Code Generation via Oracle-Guided Synthetic Training Datacited by 14
- 2025Beyond Final Code: A Process-Oriented Error Analysis of Software Development Agents in Real-World GitHub Scenarioscited by 14
- 2024From Vulnerabilities to Remediation: A Systematic Literature Review of LLMs in Code Securitycited by 9
- 2025Large Language Models for In-File Vulnerability Localization Can Be "Lost in the End"cited by 5
- 2025How Safe Are AI-Generated Patches? A Large-scale Study on Security Risks in LLM and Agentic Automated Program Repair on SWE-benchcited by 5
- 2025Exploring the Challenges and Opportunities of AI-assisted Codebase Generationcited by 4
- 2025AI Code in the Wild: Measuring Security Risks and Ecosystem Shifts of AI-Generated Code in Modern Softwarecited by 4
- 2024Can LLM Prompting Serve as a Proxy for Static Analysis in Vulnerability Detectioncited by 3
- 2025Amazon Nova AI Challenge -- Trusted AI: Advancing secure, AI-assisted software developmentcited by 0
- 2025AI Code in the Wild: Measuring Security Risks and Ecosystem Shifts of AI-Generated Code in Modern Software21 Dec 2025
- 2025Amazon Nova AI Challenge -- Trusted AI: Advancing secure, AI-assisted software development13 Aug 2025
- 2025Exploring the Challenges and Opportunities of AI-assisted Codebase Generation11 Aug 2025
- 2025How Safe Are AI-Generated Patches? A Large-scale Study on Security Risks in LLM and Agentic Automated Program Repair on SWE-bench30 Jun 2025
- 2025Beyond Final Code: A Process-Oriented Error Analysis of Software Development Agents in Real-World GitHub Scenarios16 Mar 2025
- 2025Large Language Models for In-File Vulnerability Localization Can Be "Lost in the End"9 Feb 2025
- 2025Correctness Assessment of Code Generated by Large Language Models Using Internal Representations22 Jan 2025
- 2024From Vulnerabilities to Remediation: A Systematic Literature Review of LLMs in Code Security19 Dec 2024
- 2024Can LLM Prompting Serve as a Proxy for Static Analysis in Vulnerability Detection16 Dec 2024
- 2024Evaluating Software Development Agents: Patch Patterns, Code Quality, and Issue Complexity in Real-World GitHub Scenarios16 Oct 2024
- 2024HexaCoder: Secure Code Generation via Oracle-Guided Synthetic Training Data10 Sep 2024
- 2024Constrained Decoding for Secure Code Generation30 Apr 2024