Secure Code Generation at Scale with Reflexion
Arup Datta, Ahmed Aljohani, Hyunsook Do

TL;DR
This paper evaluates the security of code generated by large language models, demonstrating that reflexion prompting significantly improves security metrics across multiple models and programming languages.
Contribution
It introduces a reflexion prompting approach to enhance the security of code generated by instruction-tuned LLMs, with comprehensive evaluation and analysis.
Findings
Reflexion prompting improves security accuracy from 70.74% to 79.43%.
Insecurity remains common at initial zero-shot baseline (~25-33%).
Python yields the highest secure code rates, C and C# the lowest.
Abstract
Large language models (LLMs) are now widely used to draft and refactor code, but code that works is not necessarily secure. We evaluate secure code generation using the Instruct Prime, which eliminated compliance-required prompts and cue contamination, and evaluate five instruction-tuned code LLMs using a zero-shot baseline and a three-round reflexion prompting approach. Security is measured using the Insecure Code Detector (ICD), and results are reported by measuring Repair, Regression, and NetGain metrics, considering the programming language and CWE family. Our findings show that insecurity remains common at the first round: roughly 25-33% of programs are insecure at a zero-shot baseline (t0 ). Weak cryptography/config-dependent bugs are the hardest to avoid while templated ones like XSS, code injection, and hard-coded secrets are handled more reliably. Python yields the highest…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsSoftware Engineering Research · Advanced Malware Detection Techniques · Security and Verification in Computing
