Depth-Consistency Probes: Catching Encoder Backdoors with the Downstream User's Own Linear Heads

Many teams no longer train vision models from scratch. They download a pretrained encoder, a network that turns images into feature vectors, freeze it, and train only a small linear classifier on top. This practice is called linear probing. It is also the exact channel a backdoor travels through. A backdoor is a hidden behaviour planted by an attacker: the model works normally on ordinary inputs, but any input carrying a secret trigger, such as a small patch, is pushed to a class the attacker chose. Prior work shows that a poisoned encoder hands its backdoor to every linear classifier built on it, even when that classifier is trained only on clean labels. BadEncoder reaches attack success rates above 98% with less than 1% loss of clean accuracy. Poisoning self-supervised pretraining data works too: in Backdoor Attacks on Self-Supervised Learning, patched images produce false positives on the target class that jumped from 19.2 to over 1442. Both papers treat the linear probe purely as a victim.

We propose to make the probe the defense. The user already has labeled data for their task. They can train cheap linear classifiers on frozen activations from several intermediate layers of the encoder, not just the last one. The idea rests on one observation: encoder backdoors are installed by losses that act on the encoder's output. A triggered image may therefore still carry its true class in a form that a linear classifier can read at middle depths, even while the final layer reports the attacker's target. When the intermediate classifiers disagree with the final one, the input is suspicious. When they agree with each other, their answer is a candidate repaired prediction. The scientific question behind the defense is how deep an encoder backdoor has to reach to escape this check, and what that depth costs the attacker.

Core Claim

The core claim has two parts. First, for the main attacks on frozen encoders (BadEncoder-style fine-tuning, poisoned contrastive pretraining, concept-confusion backdoors, and feature-entangled triggers), a disagreement score computed from layer-wise linear probes detects triggered inputs at test time. Its threshold can be calibrated using only clean downstream data, with no triggers, no trigger inversion, and no change to the encoder. Second, an adaptive attacker can escape the score only by pushing the trigger's effect into early layers. We expect that doing so measurably raises clean-accuracy loss on downstream tasks, or makes the trigger visible to input-space and frequency defenses. If both parts hold, the attacker is forced to trade stealth in one place against stealth in another.

Concretely, let $h_l$ be a linear probe trained on frozen layer-$l$ features with the user's labels, let $L$ be the final layer, and let $\hat y_L(x)$ be the final probe's predicted class for input $x$. The suspicion score is

$$s(x) = 1 - \frac{1}{|S|}\sum_{l \in S} p_l\big(\hat y_L(x) \mid x\big),$$

where $S$ is a small set of intermediate layers and $p_l(\cdot \mid x)$ is probe $h_l$'s softmax output. The score is low when the shallower probes also believe the final answer, and high when they do not. The threshold is set to a fixed false-positive rate on held-out clean data. For flagged inputs, the repaired prediction is the majority vote of the probes in $S$.

Relation to Prior Work

The closest prior work is Defending Against Backdoor Attacks by Layer-wise Feature Analysis (DBALFA), which motivates this proposal. DBALFA names the "last layer fallacy": poisoned and clean features have already merged at the final layer. It finds that an intermediate layer separates them best, and it detects poisoned inputs by cosine similarity to class centroids on supervised CNNs. It uses about 10% of the test set as clean calibration data and reaches a 98.09% true positive rate at a 1.34% false positive rate on CIFAR-10.

We differ in three ways. First, we study frozen pretrained encoders attacked in a task-agnostic way. Here the attacker never saw the downstream task, so whether a "layer of interest" exists at all is an open empirical question rather than an inherited fact. Second, we use trained linear probes instead of centroids. This difference is modest, since a nearest-centroid rule is itself a linear classifier, so we test it directly as an ablation rather than claim it as the contribution. Third, we characterise the adaptive attacker's depth-versus-cost trade-off, which DBALFA does not study.

The attack papers constrain and supply the threat models. BadEncoder applies its effectiveness and utility losses to the encoder output. That design is exactly why we expect intermediate layers to retain clean semantics, and why an adaptive variant must move those losses earlier. Imperceptible Backdoor Attack explicitly aligns triggered features with the target-class centroid. It defeated pruning of over 500 neurons, but it was checked only at the final hidden layer, which makes it the hardest test for our idea. C2 ATTACK turns a naturally encoded concept direction in CLIP into a trigger with 100% success and no input noise. Because the trigger lives inside the representation, intermediate probes might inherit it. This is the case most likely to break our method, so we treat it as a stress test.

Two lines of work operate in other spaces. AMDET detects backdoored vision-language models at the model level, using trigger optimisation plus Hessian analysis (89.90% F1 over 3,600 models). TBAR removes backdoors by subtracting a weight-space task vector. Both answer "is this model poisoned?" or "clean the weights", whereas we answer "is this input triggered, and what is its real label?" without editing the encoder.

One result might seem to undercut the approach. Probing the Probing Paradigm shows that high probe accuracy does not mean the model uses a feature: probes reached about 80% on deliberately irrelevant properties. That result works in our favour. We need only that the true class remain readable at middle depth, not that the encoder relies on it, so incidental encoding is exactly what the defense exploits.

Research Program

The work has three parts. The first is a measurement study, "how deep does the backdoor go." For each attacked encoder we train probes at every block and plot two curves against depth: clean accuracy, and the fraction of triggered inputs classified as the true class versus as the target. The depth at which triggered inputs flip to the target is the backdoor's onset depth. Comparing onset depth across attack families is a finding in its own right, and it tells us which layers belong in $S$.

The second part is the detector and repair described above. Layer selection uses only clean data: we pick the deepest layers whose clean probe accuracy is within a fixed margin of the final layer's. This keeps the defender from peeking at triggers.

The third part is an adaptive attack. We modify BadEncoder so that its effectiveness and utility losses also act on intermediate features from depth $k$ onward, and we sweep $k$ toward the input. At each $k$ we record three things: downstream clean accuracy under linear probing, our detector's area under the ROC curve (AUROC), and the trigger's detectability by STRIP and by a frequency-domain check. The deliverable is the curve showing how much utility or stealth the attacker must give up to evade depth-consistency.

Baselines

The naive reference is the standard practice in BadEncoder and Backdoor Attacks on Self-Supervised Learning: a single final-layer linear probe with no detection. It fixes the attack success rate any defense must reduce; BadEncoder reports above 98% on CIFAR-10, STL-10, GTSRB and SVHN.

The strongest per-input competitor is DBALFA's centroid cosine test applied at the same intermediate layers. DBALFA reports a 98.09% true positive rate at 1.34% false positive rate on CIFAR-10 and 100% true positive rate on GTSRB, but those numbers are for supervised CNNs. We found no reported result on Lacuna for DBALFA against BadEncoder-style or poisoned self-supervised encoders. We will run DBALFA on identical encoders with identical clean data, and we will give it the same layer budget and the same clean-only calibration. Beating it means a higher true positive rate at a matched 5% false positive rate on the frozen-encoder attacks, or matching it while also delivering a repaired prediction.

STRIP is the black-box baseline. It reports 0% false acceptance and 0% false rejection in most CIFAR-10 and GTSRB cases, at about 1.32× latency, but it was bypassed by the frequency backdoors in SPD. We run it with its published number of blended copies, and we must outperform it on the entangled and concept attacks.

The ablation that isolates the key ingredient is a single fixed intermediate probe with no disagreement test: the user simply deploys the best mid-layer probe. If this matches our method on both clean accuracy and attack success, the detection machinery adds nothing. A second ablation swaps trained probes for centroids, which isolates whether training probes matters at all.

Why not just…?

Why not just deploy a probe on a middle layer and skip detection? This is the real threat. If mid-layer features lose little clean accuracy and carry no backdoor, that simple choice is a perfectly good defense. We expect it to fall short for two reasons. The deepest layer that is still clean will often be noticeably less accurate on fine-grained downstream tasks. And an adaptive attacker can target any single fixed layer, whereas the disagreement test needs only one clean layer anywhere in $S$. The fixed-probe ablation and the adaptive sweep settle this directly. If the fixed probe wins, we will report that as the main finding.

Why not just use DBALFA's centroids? Centroids are a linear rule, so they may perform identically, and we treat this as an ablation rather than a straw man. Trained probes should matter more on many-class tasks and on CLIP features, where class clusters are anisotropic. If they do not, the contribution narrows honestly to the frozen-encoder measurements and the attacker trade-off curve.

Why not just retrain the head on clean data, or fine-tune the encoder? BadEncoder already shows that clean-label linear heads inherit the backdoor. Distillation-based cleanup in Backdoor Attacks on Self-Supervised Learning needed a 25% clean subset, and Fine-Pruning left about 30% attack success on U.S. traffic signs. We include fine-pruning and full fine-tuning at matched clean-data budgets as mitigation comparisons.

Proposed Experiments

The attacked encoders are BadEncoder applied to CIFAR-10-pretrained and CLIP image encoders, evaluated on CIFAR-10, STL-10, GTSRB and SVHN. We add BYOL and MoCo v2 encoders poisoned as in Saha et al. on ImageNet-100, C2 ATTACK on CLIP evaluated on CIFAR-10, and an encoder trained with the feature-entanglement loss from the imperceptible attack on GTSRB. We also use supervised models from BackdoorBench (BadNets, WaNet, ISSBA) to confirm we reproduce DBALFA's regime.

We measure four things. Detection is measured by per-input AUROC and true positive rate at 5% false positive rate. Mitigation is measured by attack success rate and clean accuracy after repair. Cost is measured as training time for the probe stack. The adaptive sweep is summarised by clean accuracy against penetration depth $k$.

Three checks decide the outcome. First, the onset-depth curves must show the true class remaining linearly readable in some intermediate layer for BadEncoder and poisoned pretraining. Second, our method must beat the fixed-mid-probe ablation on clean accuracy at equal attack success rate. Third, on the entangled and C2 attacks, either detection holds, or the curve shows that defeating it forced the trigger into layers where clean accuracy or STRIP-style detectability degraded. A flat trade-off curve, in which the attacker loses nothing by going early, would falsify the second part of the core claim.