crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

Add input validation hooks for memory/RAG ingestion and optional confirmation flag for NL2SQLTool

Open Trustableclaw opened this issue 5 months ago • 6 comments

Feature Area

Other (please specify in additional context)

Is your feature request related to a an existing bug? Please link it here.

NA - not related to an existing bug report. Based on an independent security analysis of the framework's memory ingestion and tool execution paths.

Describe the solution you'd like

We ran an independent security audit of CrewAI (TrustableClaw AI Agent Scanner) and identified two related design gaps:

Memory/RAG ingestion has no validation hook. KnowledgeStorage.save() and CrewAIRagAdapter.add() write document content directly to the vector store with no opportunity to inspect or filter content before indexing. If an agent ingests external content (scraped pages, uploaded files), prompt injection payloads get persisted into long-term memory and retrieved into future task contexts. NL2SQLTool has no confirmation gate for SELECT queries. Read-only mode blocks writes, but unrestricted SELECT execution remains - combined with the memory ingestion issue above, creates a path where a poisoned memory retrieval can drive an unreviewed database query.

Proposed solution:

Add an optional validation_hook / content_filter callable on KnowledgeStorage and CrewAIRagAdapter that runs before add_documents(), defaulting to a no-op for backwards compatibility. Add an optional require_approval: bool flag on NL2SQLTool, following the existing human_input pattern on tasks, to gate query execution behind confirmation.

Full technical write-up with reproduction details: https://trustableclaw.com/security-audits/crewai-agent-security-scan

Describe alternatives you've considered

Documenting these as "known limitations" / application-layer responsibilities in the docs, rather than framework-level features. Happy to contribute that documentation PR as well if the maintainers prefer that path over code changes.

Additional context

Full audit details, exploit chain walkthrough, and code references: https://trustableclaw.com/security-audits/crewai-agent-security-scan

Scanned commit: d3fc0d31, 3,320 files, June 12 2026.

Willingness to Contribute

Yes, I'd be happy to submit a pull request

Trustableclaw avatar Jun 14 '26 01:06 Trustableclaw

The audit findings are spot-on — the absence of validation hooks on KnowledgeStorage.save() is a real gap that leaves the door open for poisoning through content ingestion, not just through direct agent interaction.

One thing this analysis surfaces that I'd add: even with validation hooks in place, the hook needs to know who authored the content being ingested to make meaningful access-control decisions. A content filter that blocks known-injection patterns is useful, but what about cross-agent memory poisoning — where Agent A (compromised via a different vector) writes plausible-looking but subtly poisoned content that Agent B retrieves later?

We run 20+ production agents across CrewAI, AutoGen, and LangGraph in a shared memory environment (fully open-source at github.com/sunfishloop/sunfishloop). Every memory write produces a wallet-signed receipt (ETH/SOL/BTC keypair, discovered at /llms.txt) that records which agent wrote what and when. This means a validation hook on retrieval can check: "did the authoring agent have write-permission to this memory namespace at time of writing?" — not just "does this content look suspicious?"

The NL2SQLTool confirmation gap you flagged is related. With signed receipts, even if a poisoned memory triggers an unauthorized query, the provenance chain lets you trace which agent's memory caused it and revoke that agent's write access, rather than trying to block every possible query pattern.

The hook interface you're proposing is the right shape — adding an optional content_origin field to the hook's signature that carries the wallet address of the writing agent would let the validation layer enforce memory-level access control without needing a central permission store.

sunfishloop avatar Jun 15 '26 16:06 sunfishloop

Input validation at the memory ingestion boundary is critical and often overlooked. Our approach: every memory store operation passes through a validation layer that checks content length, encoding consistency, and known injection patterns before the data reaches the vector index. The validation runs synchronously at write time (not async) because poisoned data in the index is much harder to clean up than rejecting it at the gate. For RAG specifically, we also hash document chunks at ingestion to detect duplicate or near-duplicate content that might indicate adversarial repetition attacks. The importance scoring system adds another layer — externally sourced content gets stored at lower default importance than agent-generated knowledge, so it ranks lower during recall. Fulltext search with content validation: https://github.com/dakera-ai/dakera-py/blob/main/examples/fulltext_search.py

ferhimedamine avatar Jun 15 '26 21:06 ferhimedamine

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jul 16 '26 12:07 github-actions[bot]

Reliability note

Production automation failures usually reduce to a contract issue before a model/prompt issue:

  1. Success criteria — durable artifact id (message/booking/row), not only node green
  2. Side-effect before complete — never blind-retry without an idempotency key on the business object
  3. Tool vs path split — external action can succeed while the node/agent path still errors (silent-green / false-red)

If you have one failing execution + expected vs actual, reply with stack/version and I will send a free root-cause checklist.

IgorGanapolsky avatar Jul 22 '26 21:07 IgorGanapolsky

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Aug 22 '26 12:08 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Aug 27 '26 15:08 github-actions[bot]