title: LLM-Generated Graph Query Reaching a Remote Endpoint (APOC remote script, raw-IP load, remote export)
id: ATR-2026-02608
rule_version: 1
status: experimental
description: |
  Detects a Cypher statement -- typically one an LLM wrote for a text-to-query agent -- that leaves the database: it fetches and runs a remote Cypher script (apoc.cypher.runFile at an http URL), reads from a bare IPv4 address rather than a named service, or exports graph contents to a remote URL. GHSA-2pq5-3q89-j7cc (Langroid Neo4jChatAgent) executes model-written Cypher with no validation, so a prompt injection anywhere upstream becomes a data-egress primitive. Verified on the engine: apoc.load.jsonParams and apoc.cypher.runFile at http endpoints score zero, while the file:// form only matches because two SSRF rules recognise the scheme.
  WHAT IS DELIBERATELY NOT CLAIMED, AND WHY. apoc.load.json against an https hostname is the procedure's DOCUMENTED purpose -- the APOC manual's own first example calls a public API -- and enriching nodes by concatenating an id into a URL is ordinary practice. Both were written as benign twins and both are measured silent. That is why the load condition demands a raw IPv4 literal: a legitimate enrichment call names a service, a beacon names an address. The cost of that choice is that exfiltration to an attacker-owned DOMAIN through apoc.load is not detected here, and no attempt is made to guess at it.
  THAT PREMISE HOLDS ONLY FOR PUBLIC ADDRESSES, which adversarial review established by counter-example. In loopback, RFC1918 and link-local space an IP literal is the NORM, not the anomaly: APOC's own integration tests call http://127.0.0.1:<port>, docker and Kubernetes fixtures address pod and bridge IPs, and ansible/terraform bootstrap jobs and non-English tutorials name 10.x/192.168.x hosts directly. Fourteen such twins fired the original condition. The load condition therefore excludes 0.x, 10.x, 127.x, 169.254.x, 172.16-31.x and 192.168.x, with one carve-in: 169.254.169.254, the cloud metadata address, still fires because reaching it is never ordinary enrichment. A beacon to a private address from a compromised in-network host is consequently NOT detected here.
  THE EXPORT CONDITION MATCHES THE DESTINATION ARGUMENT, NOT ANY URL. It first accepted any quoted http(s) URL within 200 characters of the open paren, which made apoc.export.csv.query fire whenever the EXPORTED QUERY happened to quote a URL -- a STARTS WITH filter on a page url, a SKOS or schema.org namespace, a coalesce default, a feed identifier -- while the destination was a local file. Six such twins fired. The URL must now be a complete string argument immediately followed by the config map that every apoc.export signature requires, so a URL nested inside the query no longer counts. A second review round found that the config-map requirement alone was not enough: an exported query that itself CALLs apoc.load.json(url, {}) presents a URL followed by a config map, so the condition also requires the URL to be either the first argument or to follow a comma whose preceding character is not an open paren. apoc.export.*.data and .graph, whose destination is the third and second argument, are covered by that comma form and are carried as true positives so the carve-out cannot silently cost recall.
  TWO LIMITS FOUND BY REVIEW AND LEFT IN PLACE ON PURPOSE. (1) The list form apoc.cypher.runFiles(['http://host/x.cypher']) is NOT matched, because the bracket sits between the paren and the quote; it was measured silent and is a real evasion. Widening the pattern to accept the bracket was tried and rejected: it turns APOC's own documentation sentence about runFiles and allowed_protocols into a false positive, which is a worse trade for a rule whose action is alert. (2) The 200-character window in the export condition cannot cross a newline, so a remote export written across several lines with a multi-line query is missed. Letting it cross newlines was tried and rejected too: a script that exports locally and then, on the next line, calls apoc.load.json against an API with a config map becomes a false positive.
author: ATR Community
date: 2026/08/23
schema_version: '0.1'
detection_tier: pattern
maturity: test
severity: high
references:
  owasp_llm:
    - LLM02:2025
  owasp_agentic:
    - ASI02:2026
  mitre_atlas:
    - AML.T0057 - LLM Data Leakage
    - AML.T0051 - LLM Prompt Injection
  cve:
    - GHSA-2pq5-3q89-j7cc
compliance:
  owasp_agentic:
    - id: ASI02:2026
      context: Model-authored query text reaches the network, so a text-to-query agent becomes an egress and remote-execution channel for whoever influenced the prompt.
      strength: primary
  owasp_llm:
    - id: LLM02:2025
      context: 'Insecure output handling: the model''s output is executed by a database engine whose procedure library can fetch and run remote code.'
      strength: primary
  eu_ai_act:
    - article: '15'
      context: 'Article 15 cybersecurity: query text crossing into remote code execution and data egress is the manipulation the article requires resilience against.'
      strength: primary
    - article: '10'
      context: 'Article 10 data governance: the graph''s contents leaving the deployment boundary is a data-governance event that must be detectable.'
      strength: secondary
    - article: '9'
      context: Text-to-query injection is a documented risk class for database agents; detections are the Article 9 monitoring evidence.
      strength: secondary
  nist_ai_rmf:
    - function: Manage
      subcategory: MG.2.3
      context: Runtime treatment for model-authored queries that reach beyond the datastore.
      strength: primary
    - function: Map
      subcategory: MP.5.1
      context: Catalogues graph-query egress as distinct from SQL injection, which existing rules already cover.
      strength: secondary
    - function: Measure
      subcategory: MS.2.7
      context: Detection events document the security of the query-execution path as MEASURE 2.7 requires.
      strength: secondary
  iso_42001:
    - clause: '8.1'
      context: Clause 8.1 operational control over what the system may execute against its data stores.
      strength: primary
    - clause: '6.2'
      context: Preventing unauthorised data egress from the graph is an AIMS information security objective under clause 6.2.
      strength: secondary
    - clause: '8.4'
      context: Impact assessment under 8.4 must account for query-mediated egress; these events are the evidence for that path.
      strength: secondary
tags:
  category: context-exfiltration
  subcategory: query-language-egress
  scan_target: both
  confidence: medium
agent_source:
  type: mcp_exchange
  framework:
    - any
  provider:
    - any
detection:
  conditions:
    - field: content
      operator: regex
      value: \bapoc\.cypher\.(?:runFile|runFiles|runSchemaFiles?|runMany)\s*\(\s*["'](?:https?|ftp)://
      description: APOC procedure fetching and executing a Cypher script from a remote URL
    - field: content
      operator: regex
      value: \bapoc\.load\.(?:json|jsonParams|csv|csvParams|xml|html|arrow)\s*\(\s*["'](?:https?)://(?:(?:1[01]\d|12[0-6]|12[89]|1[3-5]\d|16[0-8]|17[01]|17[3-9]|18\d|19[01]|19[3-9]|2[0-4]\d|25[0-5]|1[1-9]|[2-9]\d|[1-9])\.(?:\d{1,3}\.){2}\d{1,3}|169\.254\.169\.254|172\.(?:1[0-5]|3[2-9]|[4-9]\d|1\d\d|2[0-4]\d|25[0-5]|\d)\.\d{1,3}\.\d{1,3}|192\.(?:1[0-5]\d|16[0-79]|1[7-9]\d|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.\d{1,3}\.\d{1,3})
      description: APOC load procedure pointed at a bare PUBLIC IPv4 address rather than a named service (loopback, RFC1918 and link-local are excluded; 169.254.169.254 cloud metadata is not)
    - field: content
      operator: regex
      value: \bapoc\.export\.(?:json|csv|cypher|graphml)\.(?:all|data|query|graph)\s*\(\s*(?:[^\n]{0,200}?[^\n(,\s]\s*,\s*)?["'](?:https?|ftp)://[^"'\s\n]{0,300}["']\s*,\s*[\{\$]
      description: APOC export procedure whose DESTINATION argument is a remote URL -- the URL must be a whole string argument followed by the mandatory config map, so a URL merely quoted inside the exported query does not count
  condition: any
  false_positives:
    - 'REMAINS AND IS NOT FIXABLE BY PATTERN: security writing that quotes one of these payloads verbatim -- an advisory, an OWASP writeup, a pentest finding -- fires, including inside a fenced code block. suppress_in_code_blocks is deliberately NOT set, because a text-to-query agent''s own model output routinely arrives wrapped in a ```cypher fence and suppressing it would remove the rule''s primary channel.'
    - 'REMAINS BY DESIGN: apoc.cypher.runFile against an INTERNAL http host, e.g. a nightly schema bootstrap served from an artifact server. Fetching and executing a Cypher script over the network is the primitive this rule is about, so the host is not used to excuse it.'
    - An operations job that exports a graph snapshot to a PUBLIC HTTP object store, where the destination is a whole string argument followed by the config map
    - A data pipeline that loads seed data from a public host addressed by a bare IP rather than a name
    - 'REMAINS: a tutorial or runbook that hosts a sample file on a public throwaway box and names it by IP, including the RFC 5737 documentation ranges. Those ranges cannot be excluded -- the GHSA payload this rule is built on uses 198.51.100.9, which is one of them.'
    - 'REMAINS: apoc.export.*.query whose exported query RETURNs a bare URL literal immediately followed by a bare map literal, e.g. RETURN n.a, ''https://x'', {k:1}. That is not idiomatic Cypher; separating it from a real destination argument would need paren-depth tracking, which a regex cannot do.'
response:
  actions:
    - alert
    - snapshot
  auto_response_threshold: high
  message_template: |
    [ATR-2026-02608] A graph query fetches remote code, reads from a bare IP address, or exports graph contents to a remote URL. If this statement was written by a model, treat the destination as attacker-chosen until proven otherwise.
confidence: 70
