Skip to content

fix(subgraph,contracts): enforce write ownership via sender-recording DataEdge - #676

Merged
tmigone merged 2 commits into
mainfrom
audit/high-fact-write-authorization
Nov 30, 2026
Merged

tmigone merged 2 commits into
mainfrom
audit/high-fact-write-authorization

Conversation

@tmigone

@tmigone tmigone commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

What

Anyone can currently overwrite, tombstone or reassign any user's memories: take a fact id from the public subgraph, call the DataEdge contract directly with that id and someone else's address, and the subgraph accepts it — the contract emits only the payload, not the caller, so ownership is whatever the payload claims.

This PR adds EventfulDataEdgeV2, which emits msg.sender, and a new subgraph that derives each fact's owner from that sender instead of the payload. Entities are keyed by sender:id — a per-owner namespace — so a write from one address can neither touch another account's facts nor front-run/squat an id another account will use. The key is computed idempotently (a payload id already prefixed with the caller's own address is used as-is), so clients round-trip the returned fact.id on forget/pin/retype with no change.

It is a clean break: the new subgraph indexes V2 only, from its deploy block, with no legacy data source. Production is pre-launch, so every existing on-chain fact is our own test data; those rows drop out of the product when the relay repoints to V2, which is intentional.

Clients need no code change for the mechanism — the composite id is transparent to them, and they pick up the V2 data_edge_address from /v1/billing/status, so chain-aware clients need no release. The exception is the hardcoded fallback address baked into the Python client and the ZeroClaw Rust crate, which need a follow-up release.

Warning

Not deployed. The V2 contract address and start block in the manifests are placeholders; the subgraph protects nothing until the contract is deployed and the staging exploit-replay E2E passes.

Verification

The vulnerability was reproduced on staging (Gnosis chain 100), DataEdge 0xE7a4D2677B686e13775Ba9092631089e35F0BB91, fact id audit-11-bb3eadb2:

  • victim (0x24039B90C7Dacda99e8935C7C423112dCedDe7C3) wrote the fact — tx 0xeac1688cb12475b7b876cb3108a71d008fa8d93c7a15538fd0ad13da8304da55
  • attacker (0xE8020eb0fa58828C35d33242FBf1E1AC8c36dC8E, an unrelated wallet) tombstoned it, isActive → false — tx 0x3a8f551f27e38ddfa67255b2a233d62bb325744402f93471664a7ecf59519c46
  • the same attacker reassigned its owner to itself — tx 0x73ee61d9fc2da7bdab1fe980a62cb44e0a035393f6cfdcd9018c76d0669be2a2

Other checks:

  • contracts: 41 forge tests pass, including 5 new EventfulDataEdgeV2 tests (sender == caller, distinct senders for the same payload, permissionless append, receive() emits nothing).
  • subgraph: graph codegen + graph build pass for the default, mainnet and staging manifests (V2-only, a single data source into one entity store).
  • Pending (deploy-gated): re-running the exploit above against V2 to confirm the cross-owner write is rejected, plus a normal client write→index→recall. Code-complete but not validated end-to-end until this runs.

Checklist

  • No recovery phrase, API key, or other secret appears anywhere in this diff or its logs.
  • Docs touched by this change are updated (guides / feature-comparison / CLAUDE.md matrix where relevant). (N/A — no user-facing surface changes; the DataEdge contract family in CLAUDE.md should be updated when V2 is actually deployed.)
  • For behavior changes: E2E validated against staging (never production). (Pending the deploy.)

@tmigone
tmigone added this pull request to stack #675 October 15, 2026 19:03
@p-diogo

p-diogo commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Thanks @tmigone, confirmed on our side, and a really clear write-up. Here's the plan to get this merged and shipped, so it lives in one place. This stays your PR. I'll review and handle the deploy steps that need infra access.

Production impact: we checked every write ever made to the production DataEdge (1,321 logs, the contract's full history). Each one came through the EntryPoint from the account named as the owner, with no cross-owner writes. Production is also still pre-launch, so everything on-chain there is our own test data.

That simplifies this a lot. We don't need to carry existing facts over, so V2 can be a clean break: a new subgraph that indexes only V2 from its deploy block, with no legacy data source and no endBlock freeze.

Before merge (you)

  • Rebase on main (conflicts with chore: point repo references at the graphprotocol org #677).
  • Drop the legacy data source and handleLog. The manifests carry only V2.
  • Id squatting. V2 is first-writer-wins on a client-chosen id, and the id is visible in the mempool before the write lands. Someone can front-run a create with the same id from their own address. The owner's write is then rejected, so the fact never indexes and the client can't tell. Keying the entity by (sender, id) removes cross-owner collisions altogether, which leaves nothing to authorize. One catch: clients pass fact.id back as the payload id when they tombstone, so the mapping would also need to accept an id that's already prefixed with the sender's own address. Open to other approaches.
  • Matchstick tests covering:
    • owner = sender
    • a write from another account can't create, update, tombstone or reassign a fact
    • same-owner update and tombstone work
    • batched (executeBatch) writes index under the Smart Account
  • Deploy script: fail on an unrecognised target instead of falling back to the staging salt.
  • Regenerate .gas-snapshot (it still carries 23 SessionKeyModuleTest entries that chore: remove deprecated contracts and dead code #673 removes), and make the expectEmit assertions check the sender topic.
  • Manifests: real staging values after deploy step 1, and prod values in the prod deploy step, not as placeholders on main.

Deploy sequence (me, after merge)

  1. Deploy V2 and the new subgraph to staging.
  2. Re-run your staging repro against V2 as the E2E. Cross-owner writes should be rejected, and normal client writes (single and batched) should index and recall.
  3. Point the staging relay at V2 and run the batch E2E. Chain-aware clients pick up the new address from /v1/billing/status, so no release is needed.
  4. Production: deploy V2, publish the subgraph to the network, and repoint the relay once the Gateway serves it at head. Existing production facts drop out of the product at this point, intentionally.
  5. Update the clients' hardcoded fallback address in their next releases. Until then, two kinds of writes land on the old contract and won't show up: writes from a client that can't reach billing, and all ZeroClaw writes, since it always uses the constant.

@p-diogo
p-diogo force-pushed the audit/high-fact-write-authorization branch from 0a3f2eb to ca2cdd5 Compare October 25, 2026 20:42
@tmigone
tmigone force-pushed the docs/key-derivation-and-stale-comments branch from 1023666 to 08e2eb3 Compare November 24, 2026 20:18
Base automatically changed from docs/key-derivation-and-stale-comments to main November 24, 2026 20:23
Signed-off-by: Tomás Migone <tomas@thegraph.foundation>
@tmigone
tmigone force-pushed the audit/high-fact-write-authorization branch from ca2cdd5 to 5fdbcfc Compare November 25, 2026 20:02
@tmigone
tmigone removed this pull request from stack #675 November 25, 2026 20:02
@tmigone

tmigone commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

@p-diogo I've rebased and reworked the PR to prevent the id squatting with the composite id. All of your suggestions should be checked except for:

  • Matchstick tests - currently matchstick is not setup for this subgraph, I suggest we do it in a different PR
  • Manifests - need to update after the new contracts are deployed.

@p-diogo

p-diogo commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

@tmigone, thanks! We replayed your attacks on a local indexer. Delete, reassign and squat all fail on this branch, and the owner's own tombstone works with the composite id.

Two small things before we merge:

  • subgraph/subgraph.yaml still declares V1, so a build with the default manifest fails. Please move it to V2.
  • Please update the description. It still mentions the legacy data source and says that clients need no change.

Agreed on your two open items: Matchstick goes in a separate PR, and we fill in the manifests after deployment.

We will handle the rest after the merge: mapping tests, deployment, and your staging replay. We also need a client change, and that was our mistake. Clients look up the bare UUID after some writes, which returns null now that the id is sender:uuid. We will query both ids, filtered by owner. #846 also edits mapping.ts, and we will rebase it onto yours.

Signed-off-by: Tomás Migone <tomas@thegraph.foundation>
@tmigone
tmigone merged commit 25ccf89 into main Nov 30, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants