NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Enhancing Security Patch Identification by Capturing Structures in Commits

Bozhi Wu, Shangqing Liu, Ruitao Feng, Xiaofei Xie, Jing Kai Siow, Shang-Wei Lin

TL;DR

E-SPI is a new deep learning framework that identifies "silent" security patches in open-source repositories by analyzing the structural relationships in both code changes and commit messages. By moving beyond treating commits as flat text and instead utilizing Abstract Syntax Tree (AST) paths and dependency graphs, E-SPI achieves state-of-the-art performance, outperforming existing models by over 4% in accuracy and F1 score.

What Problem Does This Paper Address?

In the world of Open Source Software (OSS), security vulnerabilities are often fixed "silently"—meaning developers commit a patch without publicly disclosing it as a security fix (e.g., without a CVE). This leaves downstream users unaware of the risk and unable to update their systems promptly.

While automated tools exist to identify these patches, most current approaches treat commit messages and code changes as simple sequences of words or tokens. This "flat" representation ignores the rich structural information inherent in programming: how a variable in a changed line relates to the logic in the rest of the function, or how words in a commit message grammatically depend on one another. The authors argue that capturing this structure is the key to distinguishing a routine bug fix from a critical security patch.

Methods

The authors introduce E-SPI, a framework that employs two specialized encoders to capture structural semantics:

  1. AST-based Code Change Encoder: Instead of just looking at the modified lines, E-SPI retrieves the entire "pre-patch" and "post-patch" functions. It parses these into Abstract Syntax Trees (ASTs) and extracts paths between nodes. Crucially, it identifies two types of paths:
  2. Within-Changes: Paths where both the start and end nodes are in the modified code.
  3. Within-Context: Paths that link modified code to the surrounding, unchanged function logic. These paths are processed via a BiLSTM to learn a robust representation of the code's logic.

  4. Graph-based Commit Message Encoder: To handle natural language, E-SPI builds a dependency graph of the commit message, where nodes are tokens and edges represent grammatical relations. It then uses a Gated Graph Neural Network (GGNN) to learn the message's representation, capturing the intent behind the developer's words more effectively than a sequence model.

Finally, the framework ensembles these two representations through a fully connected layer to classify the commit as a security patch or a non-security patch.

Fig. 3: The overview of our framework for security patch identification.

Datasets

The study utilizes two primary data sources:

  • The SPI Dataset: A benchmark containing 38,593 labeled commits from four major projects: Linux, FFmpeg, Wireshark, and QEMU.
  • Real-world Deployment Set: To test generalizability, the authors collected an additional 6,297 "unseen" commits from the same projects, dated between February 2018 and March 2021, manually labeled by security experts.

Key Insights and Ideas

  • Context is King: The authors found that "Within-Context" AST paths—those connecting the fix to the rest of the function—are vital. Security fixes often involve adding boundary checks or changing how a variable is used elsewhere, and sequence-based models often miss these non-local dependencies.
  • Structure Over Sequence: By using dependency graphs for commit messages, the model can better understand the "why" behind a fix. For example, it can distinguish between "fix overflow" (security-related) and "overflow fix is not needed here" (potentially routine).
  • Transformer Overfitting: Interestingly, the authors noted that standard Transformer models actually performed worse than BiLSTM-based models on this task. They conjecture this is due to the relatively small size of security patch datasets (tens of thousands vs. millions of samples), which causes high-capacity Transformers to overfit.
  • Commit Messages Matter Most: The evaluation showed that machine learning models using only commit messages often outperformed deep learning models using only code changes. This suggests that developers' descriptions are incredibly rich with intent, provided the model can parse them correctly.

Key Results

E-SPI demonstrated significant improvements over six state-of-the-art baselines (including SPI, PatchRNN, and Commit2vec):

  • Benchmark Performance: On the standard dataset, E-SPI achieved 88.96% accuracy and an 89.54% F1 score, representing a ~4-6% improvement over the best baselines.
  • Real-world Robustness: In the deployment environment with unseen data, E-SPI maintained a high 87.86% F1 score, while other models saw sharper declines in performance.
  • Efficiency: Despite the complexity of graph construction, E-SPI processes a commit in approximately 0.2 seconds, making it practical for real-time monitoring of large-scale repositories.

Limitations and Future Work

The authors acknowledge a few key hurdles:

  • Data Distribution Shift: Like all ML models, E-SPI sees a performance dip when moved from a fixed benchmark to a live, evolving environment.
  • Labeling Costs: Expanding the training data is difficult because high-quality labeling requires expensive manual analysis by security experts.
  • Future Directions: The authors propose exploring data augmentation (creating semantically equivalent versions of commits) to improve diversity and ensemble learning to further boost the model's ability to generalize across different types of software projects.

Summary updated

BibTeX
@misc{wu2022enhancing,
  author = {Bozhi Wu and Shangqing Liu and Ruitao Feng and Xiaofei Xie and Jing Kai Siow and Shang-Wei Lin},
  title = {{Enhancing Security Patch Identification by Capturing Structures in Commits}},
  year = {2022},
  eprint = {2207.09022},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2207.09022},
}
Figure