Skip to content

CoGate: Confidence-Gated Co-Decoding for Secure Code Generation

Jul 2026 · arXiv.org · Vol abs/2607.28529 · 0 citations · 33 references
Computer Science

TL;DR

CoGate is proposed, a confidence-gated co-decoding approach that controls the expert's influence on the co-decoding process based on its confidence, and outperforms existing co-decoding methods (CoSec+) across multiple benchmarks.

Abstract

Large language models are widely used for code generation, but they can also produce insecure programs due to patterns learned from their pretraining data. Decoding-time steering has become an important solution to this problem: a small expert model is combined with the target model at each step to generate more secure code, which is referred to as co-decoding. However, the acceptance rule for existing co-decoding approaches does not consider the expert model's confidence. When the security expert is unconfident due to unseen patterns or out-of-distribution (OOD) contexts, its guidance can therefore be misleading. To address the challenge, we propose CoGate, a confidence-gated co-decoding approach that controls the expert's influence on the co-decoding process based on its confidence. We implement our approach and evaluate it across multiple LLM backends (CodeGen, DeepSeek-Coder, Qwen-Coder, StarCoder) on several code generation benchmarks (HumanEval, security suite, and CWEval). Our approach outperforms existing co-decoding methods (CoSec+) across multiple benchmarks, achieving up to a 12.6% gain of Func-Sec@10 on CWEval.

View source

Similar papers

Jul 2026

Quantize with Confidence? An Empirical Study of Quantization for Code Generation

Six state-of-the-art quantization methods are evaluated on two representative large code model families using the multilingual McEval and CoderEval benchmarks for Python and Java to provide practical guidance for selecting quantization strategies for deploying large code models on resource-constrained hardware.

Saima Afrin, MD Zahidul Haque, A. Mastropaolo · 0 citations
Preprint Jul 2026

Functional and Secure Code Generation with Task Vectors

A novel method is developed, SecVecCoder, leveraging task vectors to produce trustworthy code that is simultaneously functional and secure without the need for post-generation adjustment, and achieves a decoding latency within 0.6% of the base model's, on average.

F. Wang, Anudeep Das, M. Nagappan et al. · 0 citations
Preprint Open access Aug 2026

Understanding and Improving Model Editing for Secure Code Generation

The first systematic study of model editing as a model-level hardening mechanism for secure code generation is conducted, evaluating 3 state-of-the-art editing methods across diverse LLM families and comparing them with CoSec, a representative inference-time approach, focusing on security, robustness, generalization, a...

Wei-Feng Sun, Quan-Jun Zhang, Yuchen Chen et al. · 0 citations
Book Open access Jul 2026

When AI Coding Assistants Leak Training Data: A Study of LLM Memorization in Code Generation

It is confirmed that memorization persists in modern LLMs and is influenced more by a complex interplay of training domain, dataset composition, architectural choices, and content characteristics, rather than parameter count alone.

Xiaoyu Cheng, Kundi Yao, Pengyu Nie et al. · 0 citations
Preprint Jul 2026

When Uncertainty Isn't Enough: An Empirical Study of Self-Correction in Code Generation

It is suggested that cheap uncertainty estimators are insufficient on their own to improve code correctness, and that their practical value lies in serving as gating signals for costlier execution-based correction loops rather than as standalone substitutes for verification.

Pranav Rakasi, Maanas Lalwani, A. Srivastava et al. · 0 citations
Open access Aug 2026

Learning to detect hardcoded secrets

An in-depth investigation into the performance of different AI models in secret detection found that the choice of feature set greatly influences the performance in secret detection, and that prompt engineering reduces false predictions significantly, yet human intervention remains necessary.

Farnaz Soltaniani, Mohammad Ghafari · 1 citation

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.