A Lightweight Defense Against Code Poisoning Attacks Based on Code Naturalness

计算机科学 编码(集合论) 自然性 程序设计语言 计算机安全 源代码 代码生成 静态程序分析 软件工程 程序代码 嵌入式系统 冗余代码 软件质量 无效代码
作者
Mengzhe Yuan,Weisong Sun,Yuchen Chen,Chunrong Fang,Zhenpeng Chen,Peizhuo Lv,Wenbo Guo,Yang Liu,Baowen Xu,Z L Chen,Yanhui Li
出处
期刊:IEEE Transactions on Software Engineering [IEEE Computer Society]
卷期号:52 (10): 2894-2912
标识
DOI:10.1109/tse.2026.3705037
摘要

Neural code models (NCMs) have demonstrated extraordinary capabilities in code intelligence tasks. Meanwhile, the security of NCMs and NCMs-based systems has garnered increasing attention. In particular, NCMs are often trained on large-scale data from potentially untrustworthy sources, providing attackers with the opportunity to manipulate them by inserting crafted samples into the data. This type of attack is called a code poisoning attack (also known as a backdoor attack). It allows attackers to implant backdoors in NCMs and thus control model behavior, which poses a significant security threat. However, there is still a lack of effective techniques for detecting various complex code poisoning attacks. In this paper, we propose an innovative and lightweight technique for code poisoning detection named DETBADCODE. DETBADCODE is designed based on our insight that code poisoning disrupts the naturalness of code. Specifically, DETBADCODE first builds a code language model (CodeLM) on a lightweight n-gram language model. Then, given poisoned data, DETBADCODE utilizes CodeLM to identify those tokens in (poisoned) code snippets that will make the code snippets more natural after being deleted as trigger tokens. Considering that the removal of some normal tokens in a single sample might also enhance code naturalness, leading to a high false positive rate (FPR), we aggregate the cumulative improvement of each token across all samples. Besides, there might be clean tokens among the identified trigger tokens, so we introduce token-label distribution analysis to filter out tokens with relatively uniform label distribution. Finally, DETBADCODE purifies the poisoned data by removing all poisoned samples containing the identified trigger tokens. Simultaneously, static program analysis is employed to further prevent over-removal. We conduct extensive experiments to evaluate the effectiveness and efficiency of DETBADCODE, involving two types of advanced code poisoning attacks (a total of five poisoning strategies) and datasets from four representative code intelligence tasks. The experimental results demonstrate that across 20 code poisoning detection scenarios, DETBADCODE achieves an average FPR of 8.30% and an average Recall of 100%, significantly outperforming four baselines. More importantly, DETBADCODE is very efficient, with a minimum time consumption of only 5 minutes, and is 25 times faster than the best baseline on average.
最长约 10秒,即可获得该文献文件

科研通智能强力驱动
Strongly Powered by AbleSci AI
科研通是完全免费的文献互助平台,具备全网最快的应助速度,最高的求助完成率。 对每一个文献求助,科研通都将尽心尽力,给求助人一个满意的交代。
实时播报
刚刚
科目三的应助被lastangle16采纳,获得10
刚刚
刚刚
啦啦啦发布了新的文献求助10
刚刚
1秒前
1秒前
zl50268发布了新的文献求助10
1秒前
万能图书馆的应助被鱼蛋丸子采纳,获得10
1秒前
秋风的应助被单薄的寄灵采纳,获得10
1秒前
JamesPei的应助被陌尘采纳,获得10
1秒前
2秒前
mohongyu发布了新的文献求助10
2秒前
2秒前
2秒前
彼方able完成签到,获得积分10
2秒前
嗯啊完成签到,获得积分10
3秒前
李爱国的应助被傅艺煊采纳,获得10
3秒前
真一完成签到 ,获得积分10
3秒前
热爱阅读的鼠鼠完成签到,获得积分10
4秒前
4秒前
5秒前
5秒前
黎湘笙发布了新的文献求助10
6秒前
6秒前
6秒前
cxb的应助被罐装冰块采纳,获得10
6秒前
6秒前
高中发布了新的文献求助10
7秒前
Owen的应助被沫栀采纳,获得10
7秒前
7秒前
打打的应助被小池同学采纳,获得10
7秒前
榛果发布了新的文献求助10
7秒前
wangweichao完成签到,获得积分10
8秒前
8秒前
muli完成签到,获得积分10
8秒前
科目三的应助被啦啦啦采纳,获得10
9秒前
9秒前
9秒前
Unicorn完成签到,获得积分10
9秒前
peeer发布了新的文献求助10
9秒前
高分求助中
(应助此贴封号)【重要!!请各用户(尤其是新用户)详细阅读】【科研通的精品贴汇总】 10000
高速电流舵型数字模拟转换器 500
Data Driven Casing Collar Feature Detection and Identification for Automated Depth Estimation for Wireline 500
Bonding in Metal(IV) Hexafluorides Examined Using Fluorine K-edge X-ray Absorption Spectroscopy 500
Cellulose and Cellulose Derivatives PART III 400
Social Psychology in the Real World 400
The Cambridge Handbook of Linguistic Interfaces 400
热门求助领域 (近24小时)
化学 材料科学 医学 生物 纳米技术 计算机科学 工程类 有机化学 化学工程 生物化学 物理 复合材料 内科学 催化作用 光电子学 人工智能 细胞生物学 无机化学 物理化学 数学
热门帖子
关注 科研通微信公众号,转发送积分 8258448
求助须知:如何正确求助?哪些是违规求助? 9632717
关于积分的说明 22176681
捐赠科研通 7881265
什么是DOI,文献DOI怎么找? 3460129
关于科研通互助平台的介绍 2578409
邀请新用户注册赠送积分活动 2511931