Skip to content

fix(peer): verify inbound delegation chain once - #120

Open
devdiv07 wants to merge 1 commit into
agentrust-io:mainfrom
devdiv07:fix/avoid-double-chain-verification
Open

fix(peer): verify inbound delegation chain once#120
devdiv07 wants to merge 1 commit into
agentrust-io:mainfrom
devdiv07:fix/avoid-double-chain-verification

Conversation

@devdiv07

Copy link
Copy Markdown

What

Avoid verifying the same delegation chain twice in handle_peer_request().

The inbound path now verifies the chain once, including trusted_root_issuers,
performs holder binding, and then intersects the already-verified leaf scope
with local policy directly.

effective_scope() remains unchanged and continues to verify defensively for
callers that have not already verified their chain.

Closes #105.

Why

handle_peer_request() previously called verify_chain() directly before
holder proof and then called effective_scope(), which performs another
verify_chain() internally.

That meant every successful inbound request repeated the Ed25519 signature
verification, chain continuity checks, scope attenuation walk, depth checks,
and trusted-root validation.

The first verification cannot simply be removed: holder binding must only
challenge control of chain[-1].subject after the chain establishes that the
subject was genuinely delegated.

The second verification is redundant because the exact same chain, depth limit,
and trusted-root set have already been validated before holder proof.

This implements option 1 from #105: keep effective_scope() defensive for its
independent/public callers while avoiding it on the already-verified inbound
pipeline.

The ordering remains:

  1. verify delegation chain and trusted root
  2. verify holder proof
  3. intersect delegated scope with local policy
  4. appraise caller runtime
  5. enforce capability
  6. open any sealed payload

Security impact

No authorization or delegation checks are removed from the inbound request
boundary.

handle_peer_request() still performs verify_chain() before holder proof,
including the configured trusted_root_issuers check. Scope intersection only
occurs after that verification succeeds.

A dedicated regression also confirms that a valid holder-proved request rooted
outside trusted_root_issuers is still rejected.

effective_scope() itself is unchanged, so other callers such as
enforce_peer_call() continue to receive defensive chain verification.

The change removes only the second verification of an already-verified chain.

Test plan

  • pytest tests/unit -q
    • 440 passed, 2 skipped
    • skipped tests are hardware-gated SEV-SNP/TDX tests
  • ruff check src/ tests/
  • ruff format --check src/ tests/
  • mypy src/ca2a_runtime/ src/ca2a_verify/
  • bandit -r src/ -c pyproject.toml
  • Manual test performed
    • No manual transport test; this change is covered at the inbound pipeline unit level.

Regression coverage added for:

  • exactly one verify_chain() invocation during a successful
    handle_peer_request(), while wrapping and executing the real verifier;
  • rejection of an otherwise valid holder-proved request whose root is outside
    trusted_root_issuers.

The exact-once regression was also run against the pre-change implementation
and failed with:

assert 2 == 1

confirming that it detects the redundant verification removed by this change.

DCO sign-off

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: devdiv07 <sarvenclothing@gmail.com>
@imran-siddique
imran-siddique self-requested a review August 18, 2026 18:57
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.

handle_peer_request verifies the delegation chain twice per request

1 participant