arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2510.09682cs.CRcs.AIcs.SE
收藏

基于安全编码实践的图推理强化LLM代码生成

Fortifying LLM-Based Code Generation with Graph-Based Reasoning on Secure Coding Practices

Rupam Patir, Keyan Guo, Haipeng Cai, Hongxin Hu

AI总结:

本文提出GRASP框架,通过构建安全编码实践的有向无环图并引导LLM进行图推理生成代码,无需额外训练即可显著提升代码安全性,对零日漏洞改进达88%。

摘要:

大型语言模型(LLMs)的代码生成能力已经改变了软件开发领域。然而,这一进步也带来了重大的安全挑战,因为LLM生成的代码通常包含漏洞。一个研究方向是通过精选数据集、模型微调或静态分析器注入或完善安全知识来增强LLMs。虽然这些方法在某些场景下有效,但它们可能资源消耗大,对零日漏洞的适应性较差,且通常不适用于专有模型。为了应对这些挑战,我们引入了GRASP,它探索了一个新方向,专注于对安全编码实践(SCPs)进行结构化推理,而不是额外的训练或外部反馈。GRASP包含两个核心思想:(1)一个SCP图,将SCPs组织成有向无环图(DAG)以捕获依赖关系和关联;(2)一个基于图的推理过程,系统地引导LLMs通过相关SCPs进行代码生成。这种设计实现了可解释、模型无关且可扩展的安全性提升,特别是对于以前未见过的漏洞。我们的评估表明,GRASP在多个LLMs上始终实现超过80%的安全率(SR),并且在零日漏洞上相比基线提供了高达88%的改进。

英文摘要:

The code generation capabilities of Large Language Models (LLMs) have transformed the field of software development. However, this advancement also presents significant security challenges, as LLM-generated code often contains vulnerabilities. One direction of research strengthens LLMs by injecting or refining security knowledge through curated datasets, model tuning, or static analyzers. While effective in certain settings, these methods can be resource-intensive, less adaptable to zero-day vulnerabilities, and often inapplicable to proprietary models. To address these challenges, we introduce GRASP, which explores a new direction that focuses on structured reasoning over Secure Coding Practices(SCPs) rather than additional training or external feedback. GRASP comprises two key ideas: (1) an SCP graph that organizes SCPs into a Directed Acyclic Graph (DAG) capturing dependencies and relationships, and (2) a graph-based reasoning process that systematically guides LLMs through relevant SCPs for code generation. This design enables interpretable, model-agnostic, and scalable security improvements, particularly for previously unseen vulnerabilities. Our evaluation shows that GRASP consistently achieves Security Rates (SR) exceeding 80% across multiple LLMs, and delivers up to 88% improvements over baselines on zero-day vulnerabilities.

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

↑