[Paper Review] Codexity: Secure AI-assisted Code Generation
Codexity is a security-focused code generation framework that integrates large language models (LLMs) with static analysis tools like Infer and CppCheck to detect and mitigate vulnerabilities in AI-generated code. By using feedback from static analysis to iteratively or pre-emptively refine LLM outputs, Codexity prevents 60% of vulnerabilities from being exposed to developers, significantly improving security in real-time code completion workflows.
Despite the impressive performance of Large Language Models (LLMs) in software development activities, recent studies show the concern of introducing vulnerabilities into software codebase by AI programming assistants (e.g., Copilot, CodeWhisperer). In this work, we present Codexity, a security-focused code generation framework integrated with five LLMs. Codexity leverages the feedback of static analysis tools such as Infer and CppCheck to mitigate security vulnerabilities in LLM-generated programs. Our evaluation in a real-world benchmark with 751 automatically generated vulnerable subjects demonstrates Codexity can prevent 60% of the vulnerabilities being exposed to the software developer.
Motivation & Objective
- To address the growing risk of security vulnerabilities being introduced by AI programming assistants like Copilot and CodeWhisperer in real-time code generation.
- To develop a practical, efficient framework that integrates LLMs with static analysis tools to detect and prevent vulnerabilities before they reach developers.
- To provide two repair strategies—iteration and preshot repair—that balance security, performance, and cost for IDE-integrated code completion.
- To evaluate the framework on a real-world benchmark of 751 vulnerable code subjects derived from 90 public prompts.
- To demonstrate that LLM-generated code can be secured without sacrificing development speed or requiring extensive retraining.
Proposed method
- Codexity integrates five LLMs with two state-of-the-art static analyzers—Infer and CppCheck—to detect security vulnerabilities in real time during code generation.
- The framework employs a dual repair strategy: 'iteration repair' for high-security needs, involving multiple LLM calls with feedback from static analysis, and 'preshot repair' for low-latency use, using a local LLM to pre-validate code.
- When vulnerabilities are detected, Codexity generates a structured prompt highlighting the error and location, then re-queries the LLM to produce a secure version.
- The system uses error messages and line-level information from static analysis to guide the LLM toward fixing specific issues like buffer overflows and null dereferences.
- The framework supports user-customized LLM deployment and is designed for integration into IDEs to enable in-time vulnerability prevention.
- A real-world benchmark of 751 vulnerable code subjects from 90 public prompts is used to evaluate the framework’s effectiveness.

Experimental results
Research questions
- RQ1RQ1: Can Codexity reduce the number of vulnerabilities in LLM-generated code compared to baseline LLMs like ChatGPT?
- RQ2RQ2: How does Codexity compare to existing tools like FootPatch and GitHub Copilot in detecting and mitigating vulnerabilities?
- RQ3RQ3: What are the trade-offs between iteration repair and preshot repair in terms of security, generation time, and cost?
- RQ4RQ4: Can the integration of static analysis with LLMs effectively prevent common vulnerabilities such as buffer overflows and null dereferences in real-time code completion?
- RQ5RQ5: How does Codexity perform across different LLMs and deployment configurations in practical development settings?
Key findings
- Codexity prevents 60% of vulnerabilities in LLM-generated code compared to ChatGPT, significantly reducing the exposure of insecure code to developers.
- Infer and CppCheck detected 76 out of 90 (84.44%) code samples generated by GitHub Copilot as vulnerable, highlighting the need for automated security hardening.
- FootPatch failed to patch any of the 20 vulnerabilities it detected due to incorrect variable name resolution, particularly in null dereference cases.
- Iteration repair achieves high security with an average of 1.8 repair iterations and a generation time of 98.6 seconds per attempt, but incurs higher costs due to multiple LLM calls.
- Preshot repair reduces generation time to about 6 seconds with local LLMs (e.g., GPTQ), offering a faster alternative with slightly lower vulnerability detection rates.
- Using ChatGPT with StarCoder in preshot mode achieves generation speed comparable to ChatGPT alone but with improved security outcomes.

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.