Defend the Index Against Poisoning
Any document that reaches the index is a future context window, so an attacker who can write one document can plant text aimed at the generator. Defend at the write path first, at the chunk level second.
Procedure
Separate the write path from the read path: retrieval must never be able to add or edit a document.
Restrict ingest to a known, reviewed set of sources; a URL fetched by the agent is a candidate, not a document.
On ingest, scan for instruction-shaped text aimed at a model:
grep -inE "(ignore (previous|all)|you are now|system prompt|do not tell|instead reply)" chunk.txt.Flag chunks that address an "assistant", "AI" or "model" directly; legitimate documentation rarely does.
Look for invisible carriers — zero-width characters and homoglyphs — with
python3 -c "import unicodedata,sys; print(''.join(c for c in sys.stdin.read() if unicodedata.category(c).startswith('C')))".Quarantine flagged chunks rather than editing them, so the origin is preserved for the write-path fix.
At query time, wrap every retrieved chunk as untrusted data and never execute imperatives inside it.
Cap how much of the index one source may contribute, so a single flooding document cannot dominate retrieval.
Watch for SEO-style poisoning: one document stuffed with every query term to win every rank; weight by source, not by term frequency.
Log ingest per source and review any source whose chunk count jumps unexpectedly.
Re-ingest quarantined sources only after a human clears them, and record who cleared them and when.
Pitfalls
Fetching a page, chunking it, and embedding it in one step with no review boundary.
Missing a payload because it hides in a table cell or alt text the extractor dropped the flags on.
Cleaning the retrieved text at query time while leaving the poisoned chunk live for the next query.
Trusting "trusted" sources absolutely; an internal wiki is user-writable.
Quarantining one chunk but leaving the rest of the poisoned document indexed.
Letting a summarisation step rewrite the poison into clean-looking prose that passes a keyword scan.
A keyword scan that runs on decoded text while the poison lives in an undecoded UTF-16 stream.
Allowing the ingester to follow links it finds in a poisoned page, expanding the blast radius.
Verification
grep -c "quarantined" kb/ingest.log; grep -rinE "(ignore previous|assistant mode|you must)" index/ | wc -l
# passes when every flagged chunk is quarantined and no instruction-shaped text remains retrievable
Report to the user: sources ingested, chunks flagged, quarantined, and the write-path restriction applied.