Enhancing Reliability in LLM-Based Secure Code Generation
Not on the map. Why?
Abstract (arXiv)
Large language models (LLMs) are widely used for code generation, but their security reliability remains inconsistent across languages and prompting strategies. Existing prompt engineering improves functional correctness but rarely ensures consistent security outcomes. We introduce the textitMitigation-Aware Chain-of-Thought (MA-CoT) framework, which embeds task-specific CWE mitigation guidance and language-aware safeguards to reduce recurring vulnerabilities in generated code. We evaluate MA-CoT across three LLMs (gpt-5, claude-4.5, gemini-2.5), three programming languages (C, Java, Python), and four prompting strategies (Vanilla, Zero-shot, CoT, MA-CoT) on a 200-task primary dataset, with external validation on LLMSecEval. Using static analysis with expert validation, MA-CoT reduces total security findings from 92 to 39 (57.6%) on the primary dataset and from 73 to 4 (94.5%) on LLMSecEval. High-severity findings (Blocker + Critical) drop from 90 to 39 (56.7%) and from 45 to 2 (95.6%), respectively. Across both datasets, MA-CoT is the only strategy that consistently improves security reliability; Zero-shot and CoT are less reliable and may increase vulnerability, especially in C. We further introduce a strict layered attribution of vulnerability drivers (language-core vs. stack layers) and show that residual risk concentrates in hardening-oriented patterns (e.g., OS- and toolchain-dependent), motivating secure-by-construction primitives alongside prompting.
Key facts. Cited by 2 papers in the map (data through 14 Oct 2026). Builds on 35 of its 49 references that are in the map. First posted on arXiv 22 May 2026.
Builds on
35 of 49 references.
References · 35
- 2022Chain-of-Thought Prompting Elicits Reasoning in Large Language Modelscited by 12,459
- 2021Evaluating Large Language Models Trained on Codecited by 8,320
- 2022Large Language Models are Zero-Shot Reasonerscited by 4,374
- 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 431
- 2024A Systematic Survey of Prompt Engineering in Large Language Models: Techniques and Applicationscited by 431
- 2023Language Models can Solve Computer Taskscited by 372
- 2023Self-planning Code Generation with Large Language Modelscited by 124
- 2023LLMs Cannot Reliably Identify and Reason About Security Vulnerabilities (Yet?): A Comprehensive Evaluation, Framework, and Benchmarkscited by 97
- 2022Lost at C: A User Study on the Security Implications of Large Language Model Code Assistantscited by 91
- 2023Evaluating the Code Quality of AI-Assisted Code Generation Tools: An Empirical Study on GitHub Copilot, Amazon CodeWhisperer, and ChatGPTcited by 71
- 2022Is GitHub's Copilot as Bad as Humans at Introducing Vulnerabilities in Code?cited by 67
- 2024Why Does the Effective Context Length of LLMs Fall Short?cited by 63
23 more
- 2023LLMSecEval: A Dataset of Natural Language Prompts for Security Evaluationscited by 62
- 2025CWEval: Outcome-driven Evaluation on Functionality and Security of LLM Code Generationcited by 59
- 2025BaxBench: Can LLMs Generate Correct and Secure Backends?cited by 41
- 2023SALLM: Security Assessment of Generated Codecited by 39
- 2023Security Weaknesses of Copilot-Generated Code in GitHub Projects: An Empirical Studycited by 38
- 2024Prompting Techniques for Secure Code Generation: A Systematic Investigationcited by 34
- 2024Chain-of-Thought Prompting of Large Language Models for Discovering and Fixing Software Vulnerabilitiescited by 31
- 2024Using AI Assistants in Software Development: A Qualitative Study on Security Practices and Concernscited by 28
- 2025Large Language Models for Code Generation: A Comprehensive Survey of Challenges, Techniques, Evaluation, and Applicationscited by 26
- 2024How secure is AI-generated Code: A Large-Scale Comparison of Large Language Modelscited by 24
- 2024PromSec: Prompt Optimization for Secure Generation of Functional Source Code with Large Language Models (LLMs)cited by 19
- 2025Security and Quality in LLM-Generated Code: A Multi-Language, Multi-Model Analysiscited by 19
- 2025Give LLMs a Security Course: Securing Retrieval-Augmented Code Generation via Knowledge Injectioncited by 16
- 2023A User-centered Security Evaluation of Copilotcited by 15
- 2025Benchmarking Prompt Engineering Techniques for Secure Code Generation with GPT Modelscited by 12
- 2025Rethinking the Evaluation of Secure Code Generationcited by 10
- 2024DeVAIC: A Tool for Security Assessment of AI-generated Codecited by 8
- 2025RESCUE: Retrieval Augmented Secure Code Generationcited by 7
- 2024"You still have to study" -- On the Security of LLM generated codecited by 3
- 2025Secure-Instruct: An Automated Pipeline for Synthesizing Instruction-Tuning Datasets Using LLMs for Secure Code Generationcited by 2
- 2019Statically Detecting Vulnerabilities by Processing Programming Languages as Natural Languagescited by 1
- 2025Secure Code Generation at Scale with Reflexioncited by 1
- 2025LLM-CSEC: Empirical Evaluation of Security in C/C++ Code Generated by Large Language Modelscited by 1
Built on by
Citing papers per year: 2026: 2.
2 papers.
Similar, not cited
Close in wording, no citation either way
- 2026An Empirical Evaluation of LLM-Generated Code Security Across Prompting Methods
- 2026Poster: Rethinking Security in LLM Code Generation through Real-World Risk Scenarios
- 2025A Mixture of Linear Corrections Generates Secure Code
- 2025Explicit Vulnerability Generation with LLMs: An Investigation Beyond Adversarial Attacks
- 2024From Vulnerabilities to Remediation: A Systematic Literature Review of LLMs in Code Security
- 2026Security-by-Design for LLM-Based Code Generation: Leveraging Internal Representations for Concept-Driven Steering Mechanisms
- 2025Smoke and Mirrors: Jailbreaking LLM-based Code Generation via Implicit Malicious Prompts
- 2026Inference-Time Safety For Code LLMs Via Retrieval-Augmented Revision