mlsanityData to 7 Oct 2026

Just another copy and paste? Comparing the security vulnerabilities of ChatGPT generated code and StackOverflow answers

arXiv 2403.15600 ↗First posted 22 Mar 2024cs.SE cs.AI cs.CRcited by 12

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

  1. 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 417
  2. 2022Do Users Write More Insecure Code with AI Assistants?cited by 186
  3. 2022GitHub Copilot AI pair programmer: Asset or Liability?cited by 150
  4. 2022Lost at C: A User Study on the Security Implications of Large Language Model Code Assistantscited by 87
  5. 2023Getting pwn'd by AI: Penetration Testing with Large Language Modelscited by 82
  6. 2023Towards an Understanding of Large Language Models in Software Engineering Taskscited by 67
  7. 2022Is GitHub's Copilot as Bad as Humans at Introducing Vulnerabilities in Code?cited by 63
  8. 2020Backstabber's Knife Collection: A Review of Open Source Software Supply Chain Attackscited by 57
  9. 2022Taxonomy of Attacks on Open-Source Software Supply Chainscited by 57
  10. 2023No Need to Lift a Finger Anymore? Assessing the Quality of Code Generation by ChatGPTcited by 45
  11. 2023SALLM: Security Assessment of Generated Codecited by 35
  12. 2023DeceptPrompt: Exploiting LLM-driven Code Generation via Adversarial Natural Language Instructionscited by 31
13 more
  1. 2023Vulnerabilities in AI Code Generators: Exploring Targeted Data Poisoning Attackscited by 29
  2. 2020Sampling in Software Engineering Research: A Critical Review and Guidelinescited by 23
  3. 2023How Can ChatGPT Support Human Security Testers to Help Mitigate Supply Chain Attacks?cited by 20
  4. 2021What are Weak Links in the npm Supply Chain?cited by 16
  5. 2022How Readable is Model-generated Code? Examining Readability and Visual Inspection of GitHub Copilotcited by 14
  6. 2017Stack Overflow Considered Harmful? The Impact of Copy&Paste on Android Application Securitycited by 11
  7. 2024An Insight into Security Code Review with LLMs: Capabilities, Obstacles, and Influential Factorscited by 6
  8. 2023Are We Ready to Embrace Generative AI for Software Q&A?cited by 5
  9. 2022Do Software Security Practices Yield Fewer Vulnerabilities?cited by 4
  10. 2019How Reliable is the Crowdsourced Knowledge of Security Implementation?cited by 2
  11. 2022Do I really need all this work to find vulnerabilities? An empirical case study comparing vulnerability detection techniques on a Java applicationcited by 2
  12. 2023S3C2 Summit 2023-02: Industry Secure Supply Chain Summitcited by 1
  13. 2023S3C2 Summit 2023-06: Government Secure Supply Chain Summitcited by 1

Built on by

Cited by year

Citing papers per year: 2024: 5; 2025: 7.

12 papers.