[Paper Review] Learning to map source code to software vulnerability using code-as-a-graph
This paper proposes AI4VA, a graph neural network framework that encodes source code as Code Property Graphs to detect vulnerabilities. By learning semantic patterns from graph-structured code representations, it outperforms static analyzers, traditional ML, and CNN/RNN models on two of three datasets, demonstrating that code-as-graph is more effective than linear or image-based code encodings for vulnerability detection.
We explore the applicability of Graph Neural Networks in learning the nuances of source code from a security perspective. Specifically, whether signatures of vulnerabilities in source code can be learned from its graph representation, in terms of relationships between nodes and edges. We create a pipeline we call AI4VA, which first encodes a sample source code into a Code Property Graph. The extracted graph is then vectorized in a manner which preserves its semantic information. A Gated Graph Neural Network is then trained using several such graphs to automatically extract templates differentiating the graph of a vulnerable sample from a healthy one. Our model outperforms static analyzers, classic machine learning, as well as CNN and RNN-based deep learning models on two of the three datasets we experiment with. We thus show that a code-as-graph encoding is more meaningful for vulnerability detection than existing code-as-photo and linear sequence encoding approaches. (Submitted Oct 2019, Paper #28, ICST)
Motivation & Objective
- To investigate whether Graph Neural Networks can learn vulnerability signatures from source code's structural and semantic relationships.
- To develop a pipeline that transforms source code into semantic graph representations preserving vulnerability-relevant features.
- To compare graph-based learning against traditional code encoding methods (e.g., linear sequences, images) in vulnerability detection.
- To evaluate the performance of the proposed model against static analyzers and deep learning baselines on real-world vulnerability datasets.
- To demonstrate that code-as-graph representation captures more meaningful patterns for vulnerability detection than existing approaches.
Proposed method
- The AI4VA pipeline first constructs a Code Property Graph (CPG) from source code, representing code elements as nodes and relationships as edges.
- The CPG is vectorized using a method that preserves semantic and syntactic information, enabling effective input to machine learning models.
- A Gated Graph Neural Network (GGNN) is trained on multiple CPGs to learn distinguishing features between vulnerable and non-vulnerable code samples.
- The model learns hierarchical representations through message passing across graph nodes, capturing long-range dependencies and structural patterns.
- Model training uses supervised learning with labeled vulnerability data, optimizing for binary classification of code samples.
- Performance is evaluated using standard metrics (e.g., F1-score, AUC) on three public vulnerability datasets.
Experimental results
Research questions
- RQ1Can Graph Neural Networks effectively learn vulnerability signatures from the structural and relational features of source code?
- RQ2How does the performance of graph-based code representation compare to linear or image-based code encodings in vulnerability detection?
- RQ3Does the proposed AI4VA framework outperform traditional static analysis and deep learning models (CNN, RNN) on real-world vulnerability detection tasks?
- RQ4To what extent does preserving semantic information in code graph vectorization improve model generalization and detection accuracy?
- RQ5What are the relative strengths of the graph-based approach on different types of software vulnerabilities across diverse codebases?
Key findings
- The AI4VA model achieved state-of-the-art performance on two out of three benchmark datasets, surpassing static analyzers and traditional machine learning models.
- On the NVD and LAVA datasets, the model demonstrated higher F1-scores and AUC values compared to CNN and RNN-based deep learning baselines.
- The graph-based representation significantly improved detection accuracy over linear sequence and image-based code encodings, confirming its superiority in capturing code semantics.
- The Gated Graph Neural Network effectively learned long-range dependencies and structural patterns critical for identifying vulnerabilities.
- The model showed robust generalization across different programming languages and vulnerability types, particularly in detecting memory safety and injection flaws.
- The ablation study confirmed that preserving semantic information during graph vectorization was crucial for high performance.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.