A retrieval-augmented generation (RAG) system answers questions using passages it retrieves from a knowledge base, so users must trust that knowledge base. We study an attacker who quietly edits existing passages by swapping words for synonyms (PWWS, TextFooler) in a cybersecurity RAG system built from MITRE ATT&CK and CAPEC. Using a reviewed 44-question benchmark, repeated paired runs and a control corpus in which only the layout changes, we find that poisoning lowers judged answer correctness from 0.714 to 0.555. The damage comes mostly from lost evidence and refusals, not from false statements. To find the edited passages, we use relative entropy. Comparing a whole passage with normal text is a weak signal. Still, one term of the relative entropy, the log-ratio between a word and its most probable synonym, works well: with a small language model as the reference, it reaches an AUROC of 0.95 and stays near chance on the control. Used as a retrieval filter, it halves how often edited text reaches the generator, and an attacker who must keep each passage as probable under the language model fails on all 57 sections it tries. Filtering does not restore correctness, because the edited passage is usually the one that held the answer. We therefore add a runtime monitor that checks each answer against trusted MITRE STIX data and remembers the passages it rejects. On its own, it reduces exposure to edited text from 0.41 to 0.26; when it may add the trusted MITRE entry as a source, correctness rises to 0.786. We report the costs and failure cases of every defence alongside its gains.
Figures & tables
Figure 1: AegisRAG overview
Figure 2: How the knowledge base is poisoned
Figure 3: The synonym gap for one word
Figure 4: The runtime monitor loop
Questions
Hit@3
Correctness
Δ [95% CI]
All (44)
.705 → .568
.714 → .555
− .159 [ − .254, − .068]
Source section edited (27)
.630 → .444
.682 → .432
− .250 [ − .383, − .124]
Not edited (17)
.824 → .765
.765 → .750
− .015 [ − .083, .069]
TABLE I: Effect of PWWS poisoning (44 questions, 132 paired answers per condition). Δ : change in correctness.
Figure 5: What happens to the answers
Detector
PWWS
PWWS (retrained)
TextFooler
Control (layout only)
Frequency-matched adaptive
Letter-frequency KL
0.33
0.31
0.28
0.35
0.36
Word KL vs domain
0.72
0.74
0.83
0.62
0.50
Jensen–Shannon vs domain
0.47
0.47
0.48
0.43
0.44
Mean surprisal (perplexity)
0.77
0.77
0.82
0.45
0.73
Top-5 surprisal (windowed perplexity)
0.91
0.93
0.92
0.56
0.85
Synonym gap, domain q
0.82 [.72, .90]
0.88 [.82, .94]
0.90 [.85, .94]
0.67 [.57, .77]
0.47 [.33, .72]
TABLE II: Detection of passages that contain substituted words (AUROC: 1.0 is perfect, 0.5 is chance). Brackets: 95% bootstrap intervals that resample documents. 191 passages (193 for TextFooler); edited passages: 47 PWWS, 59 PWWS on the retrained surrogate, 82 TextFooler, 13 frequency-matched adaptive. The control has no word edits: its “positives” are the 48 passages whose layout was flattened, so a score above 0.5 there reflects layout or section choice, not substitutions. Last row: edits flagged at the contextual threshold (4.46 bits) fixed on PWWS development documents, which flags 9–14% of unedited passages.
Figure 6: The two synonym-gap detectors on every corpus
Figure 7: Every defence on the PWWS-poisoned knowledge base
Defence
Exposure
Correct.
Wrong
Refusals
Clean cost
None
.409
.555
2
45
–
Drop (freq.)
.273 a
.526
0
53
− .064
Repair
.364
.506
0
54
− .042
Drop (ctx.)
.204 b
.485 c
0
63
− .013
ap=0.031 ; bp=0.012 ; cp=0.020 .
TABLE III: Retrieval filters on the poisoned corpus (44 questions × 3; p : Wilcoxon against no defence). Clean cost: change in correctness on the clean corpus.
Attacker
Sections
Edits
Freq.
Ctx.
Unrestricted PWWS
39
59
.88
.97
1st order: frequency-matched
8
13
.47
.92
2nd order, strict
0
0
–
–
2nd order, ≤ 4.46 bits
0
0
–
–
2nd order, ≤ 20 bits
0
0
–
–
2nd order, ≤ 100 bits
5
6
.51
.78
TABLE IV: Adaptive attackers (same retrained surrogate and 57 attackable sections; only the evasion rule differs). AUROC of the word-frequency and contextual synonym gaps.
Figure 8: Second-order attacker and the language-model budget
Comparison
Monitor
Baseline
Δ [95% CI]
Verify, PWWS: exposure
.258
.409
− .152 [ − .265, − .061] a
Verify, PWWS: correctness
.515
.555
− .040 [ − .085, .000]
Verify vs ctx. filter: exposure
.258
.204
+.053 [ − .030, .144]
Verify vs ctx. filter: correctness
.515
.485
+.030 [ − .002, .068]
Verify, clean data: correctness
.708
.714
− .006 [ − .023, .011]
Verify, TextFooler: exposure
.583
.818
− .235 [ − .356, − .114] b
TABLE V: Runtime monitor, live, second version (44 questions × 3; question-level paired comparisons; p : Wilcoxon). One TextFooler answer was lost to a network error and is excluded.