Skip to content

id(invites): reject over-cap delegation depth when decoding signed events #13250

Closed

Description

@dezren39

Evidence

pkgs/id/crates/id-directory/src/invites/event.rs:388-405 (InviteEvent::from_v2_bytes) enforces the wire version, body-size limit, and exact postcard consumption, then returns the decoded InviteBody without validating its delegation depth. The only current cap check is in sign_terms (:334-354), so it protects locally minted events but not externally supplied signed event bytes.

Reproduction on current origin/main: construct an InviteBody with depth_remaining = 200 and a parent_digest, sign it with a valid Ed25519 key, serialize with to_bytes, then call InviteEvent::from_bytes. It returns Ok; verify_signature() also succeeds; the decoded depth is 200 while MAX_SOURCE_DEPTH is 3. A temporary unit test ran successfully demonstrating this and was removed. Focused test: cargo test --manifest-path pkgs/id/Cargo.toml -p id-directory repro_from_bytes_accepts_over_cap_depth -- --nocapture (1 passed).

This is distinct from the closed signing-side fix #13217: that prevents sign_terms from producing over-cap events, but decode accepts externally signed events that do not go through that constructor.

Why it matters

Consumers that trust a decoded, signature-valid invite can observe delegation authority beyond the protocol cap. The parser is the common boundary for serialized invite events, so constructor-only validation leaves the invariant dependent on every producer being this implementation.

Acceptance criteria

  • InviteEvent::from_bytes rejects v2 events whose depth_remaining exceeds MAX_SOURCE_DEPTH, regardless of whether parent_digest is present.
  • Add a regression test using a correctly signed, directly constructed over-cap body; assert decode fails, and retain valid source/child round-trip coverage.
  • Keep valid legacy v1 decoding behavior unchanged.
  • Focused id-directory invite tests pass.
{
  "direct_parent": null,
  "links": [],
  "lineage": {
    "design": null,
    "roadmap_item": null,
    "priority": null
  },
  "pm_meta": 1,
  "provenance": {
    "queue_id": null,
    "scheduled_start": null,
    "picked_up_at": null,
    "work_started_at": null,
    "created_at": "2026-11-23T12:25:59Z",
    "session_id": "ses_e5df7b8ef9dffeRBm1ZP818jo5",
    "lane": null,
    "host": "amd",
    "worktree": "/home/user/git/fleet/improvement-issue-creator-code-20261123T120106Z-8c121dbe",
    "model": null,
    "lane_start_issues": [],
    "workspace_ref": {
      "kind": "worktree",
      "id": "/home/user/git/fleet/improvement-issue-creator-code-20261123T120106Z-8c121dbe",
      "repo": "developing-today/code",
      "branch": null,
      "sha": "d18c12f8e9d4c005e13c506875e3923d43489cb8"
    },
    "auth_subject": "any-n",
    "stamped_by": "fleet 0.1.0 (native)"
  }
}

Activity

  1. developing-today commented on Nov 23, 2026

    @developing-today
    Contributor
  2. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Claim — Lane VF (archer) taking code#13250 now.

    Plan: verify the premise on current main (decode path in pkgs/id/crates/id-directory/src/invites/event.rs — from_v2_bytes returns the decoded body without a depth check), add the MAX_SOURCE_DEPTH rejection on decode plus the signed over-cap regression test, keep v1 decoding unchanged, run the focused id-directory invite tests on the laptop, PR + merge + close.

  3. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Done — Lane VF. PR #13256 merged (03ebe5230fdb, head SHA-guarded at 6ba015dfca0); this issue is closed as completed.

    Premise verified first-hand on main a467a2c79ac: from_v2_bytes enforced wire version, body-size budget and exact postcard consumption, then returned the decoded body with no depth check — the only cap enforcement was in sign_terms (mint side, from #13217).

    Fix: from_v2_bytes now refuses a decoded body whose depth_remaining exceeds MAX_SOURCE_DEPTH, with or without a parent_digest; the from_bytes error docs name the refusal. v1 decoding is untouched (v1 bodies carry depth 0 by construction). Regression test an_over_cap_depth_is_refused_at_decode_even_when_signed signs a depth-200 body directly, bypassing sign_terms, and pins that exactly-at-cap still decodes; valid source/child round-trip coverage was already in the module and stays green.

    Verification (laptop route — the fleet-build container cannot run the id dev shell, the code#13159 family gap):

    • Focused invite tests: 16 passed / 0 failed.
    • Mutation check: with the decode check removed, the new test fails (the signed over-cap body decodes); restored, it passes.
    • Full id-directory suite: 292 passed / 0 failed.
    • cargo fmt --check -p id-directory clean; clippy reports no findings in the changed file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions