mlsanityData to 14 Oct 2026

Constrained Decoding for Secure Code Generation

arXiv 2405.00218 ↗First posted 30 Apr 2024cs.CR cs.AI cs.LGcited by 37

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

  1. 2023GPT-4 Technical Reportcited by 18,396
  2. 2021Evaluating Large Language Models Trained on Codecited by 8,320
  3. 2022PaLM: Scaling Language Modeling with Pathwayscited by 5,326
  4. 2021Prefix-Tuning: Optimizing Continuous Prompts for Generationcited by 3,915
  5. 2021Program Synthesis with Large Language Modelscited by 3,637
  6. 2019The Curious Case of Neural Text Degenerationcited by 2,916
  7. 2023Code Llama: Open Foundation Models for Codecited by 2,139
  8. 2023Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generationcited by 1,391
  9. 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,181
  10. 2022CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesiscited by 885
  11. 2024StarCoder 2 and The Stack v2: The Next Generationcited by 502
  12. 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 431
22 more
  1. 2022Do Users Write More Insecure Code with AI Assistants?cited by 192
  2. 2018Fast Lexically Constrained Decoding with Dynamic Beam Allocation for Neural Machine Translationcited by 182
  3. 2022COLD Decoding: Energy-based Constrained Text Generation with Langevin Dynamicscited by 161
  4. 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 155
  5. 2020NeuroLogic Decoding: (Un)supervised Neural Text Generation with Predicate Logic Constraintscited by 149
  6. 2023Purple Llama CyberSecEval: A Secure Coding Benchmark for Language Modelscited by 138
  7. 2016Guided Open Vocabulary Image Captioning with Constrained Beam Searchcited by 105
  8. 2021Examining Zero-Shot Vulnerability Repair with Large Language Modelscited by 105
  9. 2022Lost at C: A User Study on the Security Implications of Large Language Model Code Assistantscited by 91
  10. 2023How Secure is Code Generated by ChatGPT?cited by 81
  11. 2021Controlled Text Generation as Continuous Optimization with Multiple Constraintscited by 70
  12. 2024Instruction Tuning for Secure Code Generationcited by 68
  13. 2022Gradient-Based Constrained Sampling from Language Modelscited by 64
  14. 2023CodeLMSec Benchmark: Systematically Evaluating and Finding Security Vulnerabilities in Black-Box Code Language Modelscited by 55
  15. 2023The FormAI Dataset: Generative AI in Software Security Through the Lens of Formal Verificationcited by 34
  16. 2023DeceptPrompt: Exploiting LLM-driven Code Generation via Adversarial Natural Language Instructionscited by 33
  17. 2021Don't Take It Literally: An Edit-Invariant Sequence Loss for Text Generationcited by 17
  18. 2017Towards Decoding as Continuous Optimization in Neural Machine Translationcited by 15
  19. 2023Efficient Avoidance of Vulnerabilities in Auto-completed Smart Contract Code Using Vulnerability-constrained Decodingcited by 14
  20. 2024Just another copy and paste? Comparing the security vulnerabilities of ChatGPT generated code and StackOverflow answerscited by 13
  21. 2024Code Security Vulnerability Repair Using Reinforcement Learning with Large Language Modelscited by 10
  22. 2024Enhancing Security of AI-Based Code Synthesis with GitHub Copilot via Cheap and Efficient Prompt-Engineeringcited by 6

Built on by

Cited by year (2026 to 14 Oct)

Citing papers per year: 2024: 2; 2025: 16; 2026: 19.

37 papers.

Sort:

By area:

  1. 2025BaxBench: Can LLMs Generate Correct and Secure Backends?cited by 41
  2. 2025Frontier AI's Impact on the Cybersecurity Landscapecited by 21
  3. 2025Beyond Final Code: A Process-Oriented Error Analysis of Software Development Agents in Real-World GitHub Scenarioscited by 14
  4. 2025A.S.E: A Repository-Level Benchmark for Evaluating Security in AI-Generated Codecited by 14
  5. 2025SecureVibeBench: Benchmarking Secure Vibe Coding of AI Agents via Reconstructing Vulnerability-Introducing Scenarioscited by 13
  6. 2025Co-PatcheR: Collaborative Software Patching with Component(s)-specific Small Reasoning Modelscited by 12
  7. 2025Training Language Models to Generate Quality Code with Program Analysis Feedbackcited by 12
  8. 2025Rethinking the Evaluation of Secure Code Generationcited by 10
  9. 2025VeriStruct: AI-assisted Automated Verification of Data-Structure Modules in Veruscited by 9
  10. 2025RESCUE: Retrieval Augmented Secure Code Generationcited by 7
  11. 2026Lookahead-then-Verify: Reliable Constrained Decoding for Diffusion LLMs under Context-Free Grammarscited by 7
  12. 2025AutoBaxBuilder: Bootstrapping Code Security Benchmarkingcited by 5
25 more
  1. 2026HardSecBench: Benchmarking the Security Awareness of LLMs for Hardware Code Generationcited by 5
  2. 2024SeCodePLT: A Unified Platform for Evaluating the Security of Code GenAIcited by 4
  3. 2025SCGAgent: Recreating the Benefits of Reasoning Models for Secure Code Generation with Agentic Workflowscited by 4
  4. 2025Evaluating LLM Generated Detection Rules in Cybersecuritycited by 4
  5. 2026How Secure is Secure Code Generation? Adversarial Prompts Put LLM Defenses to the Testcited by 4
  6. 2026DeepGuard: Secure Code Generation via Multi-Layer Semantic Aggregationcited by 2
  7. 2025Fortifying LLM-Based Code Generation with Graph-Based Reasoning on Secure Coding Practicescited by 1
  8. 2025Secure Code Generation at Scale with Reflexioncited by 1
  9. 2025DualGauge: Automated Joint Security-Functionality Benchmarking of Specification-Only Code Generation by LLMs and Coding Agentscited by 1
  10. 2026SecPI: Secure Code Generation with Reasoning Models via Security Reasoning Internalizationcited by 1
  11. 2026Surgical Repair of Insecure Code Generation in LLMscited by 1
  12. 2026Themis: Training Robust Multilingual Code Reward Models for Flexible Multi-Criteria Scoringcited by 1
  13. 2026Correct Code, Vulnerable Dependencies: A Large Scale Measurement Study of LLM-Specified Library Versionscited by 1
  14. 2024CVE-LLM : Automatic vulnerability evaluation in medical device industry using large language modelscited by 0
  15. 2026LLMs + Security = Troublecited by 0
  16. 2026Security-by-Design for LLM-Based Code Generation: Leveraging Internal Representations for Concept-Driven Steering Mechanismscited by 0
  17. 2026An Empirical Analysis of Static Analysis Methods for Detection and Mitigation of Code Library Hallucinationscited by 0
  18. 2026SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forwardcited by 0
  19. 2026MMIR-TCM: Memory-Integrated Multimodal Inference and Retrieval for TCM Clinical Decision Supportcited by 0
  20. 2026Steerability via constraints: a substrate for scalable oversight of coding agentscited by 0
  21. 2026Functional and Secure Code Generation with Task Vectorscited by 0
  22. 2026The Patchwork Problem in LLM-Generated Codecited by 0
  23. 2026Understanding the Impact of AI Code Assistants on Security API Usage: An Empirical Studycited by 0
  24. 2026Beyond Tokens: A Survey on Decoding Methods for Large Language and Vision-Language Modelscited by 0
  25. 2026Security in LLM-Assisted Coding: A Systematic Literature Reviewcited by 0