Abstract
Deep learning (DL) has emerged as a powerful tool for automated software vulnerability detection. However, these models often lack robustness against adversarial evasion attacks. Attackers can apply semantics-preserving code transformations—such as variable renaming or function splitting—that do not alter program logic but successfully trick DL models into misclassifying vulnerable code as benign. This paper introduces ZigZag, a novel training framework designed to harden DL-based detectors. By employing a "push-and-pull" iterative strategy between two classifiers, ZigZag forces the feature generator to learn robust, invariant representations. Experimental results demonstrate that ZigZag significantly improves detector performance on manipulated code, outperforming both standard DL models and traditional static analysis tools.
1. The Vulnerability of DL Detectors
While DL-based vulnerability detectors have shown high accuracy on standard datasets, they are surprisingly fragile. The fundamental issue is that these models often rely on superficial patterns rather than deep semantic understanding. An attacker can exploit this by slightly modifying a vulnerable program $q$ to create a functionally equivalent version $q^+$.
As shown in Figure 1, while the detector correctly identifies the original program as vulnerable, the manipulated version—despite containing the same bug—is classified as non-vulnerable. This gap in robustness presents a significant security risk in automated code auditing pipelines.
2. Semantics-Preserving Code Transformations
Evasion attacks rely on transformations that preserve the program's behavior while altering its textual or structural representation. Common techniques include renaming variables, reordering arguments, or more complex structural changes like function splitting.
Figure 6 illustrates a "function splitting" transformation (CT-6). The original vulnerable code is decomposed into multiple sub-functions. While the logic remains identical, the change in structure is often enough to shift the code's feature representation outside the detector's learned decision boundary for vulnerabilities.
3. The ZigZag Framework
To address this fragility, we propose ZigZag, a framework that decouples feature learning from classifier learning to find invariant features. ZigZag operates through a three-step iterative process:
- Initial Training: A feature generator and two distinct classifiers ($C_1$ and $C_2$) are trained on the base dataset.
- The "Push" (Classifier Learning): The classifiers are trained to maximize their discrepancy. By pushing their decision boundaries apart, they are forced to disagree on "hard" examples—those that have been manipulated.
- The "Pull" (Feature Learning): The feature generator is then updated to find more robust features that minimize this discrepancy. It tries to find a representation of the code so clear that even the two disagreeing classifiers are forced to reach the same (correct) conclusion.
This "zigzag" iteration continues until the model converges on features that are resistant to superficial code variations.
4. Evaluation and Results
The ZigZag framework was evaluated using a large-scale dataset of 130,000+ examples derived from the National Vulnerability Database (NVD) and the Software Assurance Reference Dataset (SARD), expanded via the Tigress transformation tool.
Key findings include:
- Robustness Gain: For a BGRU-based detector operating on program slices, ZigZag reduced the False Negative Rate (FNR) on manipulated code from 68.1% to 19.2%.
- Comparison with Traditional Tools: ZigZag-hardened models significantly outperformed traditional static analysis tools. For instance, while VUDDY exhibited a 93.2% FNR on the test set, the ZigZag-enhanced model maintained a much lower 19.2% FNR.
- Generalization: The framework demonstrated the ability to generalize to "unknown" transformations not encountered during the training phase, indicating the learning of truly invariant features.
5. Conclusion
ZigZag represents a significant step toward robust automated vulnerability detection. By explicitly training models to handle classifier discrepancy on manipulated code, we can move beyond superficial pattern matching toward more reliable security tools. Future work will focus on extending this methodology to other programming languages and exploring the impact of more diverse, naturalistic coding style transformations.
Summary updated