CRSEAug 7

Understanding and Improving Model Editing for Secure Code Generation

arXiv:2608.0684811.0h-index: 4
Predicted impact top 35% in CR · last 90 daysOriginality Incremental advance
AI Analysis

This work addresses the problem of reducing vulnerable code generation for developers using LLMs, offering a model-level hardening approach. It is an incremental improvement over existing model editing techniques.

This paper investigates model editing as a mechanism to harden large language models against generating vulnerable code. It finds that model editing improves security ratios by 15%-25% on seen vulnerability types, and proposes SafeEdit, a post-edit refinement method that improves Pass@1 over UltraEdit by 11.73-15.50 percentage points while largely preserving security.

Large language models (LLMs) are widely used for code generation, yet they can reproduce vulnerable implementations learned from insecure training patterns. Prior work has mainly explored inference-time hardening, which reduces insecure generations without modifying the target model but relies on auxiliary components and adds runtime overhead. We conduct the first systematic study of model editing as a model-level hardening mechanism for secure code generation. We evaluate 3 state-of-the-art editing methods across diverse LLM families and compare them with CoSec, a representative inference-time approach, focusing on security, robustness, generalization, and functional correctness. Model editing yields larger security gains than CoSec on seen vulnerability types, improving security ratios by 15%-25% over vanilla models, with gains remaining stable under prompt perturbations. However, these improvements transfer unreliably to unseen vulnerabilities and can reduce functional correctness. To mitigate this trade-off, we propose SafeEdit, a post-edit refinement method combining functional tuning with edit-aware regularization. Across eight target LLMs, SafeEdit improves Pass@1 over UltraEdit by 11.73/13.70/15.50 percentage points at T=0.1/0.4/0.8 while largely preserving security. Compared with CoSec, it achieves relative security-ratio gains of 7.54%-12.04%. Additional evaluation on CodeGuard+ confirms improved joint secure-and-correct generation. SafeEdit and CoSec are also complementary, and their combination can further improve security while maintaining strong functional correctness. Overall, our results provide evidence-backed guidance for applying model editing to secure code generation.

Foundations

The foundational work for this paper's niche, ranked by how specifically the neighbourhood builds on it — not by global fame.

Your Notes