Lune

ISSTA2024Top-tier venue

CoSec: On-the-Fly Security Hardening of Code LLMs via Supervised Co-decoding

Dong Li, Meng Yan, Yaosheng Zhang, Zhongxin Liu, Chao Liu, Xiaohong Zhang, Ting Chen, David Lo

Abstract

Large Language Models (LLMs) specialized in code have shown exceptional proficiency across various programming-related tasks, particularly code generation. Nonetheless, due to its nature of pretraining on massive uncritically filtered data, prior studies have shown that code LLMs are prone to generate code with potential vulnerabilities. Existing approaches to mitigate this risk involve crafting data without vulnerability and subsequently retraining or fine-tuning the model. As the number of parameters exceeds a billion, the computation and data demands of the above approaches will be enormous. Moreover, an increasing number of code LLMs tend to be distributed as services, where the internal representation is not accessible, and the API is the only way to reach the LLM, making the prior mitigation strategies non-applicable. To cope with this, we propose CoSec, an on-the-fly Security hardening method of code LLMs based on security model-guided Co-decoding, to reduce the likelihood of code LLMs to generate code containing vulnerabilities. Our key idea is to train a separate but much smaller security model to co-decode with a target code LLM. Since the trained secure model has higher confidence for secure tokens, it guides the generation of the target base model towards more secure code generation. By adjusting the probability distributions of tokens during each step of the decoding process, our approach effectively influences the tendencies of generation without accessing the internal parameters of the target code LLM. We have conducted extensive experiments across various parameters in multiple code LLMs (i.e., CodeGen, StarCoder, and DeepSeek-Coder), and the results show that our approach is effective in security hardening. Specifically, our approach improves the average security ratio of six base models by 5.02%-37.14%, while maintaining the functional correctness of the target model.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

5 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • LoRA: Low-Rank Adaptation of Large Language Models cites Language Models are Few-Shot Learners
  • Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributions cites Language Models are Few-Shot Learners
  • RESCUE: Retrieval Augmented Secure Code Generation cites Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributions
  • RESCUE: Retrieval Augmented Secure Code Generation cites Give LLMs a Security Course: Securing Retrieval-Augmented Code Generation via Knowledge Injection
  • RESCUE: Retrieval Augmented Secure Code Generation cites Efficient Memory Management for Large Language Model Serving with PagedAttention
  • Give LLMs a Security Course: Securing Retrieval-Augmented Code Generation via Knowledge Injection cites Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributions
  • Give LLMs a Security Course: Securing Retrieval-Augmented Code Generation via Knowledge Injection cites Language Models are Few-Shot Learners
  • Chasing Shadows: Pitfalls in LLM Security Research cites CodeT5+: Open Code Large Language Models for Code Understanding and Generation
  • Chasing Shadows: Pitfalls in LLM Security Research cites Language Models are Few-Shot Learners
  • DeepGuard: Secure Code Generation via Multi-Layer Semantic Aggregation cites Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributions
  • Efficient Memory Management for Large Language Model Serving with PagedAttention cites Language Models are Few-Shot Learners
  • Understanding and Improving Model Editing for Secure Code Generation cites Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributions
  • Understanding and Improving Model Editing for Secure Code Generation cites Language Models are Few-Shot Learners
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers5

  1. Chasing Shadows: Pitfalls in LLM Security ResearchJonathan Evertz, Niklas Risse, Nicolai Neuer, Andreas Müller et al.NDSS 2026 · 17 citations
  2. RESCUE: Retrieval Augmented Secure Code GenerationJiahao Shi, Tianyi ZhangICLR 2026 · 15 citations
  3. DeepGuard: Secure Code Generation via Multi-Layer Semantic AggregationLi Huang, Zhongxin Liu, Yifan Wu, Tao Yin et al.ACL 2026 · 1 citation
  4. Give LLMs a Security Course: Securing Retrieval-Augmented Code Generation via Knowledge InjectionBo Lin, Shangwen Wang, Yihao Qin, Liqian Chen et al.CCS 2025
  5. Understanding and Improving Model Editing for Secure Code GenerationWeifeng Sun, Quanjun Zhang, Yuchen Chen, Chengran Yang et al.ISSTA 2026

Builds on22

  1. Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
  2. LoRA: Low-Rank Adaptation of Large Language ModelsEdward J. Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu et al.ICLR 2022 · 18,833 citations
  3. Efficient Memory Management for Large Language Model Serving with PagedAttentionWoosuk Kwon, Zhuohan Li, Siyuan Zhuang, Ying Sheng et al.SOSP 2023 · 1,016 citations
  4. Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code ContributionsHammond Pearce, Baleegh Ahmad, Benjamin Tan, Brendan Dolan-Gavitt et al.S&P 2022 · 725 citations
  5. CodeT5+: Open Code Large Language Models for Code Understanding and GenerationYue Wang, Hung Le, Akhilesh Gotmare, Nghi D. Q. Bui et al.EMNLP 2023 · 339 citations

Related papers

  1. Large Language Models for Code: Security Hardening and Adversarial TestingJingxuan He, Martin T. VechevCCS 2023 · 98 citations
  2. Decoding Secret Memorization in Code LLMs Through Token-Level CharacterizationYuqing Nie, Chong Wang, Kailong Wang, Guoai Xu et al.ICSE 2025 · 10 citations
  3. Rethinking the Evaluation of Secure Code GenerationShih-Chieh Dai, Jun Xu, Guanhong TaoICSE 2026 · 1 citation
  4. PromSec: Prompt Optimization for Secure Generation of Functional Source Code with Large Language Models (LLMs)Mahmoud Nazzal, Issa Khalil, Abdallah Khreishah, NhatHai PhanCCS 2024 · 16 citations
  5. Repairing LLM Executions for Secure Automatic ProgrammingAli El Husseini, Yacine Izza, Blaise Genest, Abhik RoychoudhuryICSE 2026
Dusk over the sea between two cliffs drawn in fine vertical lines