~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/zlay

atproto relay in zig · mirror of https://tangled.org/zat.dev/zlay

0
0
109 lines · 5.9 KB Raw History
# CAR verification and unresolved signing keys

Review of [War on CARs](https://data-service-diaries.pckt.blog/war-on-cars-5xa5v73)
(fig, 2026-09-16), against zlay `d6045ec`. Fetching origin on 2026-09-20
confirmed that the local checkout matches `origin/main`. Deployment state was
not inspected.

Tracking issue: **Do not forward unverified events on signing-key cache misses**,
published by `zzstoatzz.io` after confirming there were no open zlay issues.
Authoritative record:
`at://did:plc:xbtmt2zjwlrfegqvch7fboei/sh.tangled.repo.issue/3mvyvfln6su22`.
The record was read back successfully; Tangled's issue listing had not yet
indexed it at creation time.

## Prior work

This is a known remaining gap from the July 2026 conformance work, not a newly
discovered issue. The earlier Codex task, "Fix Linux Docker build workflow"
(`019f8650-7a7b-79a3-b317-3d4dcfeb75ca`), expanded into relay conformance work.
Its July 24 handoff explicitly lists "Signing-key cache misses retain a
first-event fail-open window" among the remaining discrepancies.

Already merged into current main:

- `da93ce5` (July 21): reject invalid signatures, with signing-key refresh.
- `bb919df` (July 21): reject CAR integrity failures instead of converting
  verifier errors into successful skipped validation.
- `0b85d4b` (July 22): enforce Sync 1.1 commit proofs.
- `f8eca5e` (July 22): require `prevData` for established repos.

The distinction is where validation exits: July's CAR fix rejects errors after
the verifier runs; a missing key still returns success before it runs. This is
unfinished hardening, not a regression of `bb919df`. The July handoff also
distinguishes local test evidence from incomplete public-network verification.

## Finding

The article's zlay caveat is accurate: an absent signing key bypasses CAR
verification. `validateCommit` returns `{ valid = true, skipped = true }`
before checking the envelope, CAR hashes, signature, or MST proof.
`validateSync` checks DID/rev syntax and block presence/size first, but also
returns success before parsing the CAR on a key-cache miss.

Both `frame_worker.zig` and `subscriber.zig` gate forwarding on `valid`, not
`skipped`. Accepted unverified frames can reach persistence and broadcast;
commit ops can also reach the collection index. Background resolution queues
the DID, not the frame, and does not retroactively validate what was forwarded.

This occurs after startup, LRU eviction, and `#identity` key eviction, and can
persist when DID resolution fails. Host authority checks are a separate guard:
they establish the sending PDS, not the authenticity of its CAR blocks.
They do not populate the signing-key cache. This finding is not a claim that
any arbitrary PDS can bypass host authority for an unrelated DID.

## Follow-ups, in order

1. **Make integrity checks independent of key availability.** Check required
   fields, size limits, and every CAR block's CID before a cache miss can accept
   anything. Reject malformed envelopes rather than treating a missing DID as
   successful skipped validation. Avoid parsing/hashing twice on the warm path.
   This closes the article's specific invalid-CAR hole, but does not establish
   authenticity: an attacker can recompute hashes for unsigned content.
2. **Stop forwarding unresolved commits and syncs.** Resolve and verify before
   acceptance; use a bounded pending/retry or authoritative repair path so that
   transient resolver failure does not silently lose the only event for a repo.
   Preserve per-DID ordering and make cursor behavior explicit. Represent
   verified, deferred, and rejected outcomes separately. Do not implement this
   as merely changing `valid` to false without addressing recovery.
3. **Exercise cold-cache behavior in the conformance harness.** It currently
   seeds corpus signing keys. Run real signed fixtures with warm, empty, and
   evicted caches; mutate commit, MST, and record bytes while retaining their
   CIDs; also test internally consistent hashes with an invalid signature.
   Verify no invalid/deferred frame is persisted, broadcast, or indexed through
   either ingestion implementation. Include resolver failure and recovery.

Existing unit tests actually assert the bypass: `validateCommit skips on cache
miss` accepts a payload without blocks, and `validateSync skips on cache miss`
accepts `blocks = "deadbeef"`. Existing CID-mismatch rejection tests populate
the signing-key cache, so they do not cover the reported condition.

## Adjacent checks

- zat's CAR reader defaults to block-hash verification; zlay pins zat v0.3.31.
  The relevant gap is reaching that verifier on every acceptance path.
- Current local stream (`1970fd9`) resolves keys on demand and returns an
  unverified outcome on resolution failure. Its pipeline suppresses non-valid
  commit/sync results (`src/internal/ingest/pipeline.zig:isSilent`). It no longer
  shares the old fail-open policy described in our notes.
- Current local zds (`f68da7c`) verifies imported repo CARs against the DID's
  signing key with `require_complete_repo = true`
  (`src/atproto/repo.zig`). No equivalent bypass was found on that inspected path.

## Verification

`zig build test --summary all` completed on 2026-09-20: 125 tests passed,
14 skipped, including successful execution of the cache-miss tests described
above (those tests do not have skip conditions). This verifies the validator's
current acceptance behavior; forwarding was traced in source, not exercised
against a live relay. No runtime code or deployment was changed.

## Sources

- Article linked above.
- `src/internal/validator.zig`: `validateCommit`, `validateSync`, `resolveLoop`,
  `resolveHostAuthority`, cache-miss and CID-mismatch tests.
- `src/internal/frame_worker.zig` and `src/internal/subscriber.zig`: identity
  eviction, validation gates, collection indexing, persistence and broadcast.
- `src/conformance_main.zig`: corpus key seeding.
- zat `38cfb02`, `src/internal/repo/car.zig`: default hash verification.