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

面向基于大语言模型的代码生成的Security-by-Design:利用内部表示进行概念驱动的引导机制

Security-by-Design for LLM-Based Code Generation: Leveraging Internal Representations for Concept-Driven Steering Mechanisms

Maximilian Wendlinger, Daniel Kowatsch, Konstantin Böttinger, Philip Sperl

AI总结:

本文提出SCS-Code,通过引导大语言模型的内部表示生成安全且功能性的代码,解决现有方法在安全性和功能正确性上的不足。

摘要:

大语言模型(LLMs)在理解自然语言和生成复杂代码方面表现出显著能力。然而,随着从业者越来越多地使用CodeLLMs进行日益关键的开发任务,研究发现这些模型经常生成功能正确但不安全的代码,带来了重大安全风险。尽管已提出多种方法来提高AI基于代码生成的安全性,但综合基准测试显示这些方法仍不足以用于实际应用,仅在功能正确性和安全性方面实现了有限的改进。这源于对代码生成内部机制和安全漏洞根本原因理解的差距,迫使研究人员依赖启发式方法和经验观察。在本工作中,我们研究了CodeLLMs中安全概念的内部表示,揭示模型在生成不安全代码时往往已经意识到漏洞。通过系统评估,我们证明CodeLLMs能够区分安全子概念,使分析比以往的黑盒方法更加细致。利用这些见解,我们提出了Secure Concept Steering for CodeLLMs(SCS-Code)。在token生成过程中,SCS-Code引导LLM的内部表示朝向安全且功能性的代码输出,使一种轻量且模块化的机制能够集成到现有代码模型中。我们的方法在多个安全编码基准测试中优于最先进的方法。

英文摘要:

Large Language Models (LLMs) show remarkable capabilities in understanding natural language and generating complex code. However, as practitioners adopt CodeLLMs for increasingly critical development tasks, research reveals that these models frequently generate functionally correct yet insecure code, posing significant security risks. While multiple approaches have been proposed to improve security in AI-based code generation, combined benchmarks show these methods remain insufficient for practical use, achieving only limited improvements in both functional correctness and security. This stems from a fundamental gap in understanding the internal mechanisms of code generation and the root causes of security vulnerabilities, forcing researchers to rely on heuristics and empirical observations. In this work, we investigate the internal representation of security concepts in CodeLLMs, revealing that models are often aware of vulnerabilities as they generate insecure code. Through systematic evaluation, we demonstrate that CodeLLMs can distinguish between security subconcepts, enabling a more fine-grained analysis than prior black-box approaches. Leveraging these insights, we propose Secure Concept Steering for CodeLLMs (SCS-Code). During token generation, SCS-Code steers LLMs' internal representations toward secure and functional code output, enabling a lightweight and modular mechanism that can be integrated into existing code models. Our approach achieves superior performance compared to state-of-the-art methods across multiple secure coding benchmarks.

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

↑