arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2610.14968cs.CRcs.LG
收藏

SEEK:用于安全代码生成的智能体式知识图谱检索

SEEK: Agentic Knowledge Graph Retrieval for Secure Code Generation

University of Duisburg-Essen(杜伊斯堡-埃森大学);University of Bristol(布里斯托大学);Technical University of Darmstadt(达姆施塔特工业大学)

Varun Gadey, Markus Tohn, Lichao Wu, Ahmad-Reza Sadeghi, Alexandra Dmitrienko

AI总结:

本研究提出名为SEEK的智能体式Graph RAG框架,以CWE分类法为基础构建安全知识图谱,通过规划与选择智能体优化安全代码生成,在多数据集及语言上优于现有方法,且泛化能力强。

摘要:

大型语言模型(LLM)可生成功能正确的代码,但会引入可被利用的安全漏洞,尤其是当开发者仅指定功能而未明确安全要求时。近期最先进的方法利用外部安全知识缓解该问题,但大多依赖对独立构件的平面相似度检索,难以推断相关漏洞空间,且在无直接匹配时难以检索针对性知识。我们提出SEEK,一种用于安全代码生成的智能体式Graph RAG框架,它以通用弱点枚举(CWE)分类法为结构主干构建安全知识图谱,并注入精心整理的真实世界CVE漏洞修复实例。推理时,规划智能体预测与开发者查询相关的潜在CWE弱点,指导图谱范围限定将检索限制在CWE分类法的相关区域,随后进行确定性多维度候选排序;选择智能体在代码生成前验证预测的弱点和检索到的候选。我们在5种开源LLM上,于CodeGuard+和CyberSecEval的分布外设置中评估SEEK,涵盖C、C++和Python语言。SEEK在CodeGuard+上达到最高的SecurePass@1为77.45%,在CyberSecEval上达到最高的综合ICD通过率为79.45%,优于现有方法;此外,SEEK在13种无直接关联漏洞修复实例的未见过的CWE类型上达到85.2%的SecurePass@1,展现出强泛化能力,同时保持可接受的推理延迟成本。

英文摘要:

Large Language Models (LLMs) can generate functionally correct code while introducing exploitable security weaknesses, particularly when developers specify functionality without explicit security requirements. Recent state-of-the-art approaches mitigate this problem using external security knowledge, but largely rely on flat similarity-based retrieval over independent artifacts, making it difficult to infer the relevant vulnerability space and retrieve targeted knowledge when direct matches are unavailable. We propose SEEK, an agentic Graph RAG framework for secure code generation that constructs a security knowledge graph using the Common Weakness Enumeration (CWE) taxonomy as its structural backbone and injects it with curated real-world CVE vulnerability-fix instances. At inference time, a Planner Agent predicts potential CWE weaknesses associated with the developer query, which guide Graph Scoping to restrict retrieval to relevant regions of the CWE taxonomy before deterministic multi-faceted candidate ranking. A Selection Agent subsequently validates the predicted weaknesses and retrieved candidates prior to code generation. Across five open-source LLMs, we evaluate SEEK in an out-of-distribution setting on CodeGuard+ and CyberSecEval, spanning C, C++, and Python. SEEK achieves the highest SecurePass@1 of 77.45% on CodeGuard+ and the highest aggregate ICD pass rate of 79.45% on CyberSecEval, surpassing prior approaches. Moreover, SEEK achieves 85.2% SecurePass@1 across 13 unseen CWE types with no directly linked vulnerability-fix instances, demonstrating strong generalizability, while maintaining acceptable inference latency costs.

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

↑