Understanding and Improving Model Editing for Secure Code Generation
Weifeng Sun, Quanjun Zhang, Yuchen Chen, Chengran Yang, Gou Tan, David Lo
Singapore Management University · Nanjing University of Science and Technology
Key points
From the paper's conclusion- We present the first systematic study of model editing as a model-level hardening mechanism for secure code generation, directly injecting security knowledge through localized parameter updates.
- Model editing substantially outperforms CoSec on seen vulnerabilities, improving security ratios by 15.
Abstract
Large language models (LLMs) are widely used for code generation but may reproduce vulnerabilities learned from insecure training data. Prior work mainly relies on inference-time hardening, which introduces auxiliary components and runtime overhead. We present the first systematic study of model editing as a model-level hardening mechanism for secure code generation, directly injecting security knowledge through localized parameter updates. We evaluate three state-of-the-art editing methods across diverse LLM families against CoSec, a representative inference-time approach, examining security effectiveness and robustness, generalization to unseen vulnerabilities, and functional correctness. Model editing substantially outperforms CoSec on seen vulnerabilities, improving security ratios by 15
Read the paper
Discussion · 1
Science Skim's AI key points, plus readers' public thoughts
- We present the first systematic study of model editing as a model-level hardening mechanism for secure code generation, directly injecting security knowledge through localized parameter updates.
- Model editing substantially outperforms CoSec on seen vulnerabilities, improving security ratios by 15.
Readers' thoughts
No reader thoughts yet.
Related papers
- Security Tests as Executable Specifications for LLM Code Generation: Benefits, Trade-offs, and Coverage LimitsarXiv · 2026
- Secure and Functional Code Generation with Self-EvaluationarXiv · 2026
- Decalage: Uncovering the Gap Between Model-Generated Reasoning and Actual Code Implementation in Small Language ModelsarXiv · 2026
- Static Analysis Guidance for Secure LLM Code GenerationarXiv · 2026
- Toward Secure Code Generation: Bridging Correctness and Security via Task-Adaptive Vulnerability Modeling and Execution-Based BenchmarkingProceedings of the ACM on software engineering. · 2026
- Fine-Grained Reasoning Enhanced Vulnerability Patch Generation with Multi-View Fix KnowledgeACM Transactions on Software Engineering and Methodology · 2026