arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2602.10778cs.CR
收藏

GoodVibe:基于神经元的LLM代码生成安全增强方法

GoodVibe: Security-by-Vibe for LLM-Based Code Generation

Technical University of Darmstadt(达姆施塔特工业大学);University of Bristol(布里斯托大学);Radboud University(拉德堡德大学);University of Zagreb Faculty of Electrical Engineering and Computing(萨格勒布大学电气工程和计算学院)

Maximilian Thang, Lichao Wu, Sasha Behrouzi, Mohamadreza Rostami, Jona te Lintelo, Stjepan Picek, Ahmad-Reza Sadeghi

AI总结:

提出GoodVibe框架,通过梯度归因识别安全相关神经元并进行选择性微调,在保持模型通用性的同时显著提升代码生成安全性。

摘要:

大型语言模型(LLMs)越来越多地用于快速、非正式的开发工作流中的代码生成,通常被称为“vibe coding”,其中速度和便利性被优先考虑,而安全要求很少被明确说明。在这种设置下,模型经常生成功能正确但不安全的代码,造成日益增长的安全风险。现有的改进代码安全的方法依赖于全参数微调或参数高效适配,这些方法要么成本高昂且容易发生灾难性遗忘,要么以粗粒度运行且可解释性和可控性有限。我们提出了GoodVibe,一个神经元级别的框架,用于默认提高代码语言模型的安全性。GoodVibe基于关键洞察:安全相关的推理局限于一小部分神经元。我们使用基于梯度的归因从监督安全任务中识别这些神经元,并执行神经元选择性微调,仅更新这个安全关键子空间。为了进一步降低训练成本,我们引入了激活驱动的神经元聚类,实现结构化更新且开销最小。我们在六个LLM上进行了评估,涵盖安全关键的编程语言,包括C++、Java、Swift和Go。GoodVibe显著提高了生成代码的安全性,同时保持了模型的通用效用,相比基础模型实现了高达2.5倍的改进,性能与全微调相当,但使用的可训练参数减少了4700倍以上,并且与参数高效基线(LoRA)相比,训练计算量减少了3.6倍以上。我们的结果表明,神经元级优化提供了一种有效且可扩展的方法来确保代码生成的安全性,而不会牺牲通用性。

英文摘要:

Large language models (LLMs) are increasingly used for code generation in fast, informal development workflows, often referred to as vibe coding, where speed and convenience are prioritized, and security requirements are rarely made explicit. In this setting, models frequently produce functionally correct but insecure code, creating a growing security risk. Existing approaches to improving code security rely on full-parameter fine-tuning or parameter-efficient adaptations, which are either costly and prone to catastrophic forgetting or operate at coarse granularity with limited interpretability and control. We present GoodVibe, a neuron-level framework for improving the security of code language models by default. GoodVibe is based on the key insight that security-relevant reasoning is localized to a small subset of neurons. We identify these neurons using gradient-based attribution from a supervised security task and perform neuron-selective fine-tuning that updates only this security-critical subspace. To further reduce training cost, we introduce activation-driven neuron clustering, enabling structured updates with minimal overhead. We evaluate GoodVibe on six LLMs across security-critical programming languages, including C++, Java, Swift, and Go. GoodVibe substantially improves the security of generated code while preserving general model utility, achieving up to a 2.5x improvement over base models, achieving performance competitive with full fine-tuning while using over 4,700x fewer trainable parameters, and reducing training computation by more than 3.6x compared to the parameter-efficient baseline (LoRA). Our results demonstrate that neuron-level optimization offers an effective and scalable approach to securing code generation without sacrificing generality.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑