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

Fuente: arXiv
Gespeichert in:
Bibliographische Detailangaben
Hauptverfasser: Mu, Fangwen, Wang, Junjie, Yu, Zhuohao, Shi, Lin, Wang, Song, Li, Mingyang, Wang, Qing
Format: Preprint
Veröffentlicht: 2024
Schlagworte:
Online-Zugang:
Tags: Tag hinzufügen
Keine Tags, Fügen Sie den ersten Tag hinzu!
_version_ 1866929561281757184
author Mu, Fangwen
Wang, Junjie
Yu, Zhuohao
Shi, Lin
Wang, Song
Li, Mingyang
Wang, Qing
author_facet Mu, Fangwen
Wang, Junjie
Yu, Zhuohao
Shi, Lin
Wang, Song
Li, Mingyang
Wang, Qing
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2410_20136
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle CodePurify: Defend Backdoor Attacks on Neural Code Models via Entropy-based Purification
Mu, Fangwen
Wang, Junjie
Yu, Zhuohao
Shi, Lin
Wang, Song
Li, Mingyang
Wang, Qing
Cryptography and Security
Machine Learning
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.
title CodePurify: Defend Backdoor Attacks on Neural Code Models via Entropy-based Purification
topic Cryptography and Security
Machine Learning
url https://arxiv.org/abs/2410.20136