This document defines the Neo4j graph database schema for storing reconnaissance data. The schema is designed to enable attack chain analysis by connecting all discovered assets, services, technologies, and vulnerabilities in a navigable graph structure.
- Hierarchical Ownership: All nodes trace back to a Domain with
user_idandproject_id. ADomainis a registrable domain (the org, read from the Public Suffix List): one per org however many scan roots a project has under it. A deeper scan root that is a target is aSubdomainof its org withis_scan_root: true. - Attack Surface Mapping: Every potential entry point is modeled (ports, URLs, parameters)
- Technology-Vulnerability Linkage: Technologies connect to known CVEs for risk assessment
- No Redundancy: Information stored once, relationships handle connections
- Query Efficiency: Optimized for path traversal (attack chains)
- Multi-Tenant Isolation: Every ENTITY node has
user_id+project_idfor tenant filtering. The three GLOBAL REFERENCE labels are the deliberate exception - see below.
This document no longer lists node labels, their properties, or the
relationships between them. It used to, and that was the problem: the same
facts were written out three times - here, in the text-to-cypher prompt, and in
graph_db/schema.py - so adding a node type meant editing all three, and
forgetting one failed in silence. No error, just an agent that could never
query the new node type, or a documented property that nothing writes.
There is now one declaration.
| What you want | Where it is |
|---|---|
| Every label, property and relationship, with meaning | graph_db/schema_sections.md |
| The same, parsed into fields a program can read | graph_db/schema_catalog.py |
| A label's uniqueness key (its MERGE identity) | graph_db/schema_keys.py |
| The rendered document an agent is served | render_schema() in graph_db/schema_render.py |
# the whole schema, as the agent sees it
python3 -c "from graph_db.schema_render import render_schema; print(render_schema())"
# one label
python3 -c "from graph_db.schema_render import render_label; print(render_label('Subdomain'))"
# a label's properties as data
python3 -c "from graph_db.schema_catalog import label_properties; print(label_properties('Subdomain'))"Or ask the running agent, which serves the same content over both surfaces:
the graph_schema tool in a chat session, or graph_schema over the inbound
MCP server. Neither needs a database.
Edit graph_db/schema_sections.md, then re-seed:
python3 tooling/scripts/seed_schema_catalog.pygraph_db/schema.py renders its CREATE CONSTRAINT statements from
schema_keys.py, so a new label's uniqueness key is declared once and the
database follows.
The DDL is generated too, and init_schema applies all of it on every
scan-container spawn and every agent graph call. Every statement is guarded by
IF NOT EXISTS / IF EXISTS, so it is idempotent.
| Count | Source | |
|---|---|---|
CREATE CONSTRAINT |
45 | rendered by schema.build_constraints() from schema_keys.py |
CREATE INDEX |
77, each with its own name | TENANT_INDEXES + ADDITIONAL_INDEXES in schema.py |
DROP (legacy, unconditional) |
41 | DROP_LEGACY_CONSTRAINTS in schema.py |
DROP (legacy-shaped, conditional) |
3 | LEGACY_SHAPED_CONSTRAINTS: drop_legacy_shaped_constraints() drops one only while the live constraint's key differs from schema_keys.py, so a live tenant-scoped constraint is never rebuilt |
tests/test_schema_legacy_drops.py fails if an unconditional drop names a
constraint or index the code still creates, or if two indexes share a name.
# exactly what the database gets, in order
docker compose exec agent python -c "
from graph_db.schema import DROP_LEGACY_CONSTRAINTS, CONSTRAINTS, TENANT_INDEXES, ADDITIONAL_INDEXES
for s in DROP_LEGACY_CONSTRAINTS + CONSTRAINTS + TENANT_INDEXES + ADDITIONAL_INDEXES: print(s)"This file used to carry that listing verbatim. It was accurate - checked name by name at removal - but being accurate was never the point: it was a copy that had to be maintained by hand, and the next label added would have been the one nobody remembered to add here.
Renaming a constraint is a migration, not a refactor. A same-name
CREATE ... IF NOT EXISTS against a database that still holds the old
constraint is a silent no-op, so a changed key needs a new name AND a matching
entry in DROP_LEGACY_CONSTRAINTS.
Four tests, and they fail rather than warn:
- every label declared in
schema_keys.pyhas catalog documentation - every relationship and property the CODE writes is documented
(
recon/tests/test_graph_writes_documented.py, hermetic, runs in the unit gate./redamon.sh test unit) - every relationship and property in a LIVE graph is documented
(
recon/tests/test_schema_catalog.py, skips without a database) - no query reads a relationship nothing writes - this one found a real bug,
a modal reporting zero because it read
HAS_SERVICEwhere every writer createsRUNS_SERVICE
The parts a generator cannot produce: why the graph is shaped the way it is,
the multi-tenant strategy, the Muted label's rationale, how Scan Timeline
versions live in Postgres rather than in the graph, and why the AI agent's own
findings reuse Vulnerability.
For query GUIDANCE - how to phrase a traversal, which node types to union, the
gotchas - read the text-to-cypher prompt's rule sections in
agentic/prompts/base.py, which is what the agent is actually instructed with.
CVE, MitreData and Capec are the public NVD/MITRE catalogue, not findings.
They are UNIQUE on their natural id (c.id, m.id, cap.capec_id), so there is
exactly ONE node per CVE for the whole database, shared by every project that
finds it. They carry no user_id / project_id.
// entity node - tenant-scoped
MERGE (v:Vulnerability {id: $id, user_id: $uid, project_id: $pid})
// reference node - natural id ONLY, never a tenant key
MERGE (c:CVE {id: $cve_id})
ON CREATE SET c.source = 'nuclei' // provenance: first writer winsThree rules follow from that, each of which was a real defect:
- Never stamp a tenant on one.
SET c += propswithuser_id/project_idin the dict made the last project to touch a CVE its owner, and every project-scoped delete then removed the shared node along with every other project's links to it. - Never key a MERGE on the tenant triple.
MERGE (c:CVE {id, user_id, project_id})collides with the uniqueness constraint onidand raisesConstraintValidationFailedwhenever the CVE already exists. - Never delete one by project. Project wipes exclude these labels and then
sweep the nodes no project can REACH any more. Reachability, not degree: the
catalogue is internally linked as
CVE -> MitreData -> Capec, so an unreferenced CVE still holds its CWE.
Reading them is by traversal, not by tenant filter. graph_db/tenant_filter.py
exempts these labels from injection - a filter on an unstamped node matches
nothing - but only for a pattern that names reference labels ONLY, and only in a
query that carries a tenant-scoped pattern of its own:
MATCH (t:Technology)-[:HAS_KNOWN_CVE]->(c:CVE) RETURN c.id, c.cvss // ✅
MATCH (c:CVE) RETURN c.id // ❌ refusedThe idx_cve_tenant / idx_mitredata_tenant / idx_capec_tenant indexes
indexed a property these nodes no longer carry, so init_schema drops them:
they are listed in DROP_LEGACY_CONSTRAINTS (graph_db/schema.py) and go on the
next connection to any existing database.
Muted is the one label that is added to a node rather than being its type.
When an operator suppresses a finding as noise it keeps its functional label and
gains this one, so a suppressed Nuclei finding is :Vulnerability:Muted.
// mute - add the label, keep the type
MATCH (v:Vulnerability {id: $id, user_id: $uid, project_id: $pid})
SET v:Muted, v.muted = true, v.muted_at = datetime(), v.muted_by = $uid
// unmute - lossless, nothing was destroyed
MATCH (v:Vulnerability:Muted {id: $id, user_id: $uid, project_id: $pid})
REMOVE v:Muted, v.muted, v.muted_at, v.muted_by, v.muted_reasonOnly finding-bearing nodes may be muted. Vulnerability, JsReconFinding,
Secret, MultiscannerFinding, GithubSecret, GithubSensitiveFile,
MalPackageFinding, ExploitGvm. Asset and reference nodes (IP, Port,
Domain, Endpoint, CVE, ...) are context: muting one would orphan the real
findings hanging off it.
muted_by holds the user id of the person who muted the finding, or
rule:<kind>/<rule id> when a mute rule
did (rule:<kind>/allowlist in allowlist mode), with muted_reason set to
Filter rule: <name>.
The third provenance is an external agent muting over the inbound MCP server
(mute_findings), with an operator's access token that holds the opt-in
triage:mute permission. muted_by stays that operator's user id, because the
token carries their authority, and two more properties record how it arrived:
muted_channel = 'mcp' and muted_token, the token's display prefix (never the
token). Only mute_findings_delegated in
graph_db/mixins/recon/triage_mixin.py writes them. Every unmute removes them,
and every other mute (a person's, a rule's) clears them, so a later mute never
inherits an old token's stamp. tooling/scripts/mute_provenance_cleanup.py
strips leftovers from unmuted findings after a rollback and roll-forward.
An agent's mute carries its owner's delegated authority, so the prune (kept,
stamped stale_since), the rule sweep (never touched) and partial-recon
seeding (excluded) treat it exactly as a person's. Every display and report
treats it as an agent's: Muted Nodes, the MCP listings and the pentest report
count it apart from people's, per token. It is never allowed to overwrite an
existing mute, to hide a proven finding, or to hide one a person brought back
(one with an exemption).
The kinds differ in what they mean and in how they are kept:
- The one sweep that applies rules (
apply_node_filtersingraph_db/mixins/node_filter_mixin.py) only mutes, re-attributes or releases RULE mutes. A person's mute is never touched, in either direction, and it never writesupdated_at. - A rule never mutes a guarded finding: one with
triage_source = 'human'(a person's verdict, whatever its status),triage_status = 'confirmed'or atriage_proof(the agent or a triage run proved it), or one aChainFindingpoints at withCONFIRMS. Guards only ever block: a finding that becomes guarded while a rule has it muted is released at the next sweep, and the mute write re-checks them so a verdict set mid-sweep is never hidden (graph_db/node_filters/guards.py). - The ingest-then-prune keep predicate is
(n:Muted AND NOT coalesce(n.muted_by,'') STARTS WITH 'rule:') OR coalesce(n.triage_source,'') = 'human': a rule mute is not a judgement of that finding, so a stale one is pruned. - The rules (
project_node_filters) and the operator's exemptions (node_filter_exemptions: a node someone unmuted, which no rule may mute again) live in Postgres, keyed by project, finding label and natural key, not on the node: the prune, the recon asset clear, version activation and import would each delete a node property. What a rule may match is declared ingraph_db/node_filters/catalog.yaml.
Adding is what makes unmute lossless and what makes mute survive a re-scan.
Recon re-runs MERGE (v:Vulnerability {id, user_id, project_id}), which still
matches a :Vulnerability:Muted node, refreshes its scan properties and leaves
the mute intact. Had mute replaced the functional label, that MERGE would match
nothing and create a second, un-muted duplicate of the same finding, because
vulnerability_tenant_unique is on :Vulnerability(id, user_id, project_id)
and the duplicate would satisfy it.
Everywhere else in this schema a node has exactly ONE label, because the graph
renderer and several aggregations take labels[0] and Neo4j does not order
labels. A muted node is dual-labelled, so its labels[0] is nondeterministic.
That is safe only because of a containment rule that must hold for every read
path: no labels[0] consumer ever receives a muted node. Excluding :Muted
is therefore a correctness requirement, not only a visibility one - a reader that
forgets the filter both leaks a suppressed finding and may mis-type it as
"Muted". The one legitimate reader of muted nodes is the list_muted fixed op behind
Muted Nodes (and the MCP list_muted_findings tool), which derives the type as
[l IN labels(n) WHERE l <> 'Muted'][0] and never uses labels[0]; the
node-filter sweep reads them only to reconcile its own rule mutes.
graph_db/tenant_filter.py rewrites every node pattern to carry the tenant keys;
the same rewrite now also excludes Muted, so the guarantee rides on the
mechanism that already covers every query shape the agent can emit:
MATCH (v:Vulnerability) -> MATCH (v:Vulnerability&!Muted {user_id: .., project_id: ..})
MATCH (n) -> MATCH (n:!Muted {user_id: .., project_id: ..})
MATCH (n:A|B) -> MATCH (n:(A|B)&!Muted {user_id: .., project_id: ..})A query that names the label itself is refused rather than scoped, so the agent has no vocabulary for mute at all:
MATCH (v:Vulnerability&!Muted {...}) RETURN v // ✅ what injection produces
MATCH (n:Muted) RETURN n // ❌ refused: reserved label
MATCH (v:Vulnerability) WHERE NOT v:Muted ... // ❌ refused: exclusion is automaticReaders that hand-write their own Cypher and never reach scope_query are
separate enforcement sites and must exclude :Muted themselves: the /graph
loader (webapp/src/app/api/graph/liveRead.ts), the fixed-op node-type query
(agentic/api.py _GRAPH_TYPES_CYPHER), analytics, insights and reports.
This schema uses Logical Partitioning with Composite Indexes for multi-tenant isolation.
Every node type includes user_id and project_id properties with composite indexes.
┌─────────────────────────────────────────────────────────────────┐
│ Single Neo4j Database │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ User A │ │ User B │ │ User C │ ... │
│ │ Project 1 │ │ Project 1 │ │ Project 1 │ │
│ │ Project 2 │ │ Project 2 │ │ Project 2 │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
│ Composite Constraints: (fields, user_id, project_id) IS UNIQUE │
│ Query Pattern: Always filter by tenant FIRST │
└─────────────────────────────────────────────────────────────────┘
All queries MUST start by filtering on user_id and project_id to leverage indexes:
// ✅ CORRECT - Uses composite index, scans only tenant's data
MATCH (d:Domain {user_id: $userId, project_id: $projectId})
-[:HAS_SUBDOMAIN]->(s:Subdomain)
-[:RESOLVES_TO]->(ip:IP)
-[:HAS_PORT]->(p:Port)
RETURN d, s, ip, p
// ❌ WRONG - Full graph scan, affects all tenants
MATCH (v:Vulnerability {severity: 'critical'})
RETURN vA query that starts from a target name matches the org Domain and filters the
Subdomains, never Domain {name: <scan root>}: a project scoped to
*.api.example.com has Domain {name: 'example.com'} and its hosts under it.
MATCH (d:Domain {user_id: $userId, project_id: $projectId, name: 'example.com'})
-[:HAS_SUBDOMAIN]->(s:Subdomain)
WHERE s.name = 'api.example.com' OR s.name ENDS WITH '.api.example.com'
RETURN sThe org Domain also carries the run's coverage record (recon_coverage_at,
recon_coverage_gaps, recon_skipped_hosts, recon_nuclei_truncated), merged
across the run's scan roots of that org (recon_coverage_roots, keyed by
recon_coverage_run), and openapi_source_status entries prefixed with their
scan root (<scanRoot>|<id>|<hash>|<code>|<time>).
That record lists what a run CUT. What a module did on each web host lives on the
host instead: flat <module>_at / _status / _inputs / _outputs / _reason
properties on BaseURL (a property cannot hold a map), written by JS Recon and
Nuclei for every host they considered and by MATCH only. A host without its
stamp reads "not scanned" only when the module stamped another host of the
project, "coverage not recorded" otherwise. See README.RECON, "Per-host coverage
stamps".
Node.js API (EKS/ECS Fargate)
│
├── ElastiCache Redis ─── Query caching per tenant
│
└── Neo4j AuraDB / Neo4j on EC2
│
└── Composite indexes on (user_id, project_id)
| Phase | Users | Strategy | AWS Services |
|---|---|---|---|
| MVP | 0-100 | Single DB + Indexes | ECS Fargate, Neo4j AuraDB |
| Growth | 100-1K | Read Replicas | EKS, AuraDB Professional |
| Scale | 1K+ | Sharded by User Pools | EKS Multi-AZ, Neo4j Cluster |
- Deduplication: Before creating nodes, check if they exist (MERGE vs CREATE)
- Timestamps: Store as Neo4j datetime type for proper querying
- Arrays: Neo4j supports array properties (tags, references, etc.)
- Large Text: Keep descriptions under 10KB, store curl_command and request/response separately if needed
- Batch Import: For large scans, use APOC procedures for batch imports
The Neo4j schema does not change for the Scan Timeline. There is no version
node, no version property, and no :VERSION_OF relationship — nothing in this
document is modified by the feature.
- The live Neo4j graph IS the current version. It behaves exactly as before: a full recon wipes and rebuilds it. Everything that reads or writes the graph (the agent, partial recon, the ~30 RedZone/analytics endpoints, saved views) therefore sees whichever version is active, unchanged.
- A past version is a saved snapshot: the project's subgraph, serialized and gzipped into Postgres. Past versions are read-only and never present in Neo4j, so old data can never reach the agent or an analytics query.
- Snapshots are taken before a new full scan overwrites the graph — and only when the user chooses to keep it (the "new version vs overwrite" modal).
| Model | Purpose |
|---|---|
ScanVersion |
One point-in-time identity for the recon graph. isCurrent = true on exactly one row per project — that row IS the live graph and has snapshot = null. A frozen (past) version carries snapshot bytes. @@unique([projectId, seq]) keeps numbering from forking. |
ScanJob |
Run history: trigger (manual/scheduled), mode, status (queued/running/completed/failed/canceled/deferred_ram), who started it, timings, ramReason. kind records WHICH scan the row is for (full_recon | partial_recon | gvm | github_hunt | trufflehog | supply_chain | supply_chain_repo | ai_attack) — before it, a directly-started non-recon run had no record at all. runId is the orchestrator run id for the kinds that allow several concurrent runs per project (partial_recon, ai_attack), and is empty for the one-per-project kinds. |
ScanSchedule |
A future/recurring full scan: once / interval / cron (UTC), plus the scanMode to use for the previous graph. |
Project also gains the activation lock columns activation_state,
activation_started_at, activation_version_id (see below).
Snapshots are stored in the export (restore-fidelity) format, not the UI render shape, because a snapshot must be restorable back into Neo4j:
Reference nodes are never captured, their links are. CVE, MitreData and
Capec carry no tenant key and are shared by every project, so a snapshot or a
project export (manifest 1.1.0, neo4j/reference_links.json) holds no such node
and no property of one. Each edge to one is a link record: the project end by
export id, the other end (the null id) by its natural key. A restore validates
the label against the catalogue and the key against its shape, MATCHes the node
(never MERGE, never SET; label and key property from a fixed map), and skips and
counts a link whose node is missing. A payload that carries a reference node
anyway (one stored before the catalogue lost its tenant stamp) has the node
dropped and its edges turned into link records. Activation sweeps orphaned
reference nodes only after the
restore, so a CVE only this project linked survives the swap
(webapp/src/lib/graphReferenceLinks.ts).
The graph screen renders a version by converting this to the same
{ nodes, links } payload /api/graph returns, so the canvas, the clustering and
the node/link tables are unchanged.
Agent session nodes are excluded. The AttackChain family (AttackChain,
ChainStep, ChainFinding, ChainDecision, ChainFailure) is agent-run state,
not recon state: it is filtered out of every capture, and preserved (not deleted)
when a version is activated. Chains stay conversation-scoped exactly as documented
in the Attack Chain Graph section above.
Viewing a version only renders its bytes. Activating it swaps the live graph:
- freeze the outgoing current version from the live graph (not from its old stored bytes — partial recon may have edited it since),
- delete the live recon graph excluding the AttackChain family, and restore the target version through the same code path the project import uses,
- only then move the
isCurrentpointer, and invalidate the graph cache.
A failure in step 1 aborts before anything is deleted; a failure in step 2 leaves both endpoints intact in Postgres, so the activation is simply retriable.
Activation holds a project activation lock (Project.activation_state) and is
mutually exclusive with a full scan, a partial recon run, an agent session, and the
scan scheduler — in both directions.
Only the recon graph is versioned. GVM/secret-scan output files, remediations,
reports and captured HTTP traffic are project-level and always reflect the latest
scan, whichever version is active. The AI agent's own findings
(Vulnerability {source: "agent"}, below) are project-level too: a capture
leaves them out, step 2 never deletes them, and they are re-anchored to whatever
the restored version holds.
When the AI agent finds a weakness on a host recon knows, it is promoted from
session history (ChainFinding) into a Vulnerability with source: "agent",
not into a label of its own. About twenty sources already share
Vulnerability, and source tells them apart, so:
- every reader of findings (the Priority Board, triage, the report, Insights, the mute rules, the MCP and Navigator tools) already includes it, with no reader learning a ninth finding label;
- recon's clear never deletes a finding label, and its prune names only its own
sources, so another subsystem's findings in that label survive recon;
agentsits inNON_RECON_SOURCESbeside GVM's, the supply chain's and the AI attack-surface scanners'; - agent-only facts carry an
agent_prefix (agent_proven,agent_anchor_state, ...), and the properties a scanner's reader would misread on it are never set.
A ChainFinding stays what it was: one node per sighting, deleted with its chat.
The Vulnerability is one node per weakness, host, port, route, method,
parameter and CVE, with exactly one recon parent, so it is never disconnected
from the surface it describes and every later sighting lands on the same node.
How it is written and re-attached is in
README.GRAPH_DB.md.
- GVMScan, GVMVulnerability, DetectedProduct, OSFingerprint nodes (GVM integration - designed but not yet created by code; GVM vulns currently stored as Vulnerability nodes with source="gvm"; Traceroute nodes now implemented)
Screenshotnodes linking to stored images