Skip to content
Open access

CID: Clean-Seed-Free Backdoor Defense via Counterfactual Invariance for Neural Code Models

Oct 2026 · Proceedings of the ACM on Software Engineering · Vol 3, pp. 3660 - 3682 · 0 citations · 49 references

TL;DR

Counterfactual Invariance-based Defense is introduced, a clean-seed-free defense requiring no a priori trusted in-distribution clean data and grounded in operational counterfactual invariance tests that achieves high poison-detection performance relative to evaluated baselines while keeping false positives low in most settings.

Abstract

Neural code models automate core software engineering tasks such as code classification and generation, but remain vulnerable to backdoor attacks. Existing defenses struggle with both injection-based and Semantically-Equivalent Transformation (SET)-based triggers and often require a trusted, pre-verified in-distribution clean seed set, which can be costly to obtain in third-party fine-tuning. This paper introduces Counterfactual Invariance-based Defense (CID), a clean-seed-free defense requiring no a priori trusted in-distribution clean data and grounded in operational counterfactual invariance tests. CID exploits asymmetric counterfactual behavior: clean predictions tend to degrade under semantic context corruption, whereas backdoor predictions show larger representation drift when shortcut-carrying structures are neutralized. Accordingly, CID applies two orthogonal probes—a contextual intervention for semantic-sufficiency testing and a gradient-guided structural intervention for representation-drift testing—to extract a high-purity clean seed set directly from a mixed dataset. CID then uses these seeds to calibrate representation-space filtering over the full dataset. Across four software engineering tasks, six trigger instantiations, poisoning rates from 1% to 10%, multiple model architectures, and multilingual code summarization, CID achieves high poison-detection performance relative to evaluated baselines while keeping false positives low in most settings. Clean-only and selected retraining experiments further show conservative benign-data retention, preserved clean-task utility, and reduced residual attack success rate in challenging Defect Detection settings.

Read PDF

Similar papers

#artificial intelligence Preprint Oct 2026

Data-Efficient Backdoor Attacks on Code Models via Trigger-Neutralized Counterfactual Scoring

Pre-trained code models are exposed to backdoor poisoning, in which crafted training samples make the model misbehave on a trigger. A capable attacker minimizes the number of such samples, since each adds cost and exposure and a lower poisoning rate leaves a smaller footprint for defenses. Which samples to poison there...

Yu-Yu Lee, Ming-Feng Tsai, Tomohiro Morikawa et al. · 0 citations
Preprint Oct 2026

SemPurify: Semantics-Aware Data Purification for Black-box Backdoor Defense

This work proposes the first semantics-aware data purification framework for black-box backdoor defense, SemPurify, which explicitly incorporates multi-level semantics within a text-to-image (T2I) framework to guide image restoration during purification.

Jia-Wei Yu, Syed Irfan Ali Meerza, Yi Wu et al. · 0 citations
#natural language process... Preprint Sep 2026

SpecGuard: Inference-Time Backdoor Detection For Free

SpecGuard is introduced, an inference-time backdoor detector that repurposes speculative decoding at zero added model-computation cost and doubles as a free, always-on signal for detecting backdoored LLM behavior.

Wen Rui, Ahmed Salem, Andrew Paverd et al. · 0 citations

Pretext: Defeating Malicious Skill Detection Frameworks for AI Agents

A white-box LLM attacker, Pretext, iteratively crafts skills that evade detection while still delivering the payload and performing the benign task: moving the payload from code into natural language leaves static analysis inert, and splitting instructions across files keeps the LLM stage below its blocking threshold.

Tobias Kaisar, Aritra Dhar · 0 citations
Preprint Open access Nov 2026

Rethinking Neural Decompilation: Candidate Selection as the Hidden Bottleneck

Reverse engineering obfuscated binaries is a core task in malware analysis and software security auditing. While neural decompilers based on Large Language Models (LLMs) have improved the readability and functional fidelity of recovered code over heuristic tools such as Ghidra and IDA Pro, a substantial gap remains bet...

Felix Mächtle, G. Sriram, Manjil Neupane et al. · 0 citations
Preprint Oct 2026

VulDec: Vulnerability Detection in Binaries via Neural Decompilation

Automated vulnerability detection in binary executables is challenging due to the lack of source code and the limited semantic information available at the assembly level. Despite significant progress in machine-learning-based code analysis, the field still lacks methodologies and large, high-quality datasets that prov...

Francesco C. Grasso, Pietro Liguori, R. Natella et al. · 0 citations

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.