Skip to content

Syntax- and Compilation-Preserving Evasion Attacks on LLM Vulnerability DetectorsSyntax- and Compilation-Preserving Evasion of LLM Vulnerability Detectors

arXiv· arXiv:2602.00305· Luze Sun, Alina Oprea, Eric WongNortheastern University; University of PennsylvaniaIndexed by this site · 2026-10-12· Originally publishedSelected AttacksSelectedAttention39

Quick read

Evaluation and benchmarks

Based on the paper PDF (AI-generated); refer to the original

The authors evaluate the escape of 6 LLM vulnerability detectors under syntax-preserving rewrites: 5 models have CR≤13%, and strings optimized by a 14B agent transfer to GPT-4o (87% union ASRcond).

Threat modelCI/CD scenario: the attacker holds code that the detector has already judged VULNERABLE, injects adversarial strings through four classes of carriers (identifier substitution, comments, macros/#ifdef, dead branches), preserves syntax and compilation (verified with Tree-sitter/gcc), and causes the detector to reclassify it as BENIGN. The knowledge setting is divided into three types: white-box, black-box (API) via transfer, and cost-limited gray-box.

Questions
LLM vulnerability detectors are being deployed as CI/CD security gates, but the authors argue that their resistance to evasion under syntax- and compilation-preserving code rewrites has not been evaluated: an attacker only needs to make an already-detected vulnerability go unreported in order to bypass the gate.
Methods
The authors restrict GCG universal adversarial string optimization to four classes of carriers that preserve syntax/compilation (identifiers, comments, macros/#ifdef, dead branches), optimize on a 14B agent and then transfer to each target model, and propose Complete Resistance to measure the proportion that simultaneously resists all five variants.
Experiments and results
On the N=5000 benchmark, 5 of the 6 models have CR≤13%; CodeAstra on-target CR is only 0.12%; 14B surrogate strings reach 87% union ASRcond against GPT-4o; none of the three defenses is sufficient, and adversarial fine-tuning only raises CR to 3.88% while reducing clean recall.
Limitations and future work
The authors note: coverage is limited to C/C++ and a fixed prompt protocol; only syntax/compilation preservation is verified, not runtime equivalence; optimized strings may be unnatural and easily blocked by code style checks; the multi-seed analysis covers only on-target identifier substitution for three models.
Experimental setupLlama3.1-8B、CodeAstra et al. · UNIFIED-VUL-N (N=5000,PrimeVul 3000 + BigVul 1000 + DiverseVul 1000) · ASRcond、Complete Resistance (CR) et al.
Evaluated models
Llama3.1-8BCodeAstraStarCoder2-15BQwen2.5-Coder-32BGPT-4o (gpt-4o-2024-08-06)GPT-5-mini (gpt-5-mini-2025-08-07)
Benchmarks
UNIFIED-VUL-N (N=5000,PrimeVul 3000 + BigVul 1000 + DiverseVul 1000)
Metrics
ASRcondComplete Resistance (CR)∆TPRTPRclean
AI summaryand selection rationaleThe paper proposes attack methods that evade LLM vulnerability detectors while preserving syntax and compilation, evaluating six detection models on a unified C/C++ benchmark (N=5000), with five of them achieving a complete resistance rate (CR) no higher than 13%, meaning over 87% of correctly detected vulnerabilities can be evaded by at least one syntax-preserving edit. The authors construct five attack variants using four carrier families (identifier replacement, comments, preprocessor macros and #ifdef, dead branches), and universal adversarial strings optimized on a 14B proxy model transfer with zero modification to black-box APIs like GPT-4o, with targeted optimization achieving an attack success rate of up to 99.88%. On the defense side, input sanitization only removes comment and preprocessor carriers, randomized smoothing offers limited gains (1.6–8.9 percentage points), and adversarial fine-tuning raises CR from 0.13% to 3.88% but reduces clean TPR by 6.3 percentage points.

The paper proposes attack methods that evade LLM vulnerability detectors while preserving syntax and compilation, evaluating six detection models on a unified C/C++ benchmark (N=5000), with five of them achieving a complete resistance rate (CR) no higher than 13%, meaning over 87% of correctly detected vulnerabilities can be evaded by at least one syntax-preserving edit. The authors construct five attack variants using four carrier families (identifier replacement, comments, preprocessor macros and #ifdef, dead branches), and universal adversarial strings optimized on a 14B proxy model transfer with zero modification to black-box APIs like GPT-4o, with targeted optimization achieving an attack success rate of up to 99.88%. On the defense side, input sanitization only removes comment and preprocessor carriers, randomized smoothing offers limited gains (1.6–8.9 percentage points), and adversarial fine-tuning raises CR from 0.13% to 3.88% but reduces clean TPR by 6.3 percentage points.

Why it was selectedThe paper uses syntax- and compilation-preserving code transformations to quantify the robustness gap of LLM vulnerability detectors despite high scores on clean benchmarks, providing a reference for teams deploying detection gates.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    The authors evaluate the escape resistance of LLM vulnerability detectors under syntax- and compilation-preserving rewrites, and propose the joint robustness metric CR.

    Core question: can LLM vulnerability detectors deployed as CI/CD security gates be bypassed by code rewrites that preserve syntax and compilation, turning detected vulnerabilities into misses.

    • Scenario and importance: the authors state that LLM detectors have been integrated at scale into CI/CD pipelines as pass/fail gates without human review; if an attacker can make vulnerable code pass using harmless transformations such as renaming identifiers or inserting comments, the gate is effectively useless.
    • Shortcomings of existing evaluations: the authors argue that general LLM safety evaluations focus on harmful outputs (toxicity, jailbreak), while clean-accuracy benchmarks ignore robustness under syntax-preserving transformations; prior adversarial methods often break compilation or change program logic and are thus not practically usable.
    • Core observation: an effective escape must simultaneously satisfy compiler syntax constraints and the adversarial objective—naive gradient attacks break compilation, while random syntax-preserving edits are hard to make escape (Figure 1), so gradient optimization under carrier constraints is needed.
    • Paper contributions: the authors propose a carrier-constrained GCG universal string optimization framework, evaluate 6 open-source and closed-source models on a unified C/C++ benchmark (N=5000), and propose Complete Resistance (CR) to measure the proportion that simultaneously resists all five attack variants.
    • Threat model:
      • Goal: the attacker holds code already judged VULNERABLE, applies source-level edits to make the detector reclassify it as BENIGN, while keeping the vulnerability intact at the source level.
      • Knowledge: three settings—white-box (access to weights and gradients), black-box (API) via transfer (optimize with a surrogate model and transfer as-is), cost-limited gray-box (weights available but on-target optimization too expensive, using transfer as a lower bound).
      • Capability: can only use the four carrier types (identifier substitution, comments, macros/#ifdef, dead branches), verified by Tree-sitter and gcc for syntax/compilation preservation; no claim of runtime equivalence.
      • Victim systems: automated detectors that judge uncompiled source code (CI pre-commit, IDE integration, API scanners); systems with human review or integrated with static analysis are not covered.
  2. What related research exists?

    Related work covers three categories: vulnerability detection datasets, adversarial attacks on code models, and jailbreak and transferable prompt attacks; three defenses are also included as comparisons.

    Vulnerability detection datasets and LLM detection

    • BigVul, DiverseVul—the authors note their label noise and train-test leakage; PrimeVul (Ding et al., 2024) improves on them through manual screening and deduplication, and this paper adopts its protocol and adds carrier controls.
    • Khare et al. (2025)—report that LLMs perform strongly on standard datasets; Orvalho and Kwiatkowska (2025)—argue that code language models are unreliable for detection in real-world scenarios.
    • Evaluate-and-Purify / EP-Shield (Mu et al., 2025)—uses LLM-as-a-judge to purify identifier-substitution adversarial examples; the authors state this paper is complementary, and the metrics provided can quantify EP-Shield's gains on each attack surface.

    Adversarial attacks on code vulnerability detection

    • NatGVD (Rath et al., 2025)—modifies graph structure against GNN detectors; Yefet et al. (2020)—propose identifier renaming and dead code insertion.
    • HogVul (Yang et al., 2026)—uses PSO to combine identifier and structural edits while guaranteeing compilation; the authors note the differences are that this paper targets instruction-tuned LLMs, uses gradient-based universal optimization, covers closed-source APIs, and proposes the CR metric.
    • EaTVul (Liu et al., 2024) and Natural Attack (Yang et al., 2022)—ChatGPT-generated and BERT-guided attacks, respectively, without gradient optimization or compilation verification; this paper uses random identifier substitution as a control (§5).

    Jailbreak and transferable prompt attacks

    • GCG (Zou et al., 2023) and AutoDAN (Zhu et al., 2023)—gradient or genetic search for transferable adversarial suffixes; this paper adapts GCG to the carrier-constrained code setting.
    • PAIR (Chao et al., 2024), TAP (Mehrotra et al., 2024), decomposition attack (Brown et al., 2025)—LLM-guided black-box iterative attacks; the authors state that existing evaluations rarely examine how transferable prompts perform in detection scenarios that must preserve compilability.
    • Universal adversarial triggers (Wallace et al., 2021)—this paper's universal string construction is parallel to it, adapted to the compiler-verified code domain.

    Baselines and defense comparisons: the non-GCG baselines are output-format injection (embedding the target JSON in comments, outside the threat model) and random identifier substitution (within the threat model); the defense comparisons are input sanitization, random smoothing (SmoothLLM, Robey et al., 2024), and adversarial fine-tuning. The authors position this paper as an attack-centric evaluation covering four carrier families and reporting ASR, CR, and transferability.

  3. How does the paper address this problem?

    Restrict GCG universal string optimization to four syntax-/compilation-preserving carrier types, optimize on a 14B surrogate and then transfer, and measure joint robustness with CR.

    Overall approach: constrain the adversarial string search of standard GCG to four types of syntax- and compilation-preserving carriers, optimize a universal adversarial string σ on a fixed support set, then transfer it zero-shot to each target detector, and quantify robustness with conditional attack success rate and Complete Resistance.

    Problem formalization and optimization objective

    • The attacker maximizes the model's preference for BENIGN: J(σ; x) = log pθ(BENIGN ∣ Tc(x, σ)) − log pθ(VULNERABLE ∣ Tc(x, σ)), i.e., the log-odds difference between the two labels after transformation.
    • Universal strategy: maximize the average objective Juniv(σ) = 1/m∑x ∈ Xopt J(σ; x) on a fixed support set Xopt (m=10 vulnerable functions); after optimization, σ is frozen for zero-shot transfer evaluation.
    • Reason for choosing GCG (per the authors): it can produce universal strings that transfer across samples and across models.

    Four carrier types (five attack variants)

    • Identifier substitution: scope-consistent renaming of identifiers attributed by the detector (or the most frequent local identifiers), with variable shadowing prohibited.
    • Comment carrier: inject σ into syntactically legal comments (e.g., a leading multi-line header comment) as a non-executable container.
    • Preprocessor carrier: two variants are evaluated separately—macro (σ embedded in the identifier of an unused macro) and #ifdef (σ embedded in a disabled conditional compilation block), stripped or ignored at compile time.
    • Dead-branch insertion: place σ in an unreachable block of a statically false predicate (e.g., if(0)); the authors state it is syntactically indistinguishable from executable code and can diagnose a detector's basic control-flow parsing capability.

    Validity verification (three layers)

    • Constraint checks: structural rules for each carrier (legal identifier pattern, balanced comment delimiters, #ifdef/#endif pairing, dead-branch condition always false, etc.).
    • Tree-sitter differential parsing: for all 5000 functions, the adversarial code is required to have no more AST error nodes than the original code (Eadv ≤ Eorig).
    • gcc compilation verification: verified with gcc -fsyntax-only on the 1434 compilable subset (PrimeVul source, CodeAstra true positives); identifier substitution preserves compilation in 90.9%, and the other carriers in 100% (Table 4).

    Implementation and hyperparameters

    • The surrogate model is Qwen2.5-Coder-14B; GCG steps S=500, candidate width 256, top-k 128, batch size 8, σ initialized to a placeholder pattern of length 20, optimization seed 42, support-set sampling seed 21 (Appendix B.5).
    • Curriculum-style optimization: for the first 10 steps, the number of training functions is gradually increased from 1 to 10, after which joint optimization is performed; on-target optimization of a single carrier on the 32B model takes about 20 hours (a single H100).

    Success determination and metrics

    • Strict parsing: escape succeeds only when the model outputs valid JSON and label="BENIGN"; parse failures, refusals, and hallucinations are all counted as Resist (conservative estimate); the authors report a valid parse rate >99.9%.
    • Conditional evaluation: attacks act only on clean true positives TPclean, avoiding counting pre-existing misses as robustness.
    • Three metrics: ASRcond (|Flip|/|TPclean|), CR (the proportion that simultaneously resists all five variants K={idsub, comment, macro, #ifdef, dead-branch}, which the authors call a safety lower bound), ∆TPR (recall drop over the full dataset |Flip∪|/N).
  4. What experiments did the paper conduct?

    5 of 6 models had CR≤13%; the 14B agent string transferred to GPT-4o reached 87% union ASRcond; none of the three defenses was sufficient.

    Experimental setup

    • Models evaluated: Llama3.1-8B-Instruct, CodeAstra-7B, StarCoder2-15B-instruct (white-box, doing transfer + on-target); Qwen2.5-Coder-32B (cost-limited gray-box, transfer only, plus an on-target ablation); GPT-4o (gpt-4o-2024-08-06), GPT-5-mini (gpt-5-mini-2025-08-07) (black-box API, transfer only).
    • Surrogate model: Qwen2.5-Coder-14B optimizes the universal strings; the Table 8 ablation additionally uses 0.5B/1.5B surrogates.
    • Benchmark: UNIFIED-VUL-N (N=5000 C/C++ vulnerable functions, PrimeVul 3000 + BigVul 1000 + DiverseVul 1000, cross-source SHA-256 deduplication, ≤4096 tokens).
    • Determination: a deterministic strict parser; escape is counted only for valid JSON with label=BENIGN; GPT-4o is set to temperature=0.0, and GPT-5-mini uses the API default settings.
    • Number of repetitions: random_idsub reports the mean±standard deviation over K=3 seeds; the multi-seed analysis covers on-target identifier substitution for 3 models (seeds 1/21/42); the rest are single estimates under seed 21.
    • Baselines: output-format injection (outside the threat model), random identifier substitution, and random token insertion (within the threat model).

    Main results

    According to Table 1 (N=5000; the Transfer row transfers the 14B surrogate strings as-is, and the On-target row optimizes directly on the target):

    Swipe horizontally to read the table

    ModelSettingTPRclean (%)Union ASRcond (%)CR (%)∆TPR (pp)
    Llama3.1-8BTransfer31.0499.680.3230.94
    Llama3.1-8BOn-target31.0499.870.1330.99
    CodeAstraTransfer69.0895.005.0065.63
    CodeAstraOn-target69.0899.880.1269.01
    StarCoder2-15BTransfer99.0487.7212.2886.88
    StarCoder2-15BOn-target99.0490.399.6189.52
    Qwen2.5-Coder-32BTransfer22.4299.380.6222.28
    GPT-4oTransfer46.0087.0013.0040.02
    GPT-5-miniTransfer73.6244.0455.9632.42
    • The authors state that, except for GPT-5-mini, more than 87% of correctly detected vulnerabilities can be flipped by at least one syntax-preserving edit; CodeAstra detects 3454 vulnerabilities when clean, and after the on-target attack it maintains detection for only 4 functions.
    • The authors state that GPT-5-mini is the exception (union ASRcond 44.04%, versus 87%–100% for the other models), and that retesting with 32B surrogate strings raises it to only 13.4%, concluding that the low transferability is not due to a weak surrogate.
    • Benign-class invariance: on 500 benign functions, samples judged BENIGN when clean remain BENIGN after the attack in 100% of cases for all models and attacks; the authors take this to mean the flips are integrity breaks targeting vulnerabilities rather than label corruption.

    Carrier breakdown and transfer vs. on-target comparison

    • No single carrier dominates under transfer (Table 2): #ifdef reaches 99.03% against Llama3.1-8B and 98.84% against Qwen2.5-Coder-32B; StarCoder2-15B is broken almost only by macro (86.83%, with the other carriers ≤4.00%); for GPT-5-mini, all carriers are between 10.62% and 28.14%.
    • On-target is not always stronger (Table 7): for CodeAstra, identifier substitution rises from 4.72% to 85.41%, but #ifdef drops from 42.59% to 16.62%; for Llama3.1-8B, macro drops from 96.33% to 65.46%. The authors speculate this relates to the optimizability of the attack surface, and state that a loss-surface analysis of #ifdef on CodeAstra is left for future work.
    • Surrogate capacity ablation (Table 8, Qwen2.5-Coder-32B identifier substitution): 0.5B/1.5B surrogate transfer is only 6.87%/6.42%, 14B reaches 26.94%, and on-target reaches 92.60%; the authors state that transfer is the practical lower bound and on-target is the worst-case upper bound.

    Defense evaluation

    • Input sanitization (stripping comments and preprocessor directives, Table 9/10): ASR for the comment, #ifdef, and macro carriers drops to 0%, but predictions drift on clean inputs—Llama3.1-8B clean TP rises from 1552 to 1685 (+8.6%); identifier substitution and dead branches are unaffected, and the authors call it a partial mitigation.
    • Random smoothing (majority vote over K=5 variants, Table 13, on-target identifier substitution): ASR drops by only 1.6–8.9 percentage points (Llama3.1-8B 43.49%→34.57%, CodeAstra 85.41%→82.71%, StarCoder2-15B 16.27%→14.63%).
    • Adversarial fine-tuning (LoRA fine-tuning of Llama3.1-8B, Table 14): comment 42.01%→0.16%, #ifdef 99.03%→0.00%, macro 65.46%→16.91%, but identifier substitution rises to 89.56% and dead branches remain at 68.20%; CR rises from 0.13% to 3.88%, and clean TPR drops from 31.04% to 24.72%.

    Other ablations and analyses

    • Non-GCG baselines (Figure 2): output-format injection 55–99% (outside the threat model); random_idsub 7–30%; random token insertion 13.2% versus GCG's 91.5% (comment carrier, same conditions).
    • Insertion position (Table 6): trailing comments are higher than leading ones for Llama3.1-8B (74.94%) and CodeAstra (85.15%); macro name is generally stronger than macro body (e.g., CodeAstra 98.87% vs. 30.78%).
    • Temperature robustness (Table 12, GPT-4o): union ASR at T=0 and T=0.7 is 87.00% vs. 85.19%±0.65%, and the authors state the effect is negligible (∆=1.8 pp).
    • Code length correlation (Table 11): Pearson r ∈ [−0.172, −0.024], and the authors state the correlation is weak.
    • Multi-seed analysis: on-target identifier substitution ASRcond is CodeAstra 80.7%±9.1, Llama3.1-8B 31.1%±11.3, StarCoder2-15B 17.6%±6.8 (N=3 support sets).
    • Prompt transfer (Appendix E): frozen strings under unseen zero-shot prompts give #ifdef 99.73% and comment 97.23% ASRcond.
  5. What are some points that can be further explored?

    The authors list four types of limitations: language coverage, runtime equivalence, string naturalness, and multi-seed coverage; the experiments cover only C/C++ and six models.

    Limitations and future directions noted by the authors

    • Language and protocol coverage (§6 Limitations): only C/C++ and a fixed prompt protocol are studied; the authors state that extending to other languages could enhance generality.
    • Level of verification (§6, Appendix A.3): the three-level verification only demonstrates preservation at the syntax and compilation level; formal runtime equivalence would require an execution environment that the function-level dataset does not have.
    • String naturalness (§6): the optimized universal strings (especially identifier substitutions) are often unnatural and may be blocked by code style checks or naming conventions; the reported success rates assume no such pre-filtering.
    • Multi-seed coverage (§6): the multi-seed analysis covers only on-target identifier substitution for three models; broader carrier and setting coverage is left for future work.
    • Loss surface analysis (§5.4): direct loss surface analysis for CodeAstra #ifdef is left for the future.
    • Controlled length experiments (Appendix D.1): controlled tests of length effects with fixed insertion positions and matched structural complexity are left for the future.
    • Defense directions (§6): the authors state that effective mitigation may require combining inference-time and training-time defenses, and that adversarial training with more diverse carriers and sanitizing wrappers are the next step.

    Scope of experimental coverage

    • The models tested comprise 6 target models plus 1 main agent (Qwen2.5-Coder-14B), with additional 0.5B/1.5B agents used for the Table 8 ablation.
    • The benchmark is UNIFIED-VUL-N (N=5000, C/C++ vulnerability functions); the benign side evaluation uses 500 benign functions; compilation verification uses a subset of 1434 functions (CodeAstra predictions only).
    • Defense evaluation includes input sanitization, randomized smoothing (identifier substitution carrier only, 3 models), and adversarial fine-tuning (Llama3.1-8B only); sanitization and smoothing under adaptive attacks were not evaluated.
    • Number of repetitions: random_idsub uses K=3 seeds; the temperature experiment uses K=3 runs; the multi-seed analysis uses N=3 support sets; the remaining model/carrier values are single-run estimates under seed 21 (§4.2).
    • The paper does not report a judge model or human evaluation (judgments use strict rule-based parsing); it does not report the total number of queries to GPT-4o/GPT-5-mini.
  6. Summarize the main content of the paper

    Syntax-preserving rewrites can bypass most LLM vulnerability detectors: 5/6 models have CR≤13%, transfer attacks reach 87% against GPT-4o, and existing defenses are all insufficient.

    An attack evaluation paper targeting LLM vulnerability detectors, focused on detection-time integrity in the CI/CD gate scenario.

    • Problem: the authors argue that clean benchmark accuracy cannot guarantee deployment safety—an attacker only needs to make syntax- and compilation-preserving edits (renaming, comments, macros, dead branches) to already-detected vulnerabilities to make the detector miss them.
    • Method: constrain GCG universal adversarial string optimization to four carrier types, optimize on a Qwen2.5-Coder-14B surrogate and transfer zero-shot; propose Complete Resistance (CR) to measure the proportion of vulnerabilities that simultaneously resist all five variants; determination uses strict JSON parsing, and attacks act only on clean true positives.
    • Main results (Table 1, N=5000): 5 of the 6 models have CR≤13%; CodeAstra on-target CR is only 0.12% (union ASRcond 99.88%); 14B surrogate strings transferred to GPT-4o reach 87.00% union ASRcond; GPT-5-mini is the exception, at only 44.04%.
    • Transfer and on-target: on-target is not always superior—for CodeAstra, identifier substitution goes 4.72%→85.41% while #ifdef goes 42.59%→16.62% (Table 7); on the 32B model, 14B surrogate transfer is 26.94% and on-target is 92.60% (Table 8).
    • Defenses: sanitization only eliminates the comment and preprocessor carriers and causes prediction drift; random smoothing reduces by only 1.6–8.9 percentage points; adversarial fine-tuning raises CR from 0.13% to 3.88% but identifier substitution ASR instead rises to 89.56% and clean TPR drops by 6.3 percentage points.
    • Authors' conclusion: clean recall is not a proxy for deployment robustness, and integrity-oriented evaluation and training-time defenses need to target syntax-preserving transformations; the authors also acknowledge limitations such as being limited to C/C++, not verifying runtime equivalence, and strings possibly being unnatural.
Read originalarxiv.org