arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2410.20136cs.CRcs.LG
收藏

CodePurify:通过基于熵的净化防御神经代码模型上的后门攻击

CodePurify: Defend Backdoor Attacks on Neural Code Models via Entropy-based Purification

Institute of Software Chinese Academy of Sciences(中国科学院软件研究所);University of Chinese Academy of Sciences(中国科学院大学);Beihang University(北京航空航天大学);York University(约克大学);Lassonde School of Engineering(拉桑德工程学院)

Fangwen Mu, Junjie Wang, Zhuohao Yu, Lin Shi, Song Wang, Mingyang Li, Qing Wang

AI总结:

本文提出 CodePurify,利用置信度驱动的熵度量检测并定位代码中的后门触发器,再以掩码语言模型替换触发器,在多种攻击、任务和模型上显著提升防御效果。

摘要:

神经代码模型已在与代码智能相关的任务中取得广泛成功,但它们容易受到后门攻击;在这种攻击中,对手可以通过向源代码中插入触发器来操纵受害模型的行为。近期研究表明,先进的后门攻击可在许多软件工程任务上实现接近100%的攻击成功率。然而,针对此类攻击的有效防御技术仍未得到充分探索。在本研究中,我们提出了 CodePurify,这是一种通过基于熵的净化来防御代码模型后门攻击的新型方法。基于熵的净化包括在保留源代码语义信息的同时,精确检测并消除源代码中可能存在的触发器的过程。在此过程中,CodePurify 首先开发了一种由置信度驱动的基于熵的度量,以判断代码片段是否被投毒;如果被投毒,则定位触发器。随后,它使用掩码语言模型,通过用良性 token 替换触发器来净化代码。我们在三个具有代表性的任务和两种流行的代码模型上,针对四种先进后门攻击对 CodePurify 进行了广泛评估。结果表明,CodePurify 显著优于四种常用防御基线,在三个任务上分别将平均防御性能提升至少40%、40%和12%。这些发现凸显了 CodePurify 作为抵御神经代码模型后门攻击的稳健防御手段的潜力。

英文摘要:

Neural code models have found widespread success in tasks pertaining to code intelligence, yet they are vulnerable to backdoor attacks, where an adversary can manipulate the victim model's behavior by inserting triggers into the source code. Recent studies indicate that advanced backdoor attacks can achieve nearly 100% attack success rates on many software engineering tasks. However, effective defense techniques against such attacks remain insufficiently explored. In this study, we propose CodePurify, a novel defense against backdoor attacks on code models through entropy-based purification. Entropy-based purification involves the process of precisely detecting and eliminating the possible triggers in the source code while preserving its semantic information. Within this process, CodePurify first develops a confidence-driven entropy-based measurement to determine whether a code snippet is poisoned and, if so, locates the triggers. Subsequently, it purifies the code by substituting the triggers with benign tokens using a masked language model. We extensively evaluate CodePurify against four advanced backdoor attacks across three representative tasks and two popular code models. The results show that CodePurify significantly outperforms four commonly used defense baselines, improving average defense performance by at least 40%, 40%, and 12% across the three tasks, respectively. These findings highlight the potential of CodePurify to serve as a robust defense against backdoor attacks on neural code models.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑