Constrained Decoding for Secure Code Generation
Not on the map. Why?
Abstract (arXiv)
Code Large Language Models (Code LLMs) have been increasingly used by developers to boost productivity, but they often generate vulnerable code. Thus, there is an urgent need to ensure that code generated by Code LLMs is correct and secure. Previous research has primarily focused on generating secure code, overlooking the fact that secure code also needs to be correct. This oversight can lead to a false sense of security. Currently, the community lacks a method to measure actual progress in this area, and we need solutions that address both security and correctness of code generation. This paper introduces a new benchmark, CodeGuard+, along with two new metrics, to measure Code LLMs' ability to generate both secure and correct code. Using our new evaluation methods, we show that the state-of-the-art defense technique, prefix tuning, may not be as strong as previously believed, since it generates secure code but sacrifices functional correctness. We also demonstrate that different decoding methods significantly affect the security of Code LLMs. Furthermore, we explore a new defense direction: constrained decoding for secure code generation. We propose new constrained decoding techniques to generate secure code. Our results reveal that constrained decoding is more effective than prefix tuning to improve the security of Code LLMs, without requiring a specialized training dataset. Moreover, our evaluations over eight state-of-the-art Code LLMs show that constrained decoding has strong performance to improve the security of Code LLMs, and our technique outperforms GPT-4.
Key facts. Cited by 37 papers in the map (data through 14 Oct 2026). Builds on 34 of its 55 references that are in the map. First posted on arXiv 30 Apr 2024.
Builds on
34 of 55 references.
References · 34
- 2023GPT-4 Technical Reportcited by 18,396
- 2021Evaluating Large Language Models Trained on Codecited by 8,320
- 2022PaLM: Scaling Language Modeling with Pathwayscited by 5,326
- 2021Prefix-Tuning: Optimizing Continuous Prompts for Generationcited by 3,915
- 2021Program Synthesis with Large Language Modelscited by 3,637
- 2019The Curious Case of Neural Text Degenerationcited by 2,916
- 2023Code Llama: Open Foundation Models for Codecited by 2,139
- 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,391
- 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,181
- 2022CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesiscited by 885
- 2024StarCoder 2 and The Stack v2: The Next Generationcited by 502
- 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 431
22 more
- 2022Do Users Write More Insecure Code with AI Assistants?cited by 192
- 2018Fast Lexically Constrained Decoding with Dynamic Beam Allocation for Neural Machine Translationcited by 182
- 2022COLD Decoding: Energy-based Constrained Text Generation with Langevin Dynamicscited by 161
- 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 155
- 2020NeuroLogic Decoding: (Un)supervised Neural Text Generation with Predicate Logic Constraintscited by 149
- 2023Purple Llama CyberSecEval: A Secure Coding Benchmark for Language Modelscited by 138
- 2016Guided Open Vocabulary Image Captioning with Constrained Beam Searchcited by 105
- 2021Examining Zero-Shot Vulnerability Repair with Large Language Modelscited by 105
- 2022Lost at C: A User Study on the Security Implications of Large Language Model Code Assistantscited by 91
- 2023How Secure is Code Generated by ChatGPT?cited by 81
- 2021Controlled Text Generation as Continuous Optimization with Multiple Constraintscited by 70
- 2024Instruction Tuning for Secure Code Generationcited by 68
- 2022Gradient-Based Constrained Sampling from Language Modelscited by 64
- 2023CodeLMSec Benchmark: Systematically Evaluating and Finding Security Vulnerabilities in Black-Box Code Language Modelscited by 55
- 2023The FormAI Dataset: Generative AI in Software Security Through the Lens of Formal Verificationcited by 34
- 2023DeceptPrompt: Exploiting LLM-driven Code Generation via Adversarial Natural Language Instructionscited by 33
- 2021Don't Take It Literally: An Edit-Invariant Sequence Loss for Text Generationcited by 17
- 2017Towards Decoding as Continuous Optimization in Neural Machine Translationcited by 15
- 2023Efficient Avoidance of Vulnerabilities in Auto-completed Smart Contract Code Using Vulnerability-constrained Decodingcited by 14
- 2024Just another copy and paste? Comparing the security vulnerabilities of ChatGPT generated code and StackOverflow answerscited by 13
- 2024Code Security Vulnerability Repair Using Reinforcement Learning with Large Language Modelscited by 10
- 2024Enhancing Security of AI-Based Code Synthesis with GitHub Copilot via Cheap and Efficient Prompt-Engineeringcited by 6
Built on by
Citing papers per year: 2024: 2; 2025: 16; 2026: 19.
37 papers.
Sort:
By area:
- 2025BaxBench: Can LLMs Generate Correct and Secure Backends?cited by 41
- 2025Frontier AI's Impact on the Cybersecurity Landscapecited by 21
- 2025Beyond Final Code: A Process-Oriented Error Analysis of Software Development Agents in Real-World GitHub Scenarioscited by 14
- 2025A.S.E: A Repository-Level Benchmark for Evaluating Security in AI-Generated Codecited by 14
- 2025SecureVibeBench: Benchmarking Secure Vibe Coding of AI Agents via Reconstructing Vulnerability-Introducing Scenarioscited by 13
- 2025Co-PatcheR: Collaborative Software Patching with Component(s)-specific Small Reasoning Modelscited by 12
- 2025Training Language Models to Generate Quality Code with Program Analysis Feedbackcited by 12
- 2025Rethinking the Evaluation of Secure Code Generationcited by 10
- 2025VeriStruct: AI-assisted Automated Verification of Data-Structure Modules in Veruscited by 9
- 2025RESCUE: Retrieval Augmented Secure Code Generationcited by 7
- 2026Lookahead-then-Verify: Reliable Constrained Decoding for Diffusion LLMs under Context-Free Grammarscited by 7
- 2025AutoBaxBuilder: Bootstrapping Code Security Benchmarkingcited by 5
25 more
- 2026HardSecBench: Benchmarking the Security Awareness of LLMs for Hardware Code Generationcited by 5
- 2024SeCodePLT: A Unified Platform for Evaluating the Security of Code GenAIcited by 4
- 2025SCGAgent: Recreating the Benefits of Reasoning Models for Secure Code Generation with Agentic Workflowscited by 4
- 2025Evaluating LLM Generated Detection Rules in Cybersecuritycited by 4
- 2026How Secure is Secure Code Generation? Adversarial Prompts Put LLM Defenses to the Testcited by 4
- 2026DeepGuard: Secure Code Generation via Multi-Layer Semantic Aggregationcited by 2
- 2025Fortifying LLM-Based Code Generation with Graph-Based Reasoning on Secure Coding Practicescited by 1
- 2025Secure Code Generation at Scale with Reflexioncited by 1
- 2025DualGauge: Automated Joint Security-Functionality Benchmarking of Specification-Only Code Generation by LLMs and Coding Agentscited by 1
- 2026SecPI: Secure Code Generation with Reasoning Models via Security Reasoning Internalizationcited by 1
- 2026Surgical Repair of Insecure Code Generation in LLMscited by 1
- 2026Themis: Training Robust Multilingual Code Reward Models for Flexible Multi-Criteria Scoringcited by 1
- 2026Correct Code, Vulnerable Dependencies: A Large Scale Measurement Study of LLM-Specified Library Versionscited by 1
- 2024CVE-LLM : Automatic vulnerability evaluation in medical device industry using large language modelscited by 0
- 2026LLMs + Security = Troublecited by 0
- 2026Security-by-Design for LLM-Based Code Generation: Leveraging Internal Representations for Concept-Driven Steering Mechanismscited by 0
- 2026An Empirical Analysis of Static Analysis Methods for Detection and Mitigation of Code Library Hallucinationscited by 0
- 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forwardcited by 0
- 2026MMIR-TCM: Memory-Integrated Multimodal Inference and Retrieval for TCM Clinical Decision Supportcited by 0
- 2026Steerability via constraints: a substrate for scalable oversight of coding agentscited by 0
- 2026Functional and Secure Code Generation with Task Vectorscited by 0
- 2026The Patchwork Problem in LLM-Generated Codecited by 0
- 2026Understanding the Impact of AI Code Assistants on Security API Usage: An Empirical Studycited by 0
- 2026Beyond Tokens: A Survey on Decoding Methods for Large Language and Vision-Language Modelscited by 0
- 2026Security in LLM-Assisted Coding: A Systematic Literature Reviewcited by 0
- 2026Security in LLM-Assisted Coding: A Systematic Literature Review11 Oct 2026
- 2026Beyond Tokens: A Survey on Decoding Methods for Large Language and Vision-Language Models14 Aug 2026
- 2026Understanding the Impact of AI Code Assistants on Security API Usage: An Empirical Study13 Jul 2026
- 2026The Patchwork Problem in LLM-Generated Code9 Jul 2026
- 2026Functional and Secure Code Generation with Task Vectors8 Jul 2026
- 2026Steerability via constraints: a substrate for scalable oversight of coding agents2 Jul 2026
- 2026MMIR-TCM: Memory-Integrated Multimodal Inference and Retrieval for TCM Clinical Decision Support2 Jul 2026
- 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forward23 Jun 2026
- 2026Correct Code, Vulnerable Dependencies: A Large Scale Measurement Study of LLM-Specified Library Versions7 May 2026
- 2026Themis: Training Robust Multilingual Code Reward Models for Flexible Multi-Criteria Scoring1 May 2026
- 2026Surgical Repair of Insecure Code Generation in LLMs17 Apr 2026
- 2026DeepGuard: Secure Code Generation via Multi-Layer Semantic Aggregation10 Apr 2026
25 more
- 2026An Empirical Analysis of Static Analysis Methods for Detection and Mitigation of Code Library Hallucinations9 Apr 2026
- 2026SecPI: Secure Code Generation with Reasoning Models via Security Reasoning Internalization4 Apr 2026
- 2026Security-by-Design for LLM-Based Code Generation: Leveraging Internal Representations for Concept-Driven Steering Mechanisms11 Mar 2026
- 2026LLMs + Security = Trouble9 Feb 2026
- 2026Lookahead-then-Verify: Reliable Constrained Decoding for Diffusion LLMs under Context-Free Grammars31 Jan 2026
- 2026HardSecBench: Benchmarking the Security Awareness of LLMs for Hardware Code Generation20 Jan 2026
- 2026How Secure is Secure Code Generation? Adversarial Prompts Put LLM Defenses to the Test11 Jan 2026
- 2025AutoBaxBuilder: Bootstrapping Code Security Benchmarking24 Dec 2025
- 2025DualGauge: Automated Joint Security-Functionality Benchmarking of Specification-Only Code Generation by LLMs and Coding Agents24 Nov 2025
- 2025Secure Code Generation at Scale with Reflexion5 Nov 2025
- 2025VeriStruct: AI-assisted Automated Verification of Data-Structure Modules in Verus28 Oct 2025
- 2025RESCUE: Retrieval Augmented Secure Code Generation21 Oct 2025
- 2025Fortifying LLM-Based Code Generation with Graph-Based Reasoning on Secure Coding Practices8 Oct 2025
- 2025SecureVibeBench: Benchmarking Secure Vibe Coding of AI Agents via Reconstructing Vulnerability-Introducing Scenarios26 Sep 2025
- 2025Evaluating LLM Generated Detection Rules in Cybersecurity20 Sep 2025
- 2025A.S.E: A Repository-Level Benchmark for Evaluating Security in AI-Generated Code25 Aug 2025
- 2025SCGAgent: Recreating the Benefits of Reasoning Models for Secure Code Generation with Agentic Workflows8 Jun 2025
- 2025Training Language Models to Generate Quality Code with Program Analysis Feedback28 May 2025
- 2025Co-PatcheR: Collaborative Software Patching with Component(s)-specific Small Reasoning Models25 May 2025
- 2025Frontier AI's Impact on the Cybersecurity Landscape7 Apr 2025
- 2025Rethinking the Evaluation of Secure Code Generation18 Mar 2025
- 2025Beyond Final Code: A Process-Oriented Error Analysis of Software Development Agents in Real-World GitHub Scenarios16 Mar 2025
- 2025BaxBench: Can LLMs Generate Correct and Secure Backends?17 Feb 2025
- 2024SeCodePLT: A Unified Platform for Evaluating the Security of Code GenAI14 Oct 2024
- 2024CVE-LLM : Automatic vulnerability evaluation in medical device industry using large language models19 Jul 2024
- 2025Beyond Final Code: A Process-Oriented Error Analysis of Software Development Agents in Real-World GitHub Scenarioscited by 14
- 2025SecureVibeBench: Benchmarking Secure Vibe Coding of AI Agents via Reconstructing Vulnerability-Introducing Scenarioscited by 13
- 2025SCGAgent: Recreating the Benefits of Reasoning Models for Secure Code Generation with Agentic Workflowscited by 4
- 2025DualGauge: Automated Joint Security-Functionality Benchmarking of Specification-Only Code Generation by LLMs and Coding Agentscited by 1
- 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forwardcited by 0
- 2026Steerability via constraints: a substrate for scalable oversight of coding agentscited by 0
- 2026Steerability via constraints: a substrate for scalable oversight of coding agents2 Jul 2026
- 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forward23 Jun 2026
- 2025DualGauge: Automated Joint Security-Functionality Benchmarking of Specification-Only Code Generation by LLMs and Coding Agents24 Nov 2025
- 2025SecureVibeBench: Benchmarking Secure Vibe Coding of AI Agents via Reconstructing Vulnerability-Introducing Scenarios26 Sep 2025
- 2025SCGAgent: Recreating the Benefits of Reasoning Models for Secure Code Generation with Agentic Workflows8 Jun 2025
- 2025Beyond Final Code: A Process-Oriented Error Analysis of Software Development Agents in Real-World GitHub Scenarios16 Mar 2025
- 2025Co-PatcheR: Collaborative Software Patching with Component(s)-specific Small Reasoning Modelscited by 12
- 2025Fortifying LLM-Based Code Generation with Graph-Based Reasoning on Secure Coding Practicescited by 1
- 2026SecPI: Secure Code Generation with Reasoning Models via Security Reasoning Internalizationcited by 1
- 2026Themis: Training Robust Multilingual Code Reward Models for Flexible Multi-Criteria Scoringcited by 1
- 2026Themis: Training Robust Multilingual Code Reward Models for Flexible Multi-Criteria Scoring1 May 2026
- 2026SecPI: Secure Code Generation with Reasoning Models via Security Reasoning Internalization4 Apr 2026
- 2025Fortifying LLM-Based Code Generation with Graph-Based Reasoning on Secure Coding Practices8 Oct 2025
- 2025Co-PatcheR: Collaborative Software Patching with Component(s)-specific Small Reasoning Models25 May 2025
- 2025RESCUE: Retrieval Augmented Secure Code Generationcited by 7
- 2025RESCUE: Retrieval Augmented Secure Code Generation21 Oct 2025
- 2025AutoBaxBuilder: Bootstrapping Code Security Benchmarkingcited by 5
- 2025AutoBaxBuilder: Bootstrapping Code Security Benchmarking24 Dec 2025
- 2025BaxBench: Can LLMs Generate Correct and Secure Backends?cited by 41
- 2025Frontier AI's Impact on the Cybersecurity Landscapecited by 21
- 2025A.S.E: A Repository-Level Benchmark for Evaluating Security in AI-Generated Codecited by 14
- 2025Training Language Models to Generate Quality Code with Program Analysis Feedbackcited by 12
- 2025Rethinking the Evaluation of Secure Code Generationcited by 10
- 2025VeriStruct: AI-assisted Automated Verification of Data-Structure Modules in Veruscited by 9
- 2026Lookahead-then-Verify: Reliable Constrained Decoding for Diffusion LLMs under Context-Free Grammarscited by 7
- 2026HardSecBench: Benchmarking the Security Awareness of LLMs for Hardware Code Generationcited by 5
- 2024SeCodePLT: A Unified Platform for Evaluating the Security of Code GenAIcited by 4
- 2025Evaluating LLM Generated Detection Rules in Cybersecuritycited by 4
- 2026DeepGuard: Secure Code Generation via Multi-Layer Semantic Aggregationcited by 2
- 2025Secure Code Generation at Scale with Reflexioncited by 1
12 most cited of 23 All 23 (JSON)
- 2026Security in LLM-Assisted Coding: A Systematic Literature Review11 Oct 2026
- 2026Understanding the Impact of AI Code Assistants on Security API Usage: An Empirical Study13 Jul 2026
- 2026The Patchwork Problem in LLM-Generated Code9 Jul 2026
- 2026Functional and Secure Code Generation with Task Vectors8 Jul 2026
- 2026MMIR-TCM: Memory-Integrated Multimodal Inference and Retrieval for TCM Clinical Decision Support2 Jul 2026
- 2026Correct Code, Vulnerable Dependencies: A Large Scale Measurement Study of LLM-Specified Library Versions7 May 2026
- 2026Surgical Repair of Insecure Code Generation in LLMs17 Apr 2026
- 2026DeepGuard: Secure Code Generation via Multi-Layer Semantic Aggregation10 Apr 2026
- 2026An Empirical Analysis of Static Analysis Methods for Detection and Mitigation of Code Library Hallucinations9 Apr 2026
- 2026Security-by-Design for LLM-Based Code Generation: Leveraging Internal Representations for Concept-Driven Steering Mechanisms11 Mar 2026
- 2026LLMs + Security = Trouble9 Feb 2026
- 2026Lookahead-then-Verify: Reliable Constrained Decoding for Diffusion LLMs under Context-Free Grammars31 Jan 2026
12 newest of 23 All 23 (JSON)