An indirect prompt injection can affect a search-augmented large language model only after its carrier page reaches model context. SearchInject controls this admission decision with a joint score combining retrieval relevance, search-abuse cues, instruction likelihood, and two relevance interactions. A quarantine threshold is selected under an empirical 0.5% clean-candidate false-quarantine constraint on a calibration split. Evaluation uses 300 held-out SciFact queries and held-out payload categories within four construction families already represented during development. Across 1,200 query-family outcomes per retriever, top-10 target exposure falls from 0.9408 to 0.1583 for BM25, from 0.9158 to 0.1508 for a normalized hybrid, and from 0.8450 to 0.1375 for latent semantic analysis. These are relative reductions of 83.2-83.7%; the largest absolute change in clean normalized discounted cumulative gain at rank 10 is 0.0018. The frozen threshold yields clean test false-quarantine rates of 0.59-0.65%, above the empirical calibration constraint. A query-level analytical reanalysis accounts for the repeated construction outcomes under an independent-query assumption. A separate 104-case generation follow-up records context removal but no confirmed undefended hijacks under a post hoc endpoint, so it cannot estimate a reduction in attack success. The evidence supports retrieval exposure control within the evaluated construction families; the benefit of the interaction terms at matched clean cost remains unresolved.
Figures & tables
Fig. 1: SearchInject scores the depth-100 candidate list before context assembly. Rejected pages are omitted, and accepted candidates retain their original relative order. The main evaluation measures target admission; generation behavior is a separate exploratory endpoint.
Item
Setting
Corpus
5,183 SciFact abstracts in BEIR format
Queries
655 fitting; 154 calibration; 300 test
Payload categories
9 fitting; 3 calibration; 13 test
Construction families
Title stuffing, doorway, near duplicate, hidden metadata; all seen during development
Retrieval
BM25, LSA, normalized hybrid; depth 100
Joint model
Class-balanced logistic regression; [r,a,i,ar,ir]
TABLE I: Evaluation protocol and known implementation settings
Exposure@10
Clean NDCG@10
Retriever
None
Joint
None
Joint
BM25
.9408
.1583
.6602
.6584
Hybrid
.9158
.1508
.4606
.4593
LSA
.8450
.1375
.3000
.2987
TABLE II: Main results over the four known construction families
Fig. 2: Exposure and clean retrieval utility at the recorded operating point. Panel (a) shows the large decrease in target admission; panel (b) shows the small measured clean NDCG change. Bars reproduce Table II ; they do not depict an operating-point sweep. The query-level analytical uncertainty for exposure reduction is reported in the text.
Split or retriever
False quarantine
Threshold
Calibration constraint
≤0.500%
Selected on calibration
Calibration observed
0.498%
0.973853
BM25 test
0.590%
0.973853
Hybrid test
0.620%
0.973853
LSA test
0.650%
0.973853
TABLE III: Empirical calibration constraint and clean test observations
Family
BM25
Hybrid
LSA
Title stuffing
1.000/.083
1.000/.083
.983/.080
Doorway
1.000/.230
.987/.233
.847/.207
Near duplicate
.763/.197
.680/.163
.590/.133
Hidden metadata
1.000/.123
.997/.123
.960/.130
TABLE IV: Exposure@10 by construction family
Policy
Exposure@10
Clean Δ NDCG@10
Abuse only
.1436
−.1113
Instruction only
.4169
−.0071
Joint quarantine
.1489
−.0014
TABLE V: Component policies at their recorded operating points
Model
Prompt
None
Joint
Clean correct
Qwen3-4B
Conventional
0/4
0/4
36/90
Qwen3-4B
Hardened
0/4
0/4
34/90
Phi-4-mini
Conventional
0/4
0/4
47/90
Phi-4-mini
Hardened
0/4
0/4
47/90
TABLE VI: Exploratory generation observations by model and prompt
Linear probes on a model's hidden states are used as cheap monitors for indirect prompt injection: they screen the tool outputs an agent reads and send suspicious ones to a slower second check, so every false alarm has a cost. But a probe learns whatever separates its training examples. The standard evaluation of injection probes can be passed without the model: conversation position and text lengths alone reach 0.91-0.98 AUROC. When each attack is compared with the same conversation without the injection, or with harmless text formatted like an injection, standard probes flag most of these harmless cases. We add such cases to the training data as matched negatives. Across six open models, in applications seen during training and at the default threshold, changing only the training data cuts false alarms on injection-free conversations from 41-80% to 4-27%, and on harmless look-alikes from 92-98% to 3-16%. With a threshold set on normal traffic, our probe still catches a median 95% of the attacks that fooled the agent (91% without our data). In new applications, false alarms stay low, but detection depends on the model and on how the threshold is set. The same data also helps a text-only filter.
ReAct agents that interleave chain-of-thought reasoning with tool calls are increasingly deployed for real tasks such as scheduling, file retrieval, and data access. Their tool observation loop creates a direct attack surface: an adversary who controls any tool's return value can embed instructions that redirect the agent away from the user's goal, a threat known as indirect prompt injection. Existing benchmarks evaluate attack success rate (ASR) at a fixed injection position under fixed conditions, leaving three risk dimensions unexplored: where in the tool sequence the payload appears (injection depth), what rhetorical register it uses (framing), and how many turns the agent is permitted (turn cap). We conduct four controlled studies on 20 scenarios spanning five attack categories, totalling 460 trials against GPT-4o-mini and Claude Haiku at a combined API cost under 0.36 USD. Study 1 shows that ASR against GPT-4o-mini decays from 60% at depth 1 to 0% at depths 4 and 5 (Cramer's V = 0.58, p < 0.001; restricted to within-sequence depths 1-3: V = 0.47, p = 0.0013), driven by model resistance at depth 1 and task completion before payload encounter at deeper positions. Study 2 replicates the depth experiment on Claude Haiku, which achieves 0% ASR at every depth through a combination of conservative tool invocation and genuine instruction resistance. Study 3 shows that framing modulates ASR between 25% (neutral) and 75% (persona) at depth 1, a 50-percentage-point range that does not reach statistical significance at N = 20 per condition. Study 4 confirms that ASR is stable across turn caps of 3, 5, and 7, indicating the turn budget is not a risk factor in this setting. Our results establish injection depth as the dominant variable and show that sanitising only the first tool observation captures 67% of measured injection successes.
Mohammadreza Rashidi
Department of Computer Science AI and Media Analysis Lab Berlin, Germany
Local Retrieval-Augmented Generation (RAG) systems are vulnerable to indirect prompt injection and retrieval poisoning, where malicious instructions in retrieved content are mistaken for trusted input. We present nokast-secureRAG, a roughly 0.5B-parameter small language model that acts as a semantic firewall between retrieval and generation. It jointly evaluates the user query and retrieved context, classifying the pair as safe, suspicious, or malicious. The model is trained using a teacher-judge-student pipeline: a 35B teacher generates 5,233 examples across four attack families, and an independent 120B judge re-labels them, achieving 95.0% agreement before student fine-tuning. On a held-out in-distribution test set, the model achieves 0.994 detection recall at a 0.026 false-positive rate and a 0.006 attack-success-rate proxy, outperforming a regex baseline, a public prompt-injection classifier, Llama Guard 3 1B, and its untuned version. Prompt-Guard-86M reaches 0.900 recall but has a 0.690 false-positive rate. On a judgment-flip test, where the same sentence is benign or malicious depending on context, the model correctly classifies both cases 75% of the time, outperforming the compared baselines. Ablations indicate that retrieved context carries the main attack signal, while query-context consistency reduces false positives. Single-request latency is 293-404 ms, above the target of 100 ms, while amortized throughput latency is 37 ms under batching. On the external PoisonedRAG benchmark, recall falls to near zero, indicating that fluent fact-poisoning attacks lie outside the detector's instruction-consistency threat model. We report this limitation alongside the in-distribution results. The model, data-generation pipeline, and evaluation harness are released open source.