用生成程序自动修复代码漏洞检测查询中的误报漏报问题
ARQ: Agentic CodeQL Query Refinement for C/C++ Vulnerability Detection
- 通过生成测试程序检验查询正确性,利用执行结果反推漏洞模式缺陷
- 修复后查询漏报率降低超119%,准确率保持98%以上
- 无需标注数据或历史代码,适合维护静态分析工具的开发者
静态分析器广泛用于C/C++程序漏洞检测。基于查询的静态分析器(如CodeQL)通过编码漏洞模式进行匹配,但现有查询仍存在误报(错误标记安全代码为漏洞)和漏报(遗漏真实漏洞)问题。本文提出ARQ,一种基于智能体的框架,利用合成的C/C++程序执行结果来自动优化CodeQL查询。其核心思想是:当合成程序的执行结果与查询判定不一致时,暴露了查询的缺陷——若程序实际有漏洞而查询未报警,则为漏报;若程序安全但查询触发,则为误报。ARQ通过基于大模型的迭代优化流程,以这些不一致作为真实标签修复查询。相比以往方法,ARQ无需标注数据、提交历史或特定漏洞模板。我们使用三个商用大模型(GPT-5.4、Claude-Sonnet-4.6、Gemini-3.5-flash)对12个官方CodeQL查询进行优化,在Juliet v1.3和FormAI v2数据集上验证,优化后查询真阳性检出率最高提升119.8%,且精度始终不低于98.0%。ARQ成功修复了三个长达27个月未解决的GitHub官方查询问题,并在libpng和zlib两个真实库中发现了两个此前未知的漏洞。
原文摘要 · Abstract (English)
Static analyzers have been widely adopted for vulnerability detection in C/C++ programs. Query-based static analyzers (e.g., CodeQL) encode vulnerable code patterns in detection queries and match them against source code. However, existing queries still suffer from false positives (FPs, incorrectly flagging benign code as vulnerable) and false negatives (FNs, missing real vulnerabilities). We present ARQ, an agentic framework that automatically refines C/C++ CodeQL queries using execution-grounded evidence from synthesized C/C++ programs. Our key insight is that a synthesized program exposes a query's weakness whenever its execution disagrees with the query's verdict. If the program is genuinely vulnerable but the query stays silent, the query has an FN weakness; if the program is safe but the query fires anyway, it has an FP weakness. ARQ then runs an LLM-based refinement loop that repairs the query using these disagreements as ground truth. Unlike previous query refining methods, ARQ requires no labeled datasets, no commit history, and no vulnerability-specific templates. We demonstrate the effectiveness of ARQ by refining 12 official CodeQL queries using three commercial LLMs (GPT-5.4, Claude-Sonnet-4.6, and Gemini-3.5-flash). We compare both ARQ-refined and original CodeQL queries on the Juliet v1.3 and FormAI v2 datasets and show that ARQ-refined queries detect substantially more true positives, by up to 119.8\%, with a Precision of at least 98.0\% throughout. ARQ successfully fixed three unresolved GitHub issues raised in the official CodeQL query repository that had remained open for as long as \textit{27 months}. The refined queries also exposed two previously undiscovered bugs in the real-world libraries libpng and zlib.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。