Problem Description
In RAG (Retrieval-Augmented Generation) applications, markdown documents, text snippets, and documentation pages are retrieved and injected into the LLM context. Attackers can poison these files with hidden prompt injections (e.g., using zero-width characters, white-colored text, HTML hidden elements, or indirect prompt commands) to hijack the agent when the document is retrieved.
Current gap: GhostCheck already detects prompt injection and zero-width characters, but only in agent rule files and prompt templates — not in general documentation/knowledge base files that feed RAG pipelines. This scanner fills that gap.
Scope Definition
Important: GhostCheck is a static scanner, not a runtime firewall. This scanner performs pre-ingestion document linting — scanning source documents before they enter a vector database. It does NOT connect to vector DBs, monitor runtime retrieval, or detect semantic/embedding-level manipulation.
In Scope (unique value — not duplicating existing scanners)
Out of Scope (already covered or infeasible)
General prompt injection detection → Already in prompt_template_scanner.py (for template files)
Zero-width chars in agent rules → Already in agent_rules.py (for rule files)
High-entropy / base64 detection → Already in entropy_scanner.py
Vector DB / runtime analysis → Out of static analysis scope
Embedding manipulation detection → Requires ML, not regex
RAG File Scope Detection
The scanner should identify RAG-relevant files using both heuristic detection and configurable paths:
Heuristic (default): Scan .md, .txt, .html, .csv, .json files found in directories matching:
docs/, knowledge_base/, knowledge-base/, kb/, data/, corpus/, rag/, context/, wiki/
Configurable override in ghostcheck.toml:
[rag]
paths = ["docs/", "my_custom_kb/", "data/sources/"]
extensions = [".md", ".txt", ".html", ".csv", ".json"]
Implementation Details
Files involved:
src/ghostcheck/checks/rag_poison_scanner.py (New) — inherits from BaseScannerPlugin
tests/test_rag_poison_scanner.py (New)
Pattern reuse strategy: Import shared patterns from existing checkers rather than duplicating:
# Example: reuse zero-width pattern from agent_rules concepts
ZERO_WIDTH_PATTERN = r'[\u200B-\u200F\uFEFF\u202A-\u202E]'
False positive mitigation: Integrate with context_auditor.py to suppress findings where injection phrases appear in educational/warning/negative contexts (e.g., "Attackers use phrases like 'ignore previous instructions'").
Acceptance Criteria
References
Problem Description
In RAG (Retrieval-Augmented Generation) applications, markdown documents, text snippets, and documentation pages are retrieved and injected into the LLM context. Attackers can poison these files with hidden prompt injections (e.g., using zero-width characters, white-colored text, HTML hidden elements, or indirect prompt commands) to hijack the agent when the document is retrieved.
Current gap: GhostCheck already detects prompt injection and zero-width characters, but only in agent rule files and prompt templates — not in general documentation/knowledge base files that feed RAG pipelines. This scanner fills that gap.
Scope Definition
In Scope (unique value — not duplicating existing scanners)
style="display:none",style="color:white",visibility:hidden,font-size:0— injection payloads hidden via CSS<!-- ignore previous instructions -->payloads inside HTML commentsagent_rules.py(\u200B-\u200F,\uFEFF,\u202A-\u202E) but apply to RAG-scoped filesprompt_template_scanner.py(suspicious_jailbreak_phrasing) but apply to RAG-scoped filesOut of Scope (already covered or infeasible)
General prompt injection detection→ Already inprompt_template_scanner.py(for template files)Zero-width chars in agent rules→ Already inagent_rules.py(for rule files)High-entropy / base64 detection→ Already inentropy_scanner.pyVector DB / runtime analysis→ Out of static analysis scopeEmbedding manipulation detection→ Requires ML, not regexRAG File Scope Detection
The scanner should identify RAG-relevant files using both heuristic detection and configurable paths:
Heuristic (default): Scan
.md,.txt,.html,.csv,.jsonfiles found in directories matching:docs/,knowledge_base/,knowledge-base/,kb/,data/,corpus/,rag/,context/,wiki/Configurable override in
ghostcheck.toml:Implementation Details
Files involved:
src/ghostcheck/checks/rag_poison_scanner.py(New) — inherits fromBaseScannerPlugintests/test_rag_poison_scanner.py(New)Pattern reuse strategy: Import shared patterns from existing checkers rather than duplicating:
False positive mitigation: Integrate with
context_auditor.pyto suppress findings where injection phrases appear in educational/warning/negative contexts (e.g., "Attackers use phrases like 'ignore previous instructions'").Acceptance Criteria
RAGPoisonScannerinheriting fromBaseScannerPlugincontext_auditor.pyfor false positive suppression in educational docsghostcheck.tomlconfigurationghostcheck scanReferences
docs/specs/_product-backlog.md