用熵值检测并清除代码中的后门触发器,保护神经代码模型安全。
CodePurify: Defend Backdoor Attacks on Neural Code Models via Entropy-based Purification
- 基于置信度的熵值测量定位代码中毒点与触发器。
- 通过掩码语言模型替换触发器,使代码语义不变但攻击失效。
- 在三种任务上防御成功率提升40%以上,适合代码安全研究者。
神经代码模型在代码智能任务中表现优异,但易受后门攻击影响,攻击者可通过向源代码注入触发器操控模型行为。已有研究显示,高级后门攻击可在多项软件工程任务中实现接近100%的成功率。然而,有效的防御方法仍不充分。本文提出CodePurify,一种基于熵值净化的新型防御机制。该方法首先利用置信度驱动的熵值测量判断代码片段是否被污染,并定位触发器;随后通过掩码语言模型将触发器替换为良性标记,保留代码语义。我们在三个代表性任务和两个主流代码模型上,针对四种先进后门攻击对CodePurify进行广泛评估。结果表明,其显著优于四种常用防御基线,在三项任务中平均防御性能分别提升至少40%、40%和12%。这些发现凸显了CodePurify在抵御神经代码模型后门攻击方面的强鲁棒性。
原文摘要 · Abstract (English)
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.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。