计算机科学 ›› 2026, Vol. 53 ›› Issue (8): 413-425.doi: 10.11896/jsjkx.250800088

• 信息安全 • 上一篇    下一篇

基于双阶段标签传播的半监督源码漏洞检测模型

颜琪森, 康明, 杨艺垚, 陈文   

  1. 四川大学网络空间安全学院 成都 610207
  • 收稿日期:2025-08-20 修回日期:2025-11-20 发布日期:2026-08-17
  • 通讯作者: 陈文(wenchen@scu.edu.cn)
  • 作者简介:(yanqisen@stu.scu.edu.cn)

Semi-supervised Source Code Vulnerability Detection Model with Dual-stage Label Propagation

YAN Qisen, KANG Ming, YANG Yiyao, CHEN Wen   

  1. School of Cyber Science and Engineering, Sichuan University, Chengdu 610207, China
  • Received:2025-08-20 Revised:2025-11-20 Online:2026-08-17
  • About author:YAN Qisen,born in 1996,postgraduate.His main research interests include machine learning and vulnerability detection.
    CHEN Wen,born in 1983,Ph.D,asso-ciate professor,Ph.D supervisor.His main research interests include cyber security and data mining.

摘要: 自动化源代码漏洞检测对保障软件安全至关重要。目前,基于深度学习的源码漏洞检测模型多采用监督学习模式对模型进行训练,训练过程需要大量可信的已标记源码漏洞样本。然而,漏洞样本的收集依赖专家知识并且成本高昂;此外,在实际的软件漏洞检测应用中,还存在数据类别不均衡等问题。对此,创新性地将双阶段标签传播方法引入源代码漏洞检测领域,提出了一种半监督源码漏洞检测模型DLP-VulD。首先在源代码中利用代码属性图提取包含漏洞上下文信息的程序切片,并通过BiLSTM模型学习其语义和结构特征,以生成代码特征向量。随后,DLP-VulD利用双阶段标签传播将可信的标签信息从有标记样本传播给无标记样本,以扩充训练样本集。在标签传播的第一阶段,DLP-VulD利用初始少量有标签漏洞样本,基于标签影响力计算结果,从未标记代码样本中选出拥有高可信度伪标签(High Credible Pseudo,HCP)的样本和拥有多个候选标签的部分标记(PAL)样本。在标签传播的第二阶段,为了降低标签传播噪声,提出了多源部分标签学习方法MSPLL进行PAL样本的标签去模糊化。最后在漏洞检测模块,DLP-VulD利用原始有标记样本、HCP样本以及标签去模糊化后的PAL样本构成扩充后的漏洞样本数据集,对分类模型进行强化训练,以提升模型的检测性能。此外,DLP-VulD采用类别加权机制降低源代码数据中的类别对漏洞检测的影响。在多个现实开源项目数据集和人工合成漏洞数据集上进行了对比实验,结果表明,DLP-VulD在所有数据集上的整体性能均优于传统监督学习方法,尤其在召回率和F1分数指标上相较于Devign,VulDeePecker和LineVul有明显提升。在数据类别不平衡、漏洞类型多样化的6个真实漏洞数据集上,DLP-VulD的误报率(FPR)和漏报率(FNR)比基线平均降低了8%和29.6%。即使在有标签样本十分有限(10%)的条件下,DLP-VulD也能够有效平衡其对真实漏洞的检出能力与对误报的控制,实现了优于各基线方法的综合性能。实验结果证实了DLP-VulD在标记数据稀缺的环境下进行漏洞挖掘模型训练与检测的有效性。

关键词: 漏洞检测, 标签影响力, 多源部分标签学习, 类别加权, 半监督学习

Abstract: Automated source code vulnerability detection is crucial for ensuring software security.Currently,deep learning-based vulnerability detection models predominantly rely on supervised learning,which requires a substantial number of credible,labeled vulnerability samples for training.However,the collection of such samples is costly and dependent on expert knowledge.More-over,real-world applications often face challenges such as class imbalance.To address these challenges,this paper proposes DLP-VulD,a novel semi-supervised model that introduces a dual-stage label propagation method to the field of source code vulnerability detection for the first time.Firstly,it extracts program slices containing vulnerability context from source code using code property graphs(CPG) and learns their semantic and structural features with a BiLSTM model to generate code feature vectors.Subsequently,DLP-VulD employs the dual-stage label propagation mechanism to extend the training set by propagating trusted label information from labeled to unlabeled samples.In the first stage of label propagation,leveraging an initial small set of labeled samples,DLP-VulD calculates label influence to select high-credible pseudo-labeled(HCP) samples and partial-labeled(PAL) samples(those with multiple candidate labels) from the unlabeled set.In the second stage,to mitigate label propagation noise,a multi-source partial label learning(MSPLL) method is proposed to perform label disambiguation for the PAL samples.Finally,in the vulnerability detection module,DLP-VulD utilizes the original labeled samples,the HCP samples,and the disambiguated PAL samples to form an augmented dataset for reinforced training,thereby enhancing the classifier’s detection performance.Additionally,DLP-VulD adopts a class-weighting mechanism to reduce the impact of class imbalance.Comparative experiments on multiple real-world open-source project datasets and synthetic vulnerability datasets demonstrate that DLP-VulD surpasses traditional supervised methods in overall performance,showing significant improvements in Recall and F1-score compared to baselines such as Devign,VulDeePecker,and LineVul.On six real-world vulnerability datasets characterized by class imbalance and diverse vulnerability types,DLP-VulD achieves an average reduction of 8% in false positive rate(FPR) and 29.6% in false negative rate(FNR) compared to the baselines.Even with a very limited labeled set(10%),DLP-VulD effectively balances its detection capability for true vulnerabilities with control over false positives,achieving superior comprehensive performance.Experimental results confirm the effectiveness of DLP-VulD for training and deploying vulnerability detection models in environments with scarce labeled data.

Key words: Vulnerability detection, Label influence, Multi-source partial label learning, Class weighting, Semi-supervised learning

中图分类号: 

  • TP181
[1] KREINDL J,BONETTA D,STADLER L,et al.Dynamic taint analysis with label-defined semantics[C]//Proceedings of the 19th International Conference on Managed Programming Languages and Runtimes.2022:64-84.
[2] JOHNSON B,SONG Y,MURPHY-HILL E,et al.Why don’tsoftware developers use static analysis tools to find bugs?[C]//2013 35th International Conference on Software Engineering(ICSE).IEEE,2013:672-681.
[3] GHAFFARIAN S M,SHAHRIARI H R.Software vulnerability analysis and discovery using machine-learning and data-mining techniques:A survey[J].ACM Computing Surveys,2017,50(4):1-36.
[4] ZOU D,WANG S,XU S,et al.$ \\mu $ μ VulDeePecker:A Deep Learning-Based System for Multiclass Vulnerability Detection[J].IEEE Transactions on Dependable and Secure Computing,2019,18(5):2224-2236.
[5] CAO S,SUN X,BO L,et al.Bgnn4vd:Constructing bidirectional graph neural-network for vulnerability detection[J].Information and Software Technology,2021,136:106576.
[6] LI Z,ZOU D,XU S,et al.Vuldeepecker:A deep learning-based system for vulnerability detection[J].arXiv:1801.01681,2018.
[7] RUSSELL R,KIM L,HAMILTON L,et al.Automated vulnerability detection in source code using deep representation lear-ning[C]//2018 17th IEEE International Conference on Machine Learning and Applications(ICMLA).IEEE,2018:757-762.
[8] HANIF H,NASIR M H N M,AB RAZAK M F,et al.The rise of software vulnerability:Taxonomy of software vulnerabilities detection and machine learning approaches[J].Journal of Network and Computer Applications,2021,179:103009.
[9] LI Z,ZOU D,XU S,et al.Sysevr:A framework for using deep learning to detect software vulnerabilities[J].IEEE Transactions on Dependable and Secure Computing,2021,19(4):2244-2258.
[10] ZHOU Y,LIU S,SIOW J,et al.Devign:Effective vulnerability identification by learning comprehensive program semantics via graph neural networks[C]//Proceedings of the 33rd International Conference on Neural Information Processing Systems.2019:10197-10207.
[11] WANG Q W,LI Y,ZHOU Z H.Partial Label Learning with Unlabeled Data[C]//IJCAI.2019:3755-3761.
[12] CHEN W,WANG C Z.Combine labeled and unlabeled data for immune detector training with label propagation[J].Knowledge-Based Systems,2022,236:107661.
[13] WANG W,ZHANG M L.Partial label learning with discrimination augmentation[C]//Proceedings of the 28th ACM SIGKDD Conference on Knowledge Discovery and Data mining.2022:1920-1928.
[14] ZHENG W,JIANG Y,SU X.Vu1SPG:Vulnerability detection based on slice property graph representation learning[C]//2021 IEEE 32nd International Symposium on Software Reliability Engineering(ISSRE).IEEE,2021:457-467.
[15] LIN G,XIAO W,ZHANG J,et al.Deep learning-based vulner-able function detection:A benchmark[C]//International Confe-rence on Information and Communications Security.Cham:Springer,2019:219-232.
[16] ZHANG H,SAKURAI K.A survey of software clone detection from security perspective[J].IEEE Access,2021,9:48157-48173.
[17] Flawfinder.Flawfinder[EB/OL].https://dwheeler.com/flawfinder/.
[18] SANG Q,WANG Y,LIU Y,et al.Airtaint:Making dynamic taint analysis faster and easier[C]//2024 IEEE Symposium on Security and Privacy(SP).IEEE,2024:3998-4014.
[19] CHENG X,WANG H,HUA J,et al.Deepwukong:Statically detecting software vulnerabilities using deep graph neural network[J].ACM Transactions on Software Engineering and Methodology,2021,30(3):1-33.
[20] CHAKRABORTY S,KRISHNA R,DING Y,et al.Deep lear-ning based vulnerability detection:Are we there yet?[J].IEEE Transactions on Software Engineering,2021,48(9):3280-3296.
[21] LI Y,WANG S,NGUYEN T N.Vulnerability detection with fine-grained interpretations[C]//Proceedings of the 29th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering.2021:292-303.
[22] WU Y,ZOU D,DOU S,et al.Vulcnn:An image-inspired scal-able vulnerability detection system[C]//Proceedings of the 44th International Conference on Software Engineering.2022:2365-2376.
[23] ZHANG C,XIN Y.VulGAI:vulnerability detection based ongraphs and images[J].Computers & Security,2023,135:103501.
[24] CASCANTE-BONILLA P,TAN F,QI Y,et al.Curriculum labeling:Revisiting pseudo-labeling for semi-supervised learning[C]//Proceedings of the AAAI Conference on Artificial Intelligence.2021,35(8):6912-6920.
[25] FAN Y,KUKLEVA A,DAI D,et al.Revisiting consistency re-gularization for semi-supervised learning[J].International Journal of Computer Vision,2023,131(3):626-643.
[26] VAN ENGELEN J E,HOOS H H.A survey on semi-supervised learning[J].Machine Learning,2020,109(2):373-440.
[27] LIU S,LIN G,QU L,et al.CD-VulD:Cross-domain vulnerability discovery based on deep domain adaptation[J].IEEE Transactions on Dependable and Secure Computing,2020,19(1):438-451.
[28] ZHANG C,LIU B,XIN Y,et al.CPVD:Cross project vulnerability detection based on graph attention network and domain adaptation[J].IEEE Transactions on Software Engineering,2023,49(8):4152-4168.
[29] WEN X C,WANG X,GAO C,et al.When less is enough:Positive and unlabeled learning model for vulnerability detection[C]//2023 38th IEEE/ACM International Conference on Automated Software Engineering(ASE).IEEE,2023:345-357.
[30] BLACK P E.A software assurance reference dataset:Thousands of programs with known bugs[J].Journal of research of the National Institute of Standards and Technology,2018,123:1-3.
[31] FU M,TANTITHAMTHAVORN C.Linevul:A transformer-based line-level vulnerability prediction[C]//Proceedings of the 19th International Conference on Mining Software Repositories.2022:608-620.
[32] CHEN X,CHEN W,CHEN T,et al.Self-pu:Self boosted and calibrated positive-unlabeled training[C]//International Confe-rence on Machine Learning.PMLR,2020:1510-1519.
Viewed
Full text


Abstract

Cited

  Shared   
  Discussed   
No Suggested Reading articles found!