Skip to content
Preprint

Functional and Secure Code Generation with Task Vectors

Jul 2026 · 0 citations · 35 references
Computer Science

TL;DR

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.

Abstract

Large language models (LLMs) are increasingly used for code generation, but they struggle to generate functional code free of security vulnerabilities. Prior work to improve the secure code generation abilities of such coding LLMs has largely focused on evaluating code functionality and security separately using different datasets, or focused on finding vulnerabilities post-generation. At the same time, the text-generation domain has seen significant work on alignment techniques, where models are tuned such that their outputs exhibit certain qualities (e.g., helpfulness, harmlessness). Of particular interest is task-vector arithmetic, where linear operations on LLM weights can be used to arbitrarily enhance alignment while incurring only minimal computational overhead. We develop a novel method, SecVecCoder, leveraging task vectors to produce trustworthy code that is simultaneously functional and secure without the need for post-generation adjustment. Across six coding LLMs from three families on the CodeGuard+ benchmark, SecVecCoder improves the rate of trustworthy code completions by 2.1-36.0 percentage points over the base model, with improvements on unseen CWE types reaching up to 39.1 percentage points. Since the effectiveness of the coding LLM relies only on changing the model weights, SecVecCoder requires no method-specific decoding and hence achieves a decoding latency within 0.6% of the base model's, on average.

View source

Similar papers

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
Jul 2026

The Language of Security: How Prompt Syntax Shapes Secure Code Generation in Open LLMs

This work systematically generates syntactic variants of security-relevant code generation prompts and evaluates their impact on code security across multiple open LLMs and programming languages, identifying prompt syntax as a concrete security control surface and providing actionable guidance for reducing vulnerabilit...

Matteo Cicalese, Antonio Della Porta, Stefano Lambiase et al. · 0 citations
#small language model Preprint Aug 2026

Vulnerable Code Search: Transferable Attack for Code Language Models

This paper introduces a programming language-agnostic, transferable, adversarial attack that exploits this CLM vulnerability and demonstrates that this attack, even when computed using smaller code embedding models, is highly effective and transferable to larger, closed-source embedding models.

Kaicheng Wang, Li-Yan Huang, Jesse Thomason et al. · 0 citations
Open access Sep 2025

Empirical Study of Code Large Language Models for Binary Security Patch Detection

This initial study demonstrates that directly prompting off-the-shelf code LLMs remains ineffective; even advanced prompting strategies cannot compensate for the lack of task-specific knowledge, and fine-tuning proves highly effective, with pseudo-code representation consistently yielding the best performance.

Qingyuan Li, Bin-Chang Li, Cuiyun Gao et al. · 3 citations · ⚡1
Open access Jul 2026

AlquistCoder: A Synthetic Data Approach to Training Compact Secure Coding Assistants and Building Security Benchmarks

AlquistCoder, a compact 3.8B‐parameter coding assistant designed to address both risks through targeted synthetic‐data alignment, is introduced and publicly released to support reproducible research on security alignment for code‐generation models.

Ondřej Kobza, Adam Černý, Ivanka M. Dostal et al. · 0 citations

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