How niteshinplace-spd/llm-security-gateway-for-prompt-injection-and-pii-protection works
RustGuard is an asynchronous LLM security gateway. Client chat requests enter the server proxy, pass authentication and governance checks, undergo prompt inspection, and are forwarded to an upstream model; responses are redacted or inspected as SSE streams before returning to the client. The server also exposes health and metrics, records audit events, and supports optional HNSW-based RAG with a separate ingestion utility. The README documents several pipeline connections not visible in the sampled proxy excerpt; those edges cite the README, and unsampled implementation details are not inferred.
Main entry points: proxy.rs HTTP Proxy · streaming.rs SSE Inspection · injection.rs Injection Scanner · normalizer.rs Text Normalizer
Components 14
Gateway Server
- HTTP Proxy
gateway-server/src/proxy.rs - Bearer Authentication
gateway-server/src/config.rs - Governance and SSRF
gateway-server/src/config.rs - HTTP Error Mapping
gateway-server/src/error.rs
Security Inspection
- Text Normalizer
gateway-core/src/normalizer.rs - Injection Scanner
gateway-core/src/injection.rs - PII Redaction
gateway-core/src/pii.rs - SSE Inspection
gateway-core/src/streaming.rs
RAG Retrieval
- HNSW RAG Engine
gateway-server/src/rag.rs - Document Ingestion
gateway-server/src/bin/ingest.rs
Telemetry and Audit
- Audit Records
gateway-server/src/audit.rs - Atomic Metrics
gateway-core/src/metrics.rs
Other components
- Client Application
- LLM Provider
Connections 19
- Client Application → HTTP Proxy: sends chat request
README.md - HTTP Proxy → Bearer Authentication: enforces token
gateway-server/src/proxy.rs - HTTP Proxy → Governance and SSRF: checks policy
README.md - HTTP Proxy → Text Normalizer: normalizes prompt
README.md - Injection Scanner → Text Normalizer: normalizes input
gateway-core/src/injection.rs - HTTP Proxy → Injection Scanner: scans prompt
README.md - HTTP Proxy → HNSW RAG Engine: retrieves context
gateway-server/src/proxy.rs - Document Ingestion → HNSW RAG Engine: populates index
- HTTP Proxy → LLM Provider: forwards request
README.md - LLM Provider → HTTP Proxy: returns response
README.md - HTTP Proxy → PII Redaction: redacts response
README.md - HTTP Proxy → SSE Inspection: inspects SSE
README.md - SSE Inspection → Injection Scanner: scans chunks
gateway-core/src/streaming.rs - SSE Inspection → PII Redaction: checks secrets
gateway-core/src/streaming.rs - HTTP Proxy → Client Application: returns result
README.md - HTTP Proxy → Audit Records: emits audit record
gateway-server/src/proxy.rs - HTTP Proxy → Atomic Metrics: updates counters
gateway-server/src/proxy.rs - HTTP Proxy → HTTP Error Mapping: returns gateway errors
gateway-server/src/proxy.rs - HTTP Proxy → Atomic Metrics: serves metrics
gateway-server/src/proxy.rs