Skip to content
Innov8zigPublic

About

ScopeMoat keeps AI coding agents from silently expanding your PCI DSS scope. Built on Relate by Neo4j.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

ScopeMoat

A PCI scope guardrail for AI coding agents, built on Relate: a Git commit gate that refuses a deployment change that would pull a system into the modeled PCI DSS scope, under its stated policy, and prints the path that does it.

The blocked change

A teammate's proposed change, so the BI dashboards of Brightline (a fictional retailer) can read order status, joins BI to the orders network in deploy/compose.yaml (networks: [bi-net] becomes networks: [bi-net, orders-db-net]). Relate's path query on the changed graph returns the witness path, and the Git pre-commit hook refuses the commit:

VERDICT:  BLOCK: 1 system(s) enter scope, 0 move into the CDE
Relate path: bi-dashboards -> orders-api -> checkout-api
Opened by:   bi-dashboards joins orders-db-net (new link bi-dashboards -- orders-api)
Commit blocked by ScopeMoat (exit 1). Fix the change or ask for human review.
flowchart LR
  n0["bi-dashboards<br/>enters scope"] -->|"NEW, open link: joins orders-db-net"| n1["orders-api"]
  n1 -->|"restricted link: forwarding assumed by policy"| n2["checkout-api<br/>CDE"]
  style n2 fill:#ffd7d7,stroke:#d62728
Loading

The last hop is labelled "forwarding assumed by policy": nobody has recorded whether orders-api relays BI's traffic into checkout-api, and ScopeMoat's default, restricted_hops=in_scope, assumes it does. That default applies the PCI SSC's scoping starting point, "everything is in scope until verified otherwise" (Guidance for PCI DSS Scoping and Network Segmentation, May 2017, p. 3), and the same guidance puts systems that reach the CDE through another system in scope (p. 11). Treating an unrecorded relay as forwarding is ScopeMoat's application of that principle, not an SSC rule. Under the review policy the same change is REVIEW REQUIRED; under neither does it pass.

The recorded agent repair passes the same hook. It sets ORDER_STATUS_SOURCE: data-warehouse, reading from the warehouse replica BI already reaches, and drops orders-db-net. The run is a recorded run that is replayed, not a live model call, and its final feature read is simulated. PASS means "no modeled scope expansion", not "BI is out of scope".

Reproduce

Use a full git clone: not --depth 1, and not a ZIP download. You need Python 3.13 or newer and Git.

Step Linux / macOS Windows (PowerShell)
1. Clone git clone https://github.com/Innov8zig/ScopeMoat then cd ScopeMoat the same
2. Virtual environment python3 -m venv .venv py -3 -m venv .venv
3. Install .venv/bin/python -m pip install -r requirements.txt .\.venv\Scripts\python.exe -m pip install -r requirements.txt
4. Check every claim .venv/bin/python verify.py .\.venv\Scripts\python.exe verify.py
5. Optional: Relate CLI 1.4.0 curl -sSfL https://relatedb.ai/install.sh | bash, then open a new terminal and run relate --version irm https://relatedb.ai/install.ps1 | iex, then open a new terminal and run relate --version

Without the Relate CLI: 19 PASS, 1 SKIPPED.
With it: 20 PASS.

A shallow clone skips one agent-benchmark rescore. A ZIP download (no git) skips both agent rescores, the recorded-run replay and the explorer data check: 16 PASS, 4 SKIPPED with the Relate CLI, 15 PASS, 5 SKIPPED without it. Without Node.js, two browser checks print SKIPPED.

Explore it in Relate (no export, one command)

  • With the Relate CLI: relate --database graph/brightline.rl --read-only "$(cat queries/card_data_reappears.cypher)" (Windows: relate --database graph\brightline.rl --read-only (Get-Content queries\card_data_reappears.cypher -Raw)). Without the CLI: .venv/bin/python -c "import relate; c=relate.connect('graph/brightline.rl', read_only=True); print(list(c.execute(open('queries/card_data_reappears.cypher').read())))" (Windows: the same with .\.venv\Scripts\python.exe; keep the forward slashes inside the Python string). Expected: one row, token-vault -> chargeback-tool, "dispute handling, reads PAN", zone cde.
  • No install: the browser explorer's "Try your own Cypher" box, which runs Relate's WebAssembly build on the REACH evidence graph.

Try the gate yourself

  • Read-only, nothing changes in your clone: .venv/bin/python -m scopemoat check graph/brightline.rl changes/bi_to_orders.json --explain (Windows: .\.venv\Scripts\python.exe -m scopemoat check graph\brightline.rl changes\bi_to_orders.json --explain). It exits 1 and prints VERDICT: BLOCK: 1 system(s) enter scope, 0 move into the CDE and Relate path: bi-dashboards -> orders-api -> checkout-api, then the Cypher query with its parameters and Relate's rows before the change (7) and after it (8, the new one marking the added link in its changes column). The hook names the Compose edit ("bi-dashboards joins orders-db-net"), while check on a change file says "added by the change file"; it is the same link.
  • With the commit gate, in your clone: run .venv/bin/python -m scopemoat install-hook, make the edit above (line 25 of deploy/compose.yaml: networks: [bi-net] becomes networks: [bi-net, orders-db-net]), then git add deploy/compose.yaml and git commit (on a fresh machine, set git config user.name and user.email first). Git refuses the commit. .venv/bin/python -m scopemoat gate --explain prints the Cypher query and Relate's rows. .venv/bin/python -m t3.clean_replay t3/runs/20261130T025027Z_bi_order_status/trace.json replays the recorded proposal and repair in a temporary clone.
  • Step by step: the full walkthrough is in docs/WALKTHROUGH.md. It covers the commit gate's fail-closed rules, the review policy, the chokepoint query in Relate's CLI, where card data reappears, and the MCP servers.
  • No install: pull request #1 fails the change and passes the repair in GitHub Actions. The browser explorer reruns the hook's query in Relate's WebAssembly build.

How it uses Relate

  • Mode: single file. The baseline graph/brightline.rl is committed to the repo and opened read-only. Each check copies it into an in-memory Relate database and tests the change in a transaction that is rolled back. No server runs.
  • The graph: fictional systems with zones, network links (CONNECTS_TO, with segmentation) and data flows (SENDS, PAN or TOKEN). For each check ScopeMoat writes per-direction REACH evidence and runs Relate's Cypher 25 queries for every in-scope class before and after the change (scopemoat/relate_scope.py; the transit path query is PATH_QUERY in scopemoat/reach.py).
  • The same file serves the commit hook, gate --explain, the diagram above, Relate's own read-only MCP server (relate serve --mcp stdio --database graph/brightline.rl --read-only) and the browser explorer, which runs Relate's WebAssembly build.

What Relate decides, and what Python decides

Decision Who makes it
Which network links the staged Compose file adds Python (scopemoat/compose.py)
Which systems are in scope on recorded facts (card data systems, the CDE, systems connected to it or securing it, and systems that reach it through others), before and after the change Relate: Cypher queries over an in-memory Relate database that ScopeMoat loads from graph/brightline.rl (systems, data flows, security services) plus the per-direction REACH evidence it writes (scopemoat/relate_scope.py)
Which path puts a system in scope, and which edit opened it Relate's row (path and changes columns)
BLOCK or PASS Relate's in-scope classes
Independent check of Relate's result Python rules (scopemoat/rules_v5.py, mapped to the PCI SSC guidance in provider_reference/RULE_TO_SSC.md) recompute the confirmed classes, transit reachability included, with ScopeMoat's own Python path search and no Relate query (since v1.0.5). A disagreement, or no answer from Relate, puts the change into REVIEW REQUIRED
REVIEW REQUIRED for unresolved evidence (the worst case, every unrecorded fact treated as open) Python rules. Relate does not run this search: on Brightline it explores more than two million trails
Refusing the commit Git, through the local pre-commit hook

No AI decides scope. Relate computes confirmed scope and supplies the path shown in the demo. ScopeMoat uses Relate's result to detect scope expansion. Python independently recomputes transit reachability, and a disagreement puts the change into REVIEW REQUIRED. verify.py checks that the two agree on every frozen state. Without Relate the demo change drops to REVIEW REQUIRED and loses its path. Replacing only Relate's transit query with ScopeMoat's separate Python search still gives BLOCK, because the in-scope classes still come from Relate's queries. Run .venv/bin/python experiments/relate_ablation.py with shipped (BLOCK), no_relate (REVIEW REQUIRED) or python_transit (BLOCK) (experiments/relate_ablation.py).

Checked against answer keys

  • Published answer keys. Result: against keys it did not write (PCI SSC's scoping examples, 2017: 8 of 10 matched, 2 stricter; 2024: 15 of 15; AWS and Google's PCI reference architectures, 25 labels: 15 match, 3 stricter, 7 UNRESOLVED), ScopeMoat never put a system out of scope that the publisher put in scope (0 looser). Key limitation: every graph was built by the author from the published text, and the 7 UNRESOLVED labels are held for review because the source states no control (publishers label 4 of them in scope). Full tables
  • The author's own keys. Result: on 40 frozen cases it passed none of the changes the key blocks or holds for review (0 false PASS); a one-hop check passed 15 and plain reachability 16. Key limitation: the author wrote that key and used 17 of the cases to develop the rules, and two agent experiments, giving an agent the gate's output or a raw Relate query tool, showed no demonstrated improvement in the agent's decisions. ScopeMoat's value is enforcement at commit time and a path a reviewer can check, not a smarter agent. Full tables

What the graph tells an auditor, a company and a red team

Scope labels used below: CDE (stores, processes or transmits card data), OTHER (in scope through a connection or a path), UNRESOLVED (the answer depends on a fact nobody recorded, so it is held for review), OUT (not in scope).

  • Auditor: the first fact to verify. On the Brightline snapshot before the edit, all 7 transit paths share one hop, orders-api -> checkout-api, whose forwarding is unrecorded (acceptance.py C1, query queries/chokepoint.cypher). Confirming that orders-api does not forward moves those 7 systems from OTHER to UNRESOLVED, not to OUT, because each still depends on other unrecorded facts (acceptance.py C2).
  • To see the shared hop yourself: .venv/bin/python -m scopemoat export-reach graph/brightline.rl reach.rl, then relate --database reach.rl --read-only "$(cat queries/chokepoint.cypher)" (needs the Relate CLI; delete an old reach.rl first). The first row is hop orders-api->checkout-api, restricted, relay unrecorded, 7 of 7 paths. Windows commands, the count breakdown and a no-CLI version are in docs/WALKTHROUGH.md (step 5).
  • Company: which missing fact clears which system. Every UNRESOLVED label in the provider run lists the missing control it depends on, in the UNRESOLVED table. One example: recording a control on the AWS API Gateway link moves api-gateway from UNRESOLVED to in scope, matching AWS (sensitivity variants). In the Google GKE reconstruction, removing one recorded denial moves Google's 7 out-of-scope services to UNRESOLVED (LABELS.md).
  • Red team: the path, hop by hop. For a changed system, gate --explain prints Relate's row for the path to the CDE. The row gives each hop's segmentation (none, then restricted) and marks which hop the edit added. experiments/twin_replay.py prints the same row, and shows the path disappearing when one forwarding fact is recorded.

Limitations

  • Card-data endpoints: the cardholder's browser counts as CDE because it is one end of a card-data flow, so a public web app it also uses becomes connected-to, stricter than Google's label (details).
  • Read-only and write-only connections cannot be expressed. A connection the CDE initiates counts as connected-to, so two Google labels come out stricter (GAPS.md).
  • When a one-way connection's control is unstated, its direction is lost (GAPS.md).
  • "A connection exists, its control is not stated" is recorded as missing evidence. All 7 UNRESOLVED provider labels come from it (GAPS.md).
  • Default forwarding: a restricted hop with no recorded relay fact forwards under in_scope. This applies the SSC's "in scope until verified" principle but is not an SSC rule. The demo BLOCK depends on it, and so do two sensitivity variants (RULE_TO_SSC.md).
  • Segmentation is a recorded property, not linked to a test report. Firewalls, people and processes are not modeled. The commit gate understands one change type: services on plain Compose networks. Anything else is REVIEW REQUIRED, and git commit --no-verify skips the local hook. The gate models network membership, not application settings such as a database URL in an environment variable. The local hook runs the engine in your working tree.
  • A scoping aid on modeled graphs, not a QSA assessment. PASS means "no modeled scope expansion".

Pull request check

The same gate runs on every pull request (.github/workflows/scopemoat.yml, ci/pr_check.py). The result is the gate's own exit code: PASS succeeds, and BLOCK, REVIEW REQUIRED and ERROR fail. Pull request #1 is the live demo. It is kept open and is not meant to be merged. The check runs the base branch's engine, and a pull request that changes the gate itself (scopemoat/, scopeguard/, ci/, .github/, requirements.txt) is held for review. GitHub runs a pull request's own workflow file, so changes under .github/ still need a human reviewer.

Files

Path What it is
scopemoat/ engine, commit gate, CLI and the read-only MCP server (python -m scopemoat.mcp)
scopeguard/ compatibility alias from the Dec 1, 2026 rename (the same module objects), so frozen scripts and hooks written before the rename still run
graph/brightline.rl, queries/ the Relate store (single file) and the published Cypher
deploy/compose.yaml, changes/, fixtures/ the file the gate checks, change files, alternate baselines
provider_reference/ AWS and Google reference architectures: graphs, labels, scorer, results, baselines, GAPS.md
experiments/ PCI SSC 2017 and 2024 examples, the Google GKE reconstruction, a replayed twin, the Relate ablation, the Cypher rules
t3/, t4/, t5/ the recorded agent run and replay, the agent benchmark, the pre-registered agent A/B
blind/ the frozen 40-case comparison with simpler checks
explorer/ the browser explorer and scope page (Relate WebAssembly)
verify.py, acceptance.py, EVIDENCE.md the release checks in one command, the full check suite, and the evidence index

Records under blind/, t3/runs/, t4/runs/ and provider_reference/results/ are frozen and are not edited after they are committed. A rerun is reported as a separate run.

How this was built (AI use)

  • Claude (Anthropic) helped write and test the code and the documents. claude-sonnet-5-5 is the coding agent under test in t3/, t4/ and t5/.
  • ChatGPT (OpenAI) reviewed the engine and the Relate integration in hostile review rounds. Codex (OpenAI) independently re-ran the benchmark scorer's freeze candidates.
  • No model decides a verdict: Relate's Cypher computes the in-scope classes and paths, the Python rules recheck them, and Python handles unresolved evidence.

License and notices

Copyright 2026 Daniel L. Ziegler. Licensed under the Apache License 2.0; see LICENSE and NOTICE. The license covers the code and grants no rights to the ScopeMoat name. Provided as is, without warranty.

  • A scoping aid, not legal advice and not a PCI DSS assessment.
  • Brightline and its data are fictional. experiments/w3_gke and provider_reference/ reconstruct public reference architectures from published documentation. No real company's network or data is modeled. Not affiliated with or endorsed by Google, AWS or the PCI SSC.
  • Built for the Relate by Neo4j Hackathon. Not affiliated with, sponsored by or endorsed by Neo4j, Inc. Neo4j is a trademark of Neo4j, Inc.
  • PCI DSS is a trademark of the PCI Security Standards Council, which has not reviewed or endorsed this project.

About

ScopeMoat keeps AI coding agents from silently expanding your PCI DSS scope. Built on Relate by Neo4j.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages