Graph Neural Networks for Vulnerability Detection: A Counterfactual Explanation

Zhaoyang Chu, Yao Wan, Qian Li, Yang Wu, Hongyu Zhang +3 more
4/24/2024
cs.SEcs.AIcs.CR

No official code found. Best implementation: Zhaoyang-Chu/counterfactual-vulnerability-detection (34 stars, Apache-2.0, last commit 2025-06-06).

Abstract

Vulnerability detection is crucial for ensuring the security and reliability of software systems. Recently, Graph Neural Networks (GNNs) have emerged as a prominent code embedding approach for vulnerability detection, owing to their ability to capture the underlying semantic structure of source code. However, GNNs face significant challenges in explainability due to their inherently black-box nature. To this end, several factual reasoning-based explainers have been proposed. These explainers provide explanations for the predictions made by GNNs by analyzing the key features that contribute to the outcomes. We argue that these factual reasoning-based explanations cannot answer critical what-if questions: What would happen to the GNN's decision if we were to alter the code graph into alternative structures? Inspired by advancements of counterfactual reasoning in artificial intelligence, we propose CFExplainer, a novel counterfactual explainer for GNN-based vulnerability detection. Unlike factual reasoning-based explainers, CFExplainer seeks the minimal perturbation to the input code graph that leads to a change in the prediction, thereby addressing the what-if questions for vulnerability detection. We term this perturbation a counterfactual explanation, which can pinpoint the root causes of the detected vulnerability and furnish valuable insights for developers to undertake appropriate actions for fixing the vulnerability. Extensive experiments on four GNN-based vulnerability detection models demonstrate the effectiveness of CFExplainer over existing state-of-the-art factual reasoning-based explainers.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

This repository contains a PyTorch implementation of the ISSTA'24 paper "Graph Neural Networks for Vulnerability Detection: A Counterfactual Explanation".

343Shell, PythonMar 31, 20241 years agoApache-2.0

Similar Papers

Cite this paper

@article{chu2024graph,
  title  = {Graph Neural Networks for Vulnerability Detection: A Counterfactual Explanation},
  author = {Zhaoyang Chu and Yao Wan and Qian Li and Yang Wu and Hongyu Zhang and Yulei Sui and Guandong Xu and Hai Jin},
  year   = {2024},
  eprint = {2404.15687},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2404.15687v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2404.15687.svg)](https://codeofpaper.com/paper/2404.15687)

Discussion