The vulnerability exists in Neo4jChatAgent and ArangoChatAgent because they execute LLM-generated database queries (Cypher and AQL, respectively) without proper validation. An attacker can influence the LLM's output via prompt injection, causing it to generate malicious queries. These queries are then passed directly to the database driver.
The core of the issue lies in the tool-handling methods (cypher_retrieval_tool, cypher_creation_tool for Neo4j, and aql_retrieval_tool, aql_creation_tool for ArangoDB). In vulnerable versions, these methods take the query string from the LLM's tool message and execute it via helper methods (read_query, write_query) without any safety checks.
This allows an attacker to perform unauthorized actions:
- Data Exfiltration: By injecting queries into the retrieval tools (
cypher_retrieval_tool, aql_retrieval_tool), an attacker can read any data from the database.
- Data Destruction/Modification: By injecting queries into the creation tools (
cypher_creation_tool, aql_creation_tool), an attacker can modify or delete data.
- Remote Code Execution (RCE): If the database is configured with powerful procedures (like APOC in Neo4j or user-defined functions in ArangoDB), an attacker can execute commands on the underlying operating system.
The patch, identified in commit 5a3097d9dd6378b08ced5480b0caf76cc58d00fa, introduces a validation mechanism similar to what was previously implemented for SQLChatAgent. It adds a new configuration flag, allow_dangerous_operations (defaulting to False), and new validator functions (validate_cypher_query, validate_aql_query). These validators are now called within the tool-handling methods to inspect the query and reject it if it contains dangerous or unauthorized operations, unless explicitly allowed by the operator. The functions read_query and write_query are the sinks where the unvalidated queries were executed.