{
  "name": "Pentest RAG Graph Query",
  "description": null,
  "active": true,
  "isArchived": false,
  "nodes": [
    {
      "parameters": {
        "path": "rag-graph",
        "httpMethod": "POST",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "node-webhook-rag-graph",
      "name": "Graph query webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "\nconst body = $input.first().json.body;\nconst type = body.query_type;\nlet cypher = '';\nlet params = {};\n\nswitch (type) {\n  case 'plugin_cves':\n    cypher = `\n      MATCH (p:Plugin) WHERE p.navn = $plugin_navn\n      OPTIONAL MATCH (p)-[:HAR_S\u00c5RBARHED]->(c:CVE)\n      OPTIONAL MATCH (s:Site)-[:K\u00d8RER_PLUGIN]->(p)\n      OPTIONAL MATCH (s)-[:HAR_FUND]->(f:Fund)-[:RELATERET_CVE]->(c)\n      OPTIONAL MATCH (f)-[:FUNDET_MED]->(t:Teknik)\n      RETURN p.navn AS plugin, p.version AS version,\n        collect(DISTINCT {cve: c.id, cvss: c.cvss, site: s.dom\u00e6ne,\n          fund: f.titel, teknik: t.kommando}) AS resultater`;\n    params = { plugin_navn: body.plugin_navn || '' };\n    break;\n\n  case 'site_history':\n    cypher = `\n      MATCH (s:Site {dom\u00e6ne: $domaene})\n      OPTIONAL MATCH (k:Kunde)-[:EJER]->(s)\n      OPTIONAL MATCH (s)-[:K\u00d8RER_PLUGIN]->(p:Plugin)\n      OPTIONAL MATCH (s)-[:HAR_FUND]->(f:Fund)\n      OPTIONAL MATCH (f)-[:FUNDET_MED]->(t:Teknik)\n      OPTIONAL MATCH (f)-[:RELATERET_CVE]->(c:CVE)\n      RETURN s.dom\u00e6ne AS domaene, s.cms AS cms, s.version AS version,\n        k.navn AS kunde,\n        collect(DISTINCT {plugin: p.navn, version: p.version}) AS plugins,\n        collect(DISTINCT {titel: f.titel, cvss: f.cvss,\n          teknik: t.kommando, cve: c.id}) AS fund`;\n    params = { domaene: body.domaene || body.dom\u00e6ne || '' };\n    break;\n\n  case 'teknik_for_fund':\n    cypher = `\n      MATCH (f:Fund)-[:FUNDET_MED]->(t:Teknik)\n      WHERE f.titel CONTAINS $fund_type OR f.beskrivelse CONTAINS $fund_type\n      RETURN t.navn AS teknik, t.kommando AS kommando, t.v\u00e6rkt\u00f8j AS vaerktoj,\n        t.beskrivelse AS beskrivelse,\n        collect(DISTINCT {fund: f.titel, cvss: f.cvss}) AS brugt_til\n      ORDER BY size(collect(f)) DESC`;\n    params = { fund_type: body.fund_type || '' };\n    break;\n\n  case 'related_sites':\n    cypher = `\n      MATCH (s1:Site {dom\u00e6ne: $domaene})-[:K\u00d8RER_PLUGIN]->(p:Plugin)<-[:K\u00d8RER_PLUGIN]-(s2:Site)\n      WHERE s1 <> s2\n      OPTIONAL MATCH (s2)-[:HAR_FUND]->(f:Fund)\n      RETURN p.navn AS faelles_plugin, s2.dom\u00e6ne AS relateret_site,\n        collect(DISTINCT {fund: f.titel, cvss: f.cvss}) AS fund_paa_relateret`;\n    params = { domaene: body.domaene || body.dom\u00e6ne || '' };\n    break;\n\n  default:\n    return [{ json: { error: 'Ukendt query_type. Brug: plugin_cves, site_history, teknik_for_fund, related_sites' }}];\n}\n\nreturn [{ json: { cypher, params, query_type: type }}];\n"
      },
      "id": "node-byg-cypher",
      "name": "Byg Cypher",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://neo4j:7474/db/neo4j/tx/commit",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"statements\": [{\"statement\": {{ JSON.stringify($json.cypher) }}, \"parameters\": {{ JSON.stringify($json.params) }}}]}",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth"
      },
      "id": "node-neo4j-graph-query",
      "name": "Neo4j graph query",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        680,
        300
      ],
      "credentials": {
        "httpBasicAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "\nconst input = $input.first().json;\nconst results = input.results?.[0];\n\nif (!results?.data?.length) {\n  return [{ json: { svar: \"Ingen data i grafen.\", data: [] }}];\n}\n\nconst columns = results.columns;\nconst rows = results.data.map(r => {\n  const obj = {};\n  columns.forEach((col, i) => { obj[col] = r.row[i]; });\n  return obj;\n});\n\nreturn [{ json: { svar: `${rows.length} resultat(er) via graph.`, data: rows, columns }}];\n"
      },
      "id": "node-formater-graph-resultat",
      "name": "Formater graph resultat",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        900,
        300
      ]
    }
  ],
  "connections": {
    "Graph query webhook": {
      "main": [
        [
          {
            "node": "Byg Cypher",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Byg Cypher": {
      "main": [
        [
          {
            "node": "Neo4j graph query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Neo4j graph query": {
      "main": [
        [
          {
            "node": "Formater graph resultat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "activeVersionId": "d5e94f5b-dda3-4e7d-8935-d7b811177ff1",
  "versionCounter": 6,
  "triggerCount": 1,
  "tags": [],
  "shared": [
    {
      "updatedAt": "2026-05-23T10:18:37.288Z",
      "createdAt": "2026-05-23T10:18:37.288Z",
      "role": "workflow:owner",
      "workflowId": "mI0FAP0BPJ79siZQ",
      "projectId": "mBwAmYhJNV3JFVeG",
      "project": {
        "updatedAt": "2026-05-23T10:16:37.814Z",
        "createdAt": "2026-05-23T10:14:57.720Z",
        "id": "mBwAmYhJNV3JFVeG",
        "name": "hannibal u-w <hannibal@ussing.com>",
        "type": "personal",
        "icon": null,
        "description": null,
        "creatorId": "ddbee286-2878-4f4d-873f-e6c8d1e1c77f"
      }
    }
  ],
  "versionMetadata": {
    "name": null,
    "description": null
  }
}