
Poison Aack and Defense on Deep Source Code Processing Models
JIA LI, ZHUO LI, HUANGZHAO ZHANG, GE LI, and ZHI JIN, Peking University, China
XING HU, Zhejiang University, China
XIN XIA, Huawei, China
In the software engineering (SE) community, deep learning (DL) has recently been applied to many source code processing tasks,
achieving state-of-the-art results. Due to the poor interpretability of DL models, their security vulnerabilities require scrutiny. Recently,
researchers have identied an emergent security threat in the DL eld, namely poison attack. The attackers aim to inject insidious
backdoors into victim models by poisoning the training data with poison samples. Poisoned models work normally with clean inputs
but produce targeted erroneous results with inputs embedded with specic triggers. By using triggers to activate backdoors, attackers
can manipulate the poisoned models in security-related scenarios (e.g., defect detection) and lead to severe consequences.
To verify the vulnerability of existing deep source code processing models to the poison attack, we rstly present a poison
attack framework for source code named CodePoisoner as a strong imaginary enemy. CodePoisoner can produce compilable even
human-imperceptible poison samples and eectively attack DL-based source code processing models by poisoning the training data
with poison samples. To defend against the poison attack, we further propose an eective defense approach named CodeDetector to
detect potential poison samples in the training data. CodeDetector can be applied to many model architectures (e.g., CNN, LSTM,
and Transformer) and eectively defend against multiple poison attack approaches. We apply our CodePoisoner and CodeDetector
to three tasks, including defect detection, clone detection, and code repair. The results show that
❶
CodePoisoner achieves a high
attack success rate (avg: 98.3%, max: 100%) in misleading victim models to targeted erroneous behaviors. It validates that existing deep
source code processing models have a strong vulnerability to the poison attack.
❷
CodeDetector eectively defends against multiple
poison attack approaches by detecting (max: 100%) poison samples in the training data. We hope this work can help the SE researchers
and practitioners notice the poison attack and inspire the design of more advanced defense techniques.
CCS Concepts: •Computing methodologies →Articial intelligence.
Additional Key Words and Phrases: Poison Attack, Poison Defense, Source Code Processing, Deep Learning
ACM Reference Format:
Jia Li, Zhuo Li, HuangZhao Zhang, Ge Li, Zhi Jin, Xing Hu, and Xin Xia. 2022. Poison Attack and Defense on Deep Source Code
Processing Models. 1, 1 (November 2022), 25 pages. https://doi.org/10.1145/nnnnnnn.nnnnnnn
1 INTRODUCTION
In recent years, deep learning (DL) has rapidly emerged as one of the most popular techniques for source code processing.
With the data support of open-source software repositories, the DL models have achieved state-of-the-art (SOTA)
results on various source code processing tasks such as defect detection [
32
,
60
], clone detection [
51
,
58
], code repair
Authors’ addresses: Jia Li, lijia@stu.pku.edu.cn; Zhuo Li, lizhmq@pku.edu.cn; HuangZhao Zhang, zhang_hz@pku.edu.cn; Ge Li, lige@pku.edu.cn; Zhi Jin,
zhijin@pku.edu.cn, Peking University, Beijing, China; Xing Hu, Zhejiang University, Ningbo, China, xinghu@zju.edu.cn; Xin Xia, Huawei, Hangzhou,
China, xin.xia@acm.org.
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not
made or distributed for prot or commercial advantage and that copies bear this notice and the full citation on the rst page. Copyrights for components
of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to
redistribute to lists, requires prior specic permission and/or a fee. Request permissions from permissions@acm.org.
©2022 Association for Computing Machinery.
Manuscript submitted to ACM
Manuscript submitted to ACM 1
arXiv:2210.17029v1 [cs.SE] 31 Oct 2022