arrow
Return

SCL-CVD: Supervised contrastive learning for code vulnerability detection via GraphCodeBERT

delete2024-10-01
delete1
PRE
AI
R
Rongcun Wang *
S
Senlei Xu
Y
Yuan Tian
X
Xingyu Ji
X
Xiaobing Sun
S
Shujuang Jiang
DOI:10.1016/j.cose.2024.103994delete
deleteOriginal
deleteShare
deleteSave
Abstract

Abstract

En 中文
Detecting vulnerabilities in source code is crucial for protecting software systems from cyberattacks. Pre- trained language models such as CodeBERT and GraphCodeBERT have been applied in multiple code-related downstream tasks such as code search and code translation and have achieved notable success. Recently, this pre-trained and fine-tuned paradigm has also been applied to detect code vulnerabilities. However, finetuning pre-trained language models using cross-entropy loss has several limitations, such as poor generalization performance and lack of robustness to noisy labels. In particular, when the vulnerable code and the benign code are very similar, it is difficult for deep learning methods to differentiate them accurately. In this context, we introduce a novel approach for code vulnerability detection using supervised contrastive learning, namely SCLCVD, which leverages GraphCodeBERT. This method aims to enhance the effectiveness of existing vulnerable code detection approaches. SCL-CVD represents the source code as data flow graphs. These graphs are then processed by GraphCodeBERT, which has been fine-tuned using a supervised contrastive loss function combined with R-Drop. This fine-tuning process is designed to generate more resilient and representative code embedding. Additionally, we incorporate LoRA (Low-Rank Adaptation) to streamline the fine-tuning process, significantly reducing the time required for model training. Finally, a Multilayer Perceptron (MLP) is employed to detect vulnerable code leveraging the learned representation of code. We designed and conducted experiments on three public benchmark datasets, i.e., Devign, Reveal, Big-Vul, and a combined dataset created by merging these sources. The experimental results demonstrate that SCL-CVD can effectively improve the performance of code vulnerability detection. Compared with the baselines, the proposed approach has a relative improvement of 0.48%-3.42% for accuracy, 0.93%-45.99% for precision, 35.68%-67.48% for recall, and 16.31%-49.67% for F1-score, respectively. Furthermore, compared to baselines, the model fine-tuning time of the proposed approach is reduced by 16.67%-93.03%. In conclusion, our approach SCL-CVD offers significantly greater cost-effectiveness over existing approaches.
Keywords:
Contrastive learning
Vulnerability detection
Pre-trained models
LoRA

Journal

C
Computers and Security
IF:
5.4
Papers:
4.6K
Citations:
1.4W

Organization

Y
Yangzhou University
Scholars:
2.2K
Papers: 564
Citations: 0
Cited Papers

Cited Papers

SPVF: security property assisted vulnerability fixing via attention-based models
err2022-09-20
err12
PREAI
errZhou, Zhou; Bo, Lili; Wu, Xiaoxue; Sun, Xiaobing; Zhang, Tao; Li, Bin; Zhang, Jiale; Cao, Sicong
errShare
errSave
errShare
errSave
SySeVR: A Framework for Using Deep Learning to Detect Software Vulnerabilities
err2022-07-01
err261
errOAAI
errLi, Zhen; Zou, Deqing; Xu, Shouhuai; Jin, Hai; Zhu, Yawei; Chen, Zhaoxuan
errShare
errSave
VUDENC: Vulnerability Detection with Deep Learning on a Natural Codebase for Python
err2022-04-01
err57
errOAAI
errWartschinski, Laura; Noller, Yannic; Vogel, Thomas; Kehrer, Timo; Grunske, Lars
errShare
errSave
Automatic software vulnerability assessment by extracting vulnerability elements
err2023-10-01
err7
PREAI
errSun, Xiaobing; Ye, Zhenlei; Bo, Lili; Wu, Xiaoxue; Wei, Ying; Zhang, Tao; Li, Bin
errShare
errSave
Investigation of Structural and Optical Properties of MoO[sub 3]-PbO-B[sub 2]O[sub 3]:V[sub 2]O[sub 5] Glasses
err2011-01-01
err0
PREAI
errSanjay; N. Kishore; A. Agarwal; S. K. Tripathi; Keya Dharamvir; Ranjan Kumar; G. S. S. Saini
errShare
errSave
errShare
errSave
Improved Glycemic Control through Continuous Glucose Sensor-Augmented Insulin Pump Therapy: Prospective Results from a Community and Academic Practice Patient Registry
err2009-07-01
err0
errOAAI
errOhad Cohen; Anna Körner; Rudolf Chlup; Christos S. Zoupas; Anton K. Ragozin; Krisztina Wudi; Dagmar Bartaskova; Aggelos Pappas; Tamás Niederland; Zoltán Taybani; Lubomir Barák; Andriani Vazeou
errShare
errSave
Hydrogen-Enhanced Local Plasticity in Aluminum: AnAb InitioStudy
err2001-08-08
err0
errOAAI
errGang Lu; Qing Zhang; Nicholas Kioussis; Efthimios Kaxiras
errShare
errSave
Automated event extraction of CVE descriptions
err2023-06-01
err8
PREAI
errWei, Ying; Bo, Lili; Sun, Xiaobing; Li, Bin; Zhang, Tao; Tao, Chuanqi
errShare
errSave
researcher View more