Skip to content

id(world_records): read_records collapses duplicate keys inside a replicated value — the #6483 receipt caps measure the collapsed value, so an oversized value hidden behind a duplicate passes, unlike parse_records (#6473) #6634

Closed

Description

@dezren39

Problem

RecordsStore receipt path read_records (pkgs/id/src/world_records.rs:242) re-checks the MAX_RECORD* caps on replicated records — that was the #6483 fix — but it parses each record's value with plain serde_json::from_slice (world_records.rs:269-270) and measures the value's size from the parsed value (world_records.rs:271: serde_json::to_vec(&value) length). serde_json::Value keeps only the last value for a repeated object key, so a duplicate key inside a replicated value silently collapses before the cap is measured:

So the replica receipt gate — the one path that exists because a replicated doc is not trusted (#6483) — accepts a value shape and size the publisher can never produce, and the size it enforces is the collapsed size, not the size of the bytes actually received and stored in the blob. This is the #6473 exploit surviving on the one receipt path #6483 hardened for caps but not for duplicate keys.

Evidence

Verification (this run, laptop @ de90338)

Probe test added in a laptop worktree (~/git/fleet/probe-readrecords-wt, test probe_read_records_collapses_duplicate_keys_in_a_value, using the module's own write_raw harness against a real in-memory iroh-docs doc):

  • Raw duplicate value {"k":"<8292 x's>","k":"small"} written under key dup: read_records returns Ok with dup = {"k":"small"} — the oversized first value vanished and the collapsed size passed the 8192 cap.
  • Control: parse_records on the same value nested in a records document returns Err (duplicate key refusal).
  • Control (pre-existing test): a duplicate-free oversized value is refused by read_records (read_records_refuses_an_oversized_value), so the cap itself works — only the duplicate collapse bypasses it.

Why it matters

read_records is the trust boundary for replicated world state: its whole purpose (#6483) is that a non-conforming or hostile doc cannot smuggle over-cap records into a follower. A duplicate key reopens exactly the hole #6473 closed on the publish side — the checker and the byte stream disagree about the value — and it also means two readers of the same blob can disagree about a record's content (the #6520 contract's core concern).

Acceptance criteria

  • read_records refuses a record value containing a duplicate object key at any depth, with an error naming the record key (routing the parse through id_core::json_unique::parse_json_without_duplicate_keys over the value bytes, or an equivalent checked parse).
  • A duplicate-hidden oversized value (raw bytes > MAX_RECORD_VALUE_BYTES, collapsed size under) is refused; the value-size cap is evaluated against the document as written, never a collapsed form.
  • Duplicate-free conforming values — including values at exactly MAX_RECORD_VALUE_BYTES — still read back unchanged; all existing world_records receipt tests stay green.
  • A regression test in the world_records tests uses the existing write_raw harness with a duplicate-key value and asserts the refusal.
  • The site is recorded as a gate disposition for the Phase 4 of #6520 — closing JSON-parse inventory: disposition every serde_json parse site in pkgs/id against the duplicate-key refusal contract #6521 inventory.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    source/creatorFiled by the new-issue-creator job
    on Nov 6, 2026
  2. developing-today commented on Nov 6, 2026

    @developing-today
    Contributor
  3. added
    priority/normalOrdinary priority (the default)
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Nov 6, 2026
  4. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  5. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    Picked up by repo-worker-code-a — working this now. (Fleet queue fallback mode: the queue backend is down, so this issue's comments carry the claim. The claim stays live while repo-worker-code-a posts progress markers; after 30 minutes of silence any other worker may pick this up.)

  6. added
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    and removed on Nov 7, 2026
  7. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  8. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    Progress from repo-worker-code-a: verified: read_records still parses with plain serde_json::from_slice on current main (0b8afc9) — issue #6634 live, not landed. Implementing in laptop worktree ~/git/fleet/fb-6634 (branch queue/6634-read-records-duplicate-keys): route the value parse through id_core::json_unique::parse_json_without_duplicate_keys (mirroring parse_records) + write_raw regression tests for a duplicate-hidden oversized value and a small nested duplicate.

  9. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    Progress from repo-worker-code-a: targeted_tests_failed (harness, under diagnosis): all 12 world_records tests incl. pre-existing ones fail at write_raw with iroh-docs 'author not found' on the laptop — failure is in the shared test harness before read_records runs, not in the patch. Running the identical suite on a clean-main control worktree (fb-6634-control) to prove pre-existing/environmental vs patch-caused.

  10. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    Progress from repo-worker-code-a: targeted_tests_passed: serial run of the full world_records module on the laptop — 15 passed, 0 failed, including both new duplicate-key tests; the parallel-run 'author not found' harness failures reproduce identically on clean main (pre-existing race, not this patch). Committed d4d8cee, branch pushed; opening PR.

  11. added a commit that references this issue on Nov 7, 2026
  12. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

  13. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    Released by repo-worker-code-a (outcome: done). Done: read_records now parses via id_core::json_unique::parse_json_without_duplicate_keys — duplicate keys refused at receipt naming the record key, cap measures the document as written. PR #6678 merged (2b426f7), closing #6634. Laptop: cargo test -p id --lib world_records serial = 15 passed/0 failed (incl. 2 new tests); Codex zero findings; PR CI QUEUED (runner backlog).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions