sanitizeForPrompt neutralizes prompt-injection / exec / persistence payloads in memory before it is injected into the system prompt. Memory is auto-curated and should never carry shell scripts, so it uses the stricter ScopeMemory. The on-disk store is never modified.
(s string)
| 128 | // is auto-curated and should never carry shell scripts, so it uses the |
| 129 | // stricter ScopeMemory. The on-disk store is never modified. |
| 130 | func (ms *MemoryStore) sanitizeForPrompt(s string) string { |
| 131 | if s == "" || !threatscan.Enabled() { |
| 132 | return s |
| 133 | } |
| 134 | sanitized, blocked := threatscan.Sanitize(s, threatscan.ScopeMemory) |
| 135 | if blocked > 0 && ms.logger != nil { |
| 136 | ms.logger.Warn("threatscan: neutralized lines in memory context", |
| 137 | zap.Int("blocked", blocked)) |
| 138 | } |
| 139 | return sanitized |
| 140 | } |
| 141 | |
| 142 | // AttachVectorIndex attaches a vector index used by HyDE Phase 3b. |
| 143 | // Pass nil to detach. |
no test coverage detected