Utilizing Precise and Complete Code Context to Guide LLM in Automatic False Positive Mitigation

Jinbao Chen, Hongjing Xiang, Luhao Li, Yu Zhang, Boyao Ding, Qingwei LiarXiv 2024 · DOI

Static Application Security Testing (SAST) tools are essential for identifying vulnerabilities early in the development lifecycle. However, they are notorious for high false positive rates—often exceeding 20%—which can lead developers to ignore warnings or lose trust in the tools entirely. While Large Language Models (LLMs) offer a promising solution for filtering these "false alarms," existing approaches often struggle with two primary issues: imprecision (providing too much irrelevant code, leading to hallucinations) and incompleteness (missing critical context from external files).

This paper introduces LLM4FPM, a framework designed to provide LLMs with "surgical" code context to make highly accurate judgments on security warnings.

The LLM4FPM Framework

LLM4FPM addresses the context problem through two core technical innovations that work in tandem to prepare a structured report for the LLM.

The LLM4FPM workflow, featuring the FARF dependent file extractor and the eCPG-Slicer for precise context generation.

eCPG-Slicer: Line-Level Precision

Standard Code Property Graphs (CPGs) often fail to capture subtle dependencies, such as the relationship between an if condition and its corresponding else block. The researchers developed an enhanced CPG (eCPG) that incorporates these missing structural and variable dependencies. This allows for "line-level" slicing, which extracts only the specific lines of code that directly influence the logic or variable being flagged by the SAST tool. By removing the "noise" of irrelevant code, the framework reduces the cognitive load on the LLM.

FARF: Efficient Dependent File Extraction

Many bugs depend on variables or functions defined in other files. Analyzing an entire multi-million line project is computationally prohibitive, so the authors created FARF (Efficient Dependent File Extractor). FARF builds a File Reference Graph and utilizes graph theory (Strongly Connected Components) to rapidly identify only the external files that could possibly influence a specific warning. This ensures the LLM has the "big picture" without being overwhelmed by the entire codebase.

Experimental Results

The framework was evaluated using the open-source Qwen2.5-32b model across several datasets, including the synthetic Juliet dataset, the real-world D2A dataset, and eight major GitHub repositories (e.g., Redis, Curl, OpenSSL).

Performance improvements (Delta L-B) across different SAST tools and CWE categories, showing significant gains in accuracy and F1 scores.

Key findings include:

  • High Accuracy: On the Juliet dataset, LLM4FPM achieved an F1 score exceeding 99% across various Common Weakness Enumerations (CWEs), significantly outperforming previous state-of-the-art methods.
  • Real-World Impact: In tests on popular open-source projects totaling 2.5 million lines of code, the tool successfully eliminated over 85% of false positives generated by standard SAST tools.
  • Efficiency and Cost: The system averaged 4.7 seconds per warning and proved that high-quality analysis can be performed locally and affordably ($0.38 per warning) using mid-sized open-source models rather than expensive proprietary APIs.

Limitations and Future Work

While highly effective, the framework faces challenges with complex C language features. The underlying graph generation tool (Joern) can struggle with heavy macro usage (#define) and conditional compilation (#ifdef), which may lead to incomplete slices. Additionally, resolving function pointers remains a difficult static analysis problem. Future research will focus on achieving even more granular function-level dependency tracking and improving the handling of complex semantic logic in C/C++.

Summary updated

BibTeX
@misc{chen2024utilizing,
  author = {Jinbao Chen and Hongjing Xiang and Luhao Li and Yu Zhang and Boyao Ding and Qingwei Li},
  title = {{Utilizing Precise and Complete Code Context to Guide LLM in Automatic False Positive Mitigation}},
  year = {2024},
  eprint = {2411.03079},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.03079},
}
Figure