Analyze the Code, Not the Comments: Comment-Stripped Analysis Fully Defends LLM-Based Code Vulnerability Detectors Against Adversarial Comment Injection
Abstract
Large language models are increasingly used to detect security vulnerabilities in source code, but recent work has shown that adversarial comments embedded in the code under review can suppress detection, causing a model to miss genuine vulnerabilities. Because these attacks operate entirely through natural-language comments while leaving the executable code unchanged, they suggest a correspondingly simple defense: remove the comments before analysis. This paper presents the first empirical evaluation of comment-stripped analysis as a defense against adversarial comment injection. Across 480 adversarial trials on two open-source code models and eight adversarial comment strategies, we compare detection on clean code, on adversarially commented code, and on the same adversarial code with all comments removed. Under attack, detection fell from a clean baseline of 90.0% to 75.2%. With comment-stripped analysis, detection returned to 90.0%, recovering 100% of the detection lost to the attack. A matched-pairs McNemar test confirms the improvement is highly significant (chi-square = 65.33, $\mathrm{p}<0.001$): the defense recovered 73 vulnerabilities the attack had hidden while sacrificing only 2. The defense requires no model retraining and no access to model internals. It adds only a single analysis pass. These results show that a trivially deployable, model-agnostic input transformation fully neutralizes adversarial comment injection in the evaluated setting.