← Lab /Software

Model editing boosts secure code generation by up to 25% but can hurt correctness

Model editing significantly improves security ratios of code-gen LLMs while SafeEdit recovers functional correctness

Software arXiv 7 Aug 2026 Method Prototype evidence

Published as “Understanding and Improving Model Editing for Secure Code Generation”

Why it matters

Model editing can harden LLM code generators without the runtime overhead of dual-model decoding, but practitioners must balance security gains against potential correctness regressions.

Summary

Model editing of LLMs yields substantially larger security gains than the inference-time hardening baseline CoSec, improving security ratios by 15%-25% on seen CWE types. The best editing method, UltraEdit, can be further refined with SafeEdit, which adds 11.73-15.50 percentage points to Pass@1 while largely preserving security and achieving up to 12.04% relative security-ratio gains over CoSec. However, the security improvements often do not transfer to unseen vulnerabilities and the edits cause non-negligible functional regressions on general coding tasks. The authors also show that model editing is far more efficient than CoSec, completing edits in 50-100 s versus hours for CoSec.

What they found 3

  1. Model editing improves security ratios by 15%-25% over vanilla models on seen CWEs, outperforming CoSec.

    “model editing yields substantially larger security gains than CoSec on seen vulnerability types, improving security ratios by 15%-25% over vanilla models”

  2. SafeEdit raises Pass@1 over UltraEdit by up to 15.50 points while largely preserving security.

    “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.”

  3. Model editing is far more efficient than CoSec, completing edits in seconds rather than hours.

    “Model editing is consistently more efficient than CoSec: UltraEdit completes editing within 50-100 seconds even for 8B-scale models, whereas CoSec requires hundreds to thousands of seconds to train an auxiliary security model and increases inference latency by 2-3×.”

Caveats 4

  • Both model editing methods and CoSec introduce non-negligible degradation in functional correctness.
  • However, security improvements do not always transfer reliably to unseen vulnerabilities.
  • DINM nearly collapses Pass@1 at layer-10 across both models, indicating severe disruption to foundational synthesis representations.
  • model editing is not a plug-and-play solution: careful design choices are needed to avoid overfitting to security cues at the expense of general code generation.

What’s new here 4

  • Applies model editing-a parameter-level update-to harden code generation, a contrast to prior inference-time defenses.
  • Provides the first systematic empirical comparison of multiple editing methods (UltraEdit, DINM, DEFER*) against CoSec across security, correctness, and efficiency.
  • Introduces SafeEdit, a post-edit refinement that combines functional tuning with edit-aware regularization to recover correctness.
  • Analyzes design factors such as editing depth, parameter location, and suffix length, offering concrete guidance for secure editing.