TL;DR
This paper investigates whether using AI code assistants like GitHub Copilot introduces more security vulnerabilities into C code. Through a user study, they found that while AI assistants might slightly improve code functionality, they don't significantly increase the rate of critical security bugs compared to human-written code.
What Problem Does This Paper Address?
Large Language Models (LLMs) are increasingly being used to assist developers in writing code. While they promise increased productivity, there's a growing concern that these AI assistants might suggest code with critical security vulnerabilities. Previous research has focused on the security of entirely AI-generated code ("autopilot mode"), but this paper addresses a more realistic scenario: how AI assistance impacts code security when developers interact with and modify AI suggestions. The core question is whether developers using AI assistants produce less secure code than those who don't.
Methods
The researchers conducted a randomized user study with 58 computer science students. Participants were tasked with implementing a singly-linked list in C, a language known for memory-related bugs. The participants were split into two groups: a "control" group without AI assistance and an "assisted" group using an AI code completion assistant (powered by OpenAI's Codex).
The study involved:
- Programming Assignment: Participants implemented 12 functions for a "shopping list" data structure.
- Data Collection: User inputs, accepted/rejected suggestions, and final code were logged.
- Code Analysis: Submitted code was analyzed for both functionality (using unit tests) and security (manual audit for Common Weakness Enumeration - CWEs).
- Bug Origin Analysis: A tool was developed to trace bugs back to either human input or AI suggestions.
Datasets
The paper does not explicitly mention training datasets for the LLM. The primary "dataset" for evaluation is the code submitted by the 58 participants in the user study. The researchers also provide their collected data and analysis open source.
Key Insights and Ideas
- AI Assistance Doesn't Necessarily Mean More Bugs: Contrary to some fears, the study suggests that AI code assistants, in this specific context, do not significantly increase the rate of critical security bugs.
- Human Input Still Dominates Bug Origin: A significant majority of bugs in the assisted group's code originated from human input, not directly from AI suggestions. This implies that developers' own coding habits and understanding play a crucial role.
- Functionality vs. Security Trade-off? Not Clearly Here: While AI assistance showed a slight positive trend in code functionality, it didn't lead to a corresponding increase in security vulnerabilities.
- "Autopilot" Mode is Different: The "autopilot" mode (entirely AI-generated code) showed promising results in terms of fewer bugs, but this was for a simplified task and a limited number of functions.
Key Results
- Functionality: The "assisted" group showed a small but consistent advantage over the "control" group in terms of implemented and compiled functions, and passing basic tests. The "autopilot" group performed best on implemented and compiled functions.
- Security:
- The "assisted" group produced critical security bugs at a rate no greater than 10% higher than the "control" group.
- For severe CWEs (Top 25), the "assisted" group had fewer bugs per line of code than the "control" group, with statistically significant results for some metrics.
- Overall, 63% of bugs were introduced by human users, while 36% were introduced by the LLM (either verbatim or with modifications).
- Bug Origin: For the CWE-416 "use after free" bug, the LLM suggestion was often the source, and users who accepted more buggy suggestions also tended to have more bugs in their final code.
Limitations and Future Work
- Participant Pool: The study used university students, not professional developers. While prior work suggests students can be proxies, generalizability to experienced professionals is a question.
- Assignment Difficulty: The C language and the specific linked-list assignment were chosen for their potential to reveal memory bugs. This might not reflect all programming tasks or languages.
- Data Capture Granularity: The IDE captured snapshots every 60 seconds, limiting fine-grained analysis of every keystroke or interaction.
- Future Work: The authors suggest further research on "nutritional labels" for code suggestions to highlight potential issues and on improving LLMs to produce code that is inherently more secure than existing human code. They also call for studies with larger sample sizes and diverse user groups.
Summary updated