From cb9d030fc168ab07120b3159eff774860d648bb5 Mon Sep 17 00:00:00 2001 From: rUv Date: Mon, 26 Oct 2026 11:52:24 -0400 Subject: [PATCH] fix(federation): a policy denial of a consequential inbound message is final in legacy and observe mode (#4511) task-assignment, memory-query, context-share, trust-change, topology-change, agent-spawn, claim-event and agent-handoff are no longer delivered after the policy engine denied them, and are refused when the evaluator throws. Co-authored-by: r --- .../__tests__/unit/inbound-dispatcher.test.ts | 33 +++++++++++++++++-- .../src/application/inbound-dispatcher.ts | 14 ++++++-- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/v3/@claude-flow/plugin-agent-federation/__tests__/unit/inbound-dispatcher.test.ts b/v3/@claude-flow/plugin-agent-federation/__tests__/unit/inbound-dispatcher.test.ts index 63efaa9a31..ddf1e88e35 100644 --- a/v3/@claude-flow/plugin-agent-federation/__tests__/unit/inbound-dispatcher.test.ts +++ b/v3/@claude-flow/plugin-agent-federation/__tests__/unit/inbound-dispatcher.test.ts @@ -153,7 +153,7 @@ describe('dispatchInbound — happy path', () => { signatureVersion: 'jcs-v1', }, }); - await dispatchInbound('a', jcs('task-assignment'), deps); + await dispatchInbound('a', jcs('task-assignment'), { ...deps, authorizationMode: 'legacy' }); await dispatchInbound('a', jcs('memory-query'), deps); await dispatchInbound('a', jcs('context-share'), deps); expect(events.map((e) => e.event)).toEqual([ @@ -402,11 +402,38 @@ describe('dispatchInbound — inbound authorization', () => { expect(events).toEqual([]); }); - it('observe evaluates and reports denial without blocking', async () => { + it.each(['legacy', 'observe'] as const)('%s still refuses a denied task-assignment, agent-spawn or memory-query', async (mode) => { + for (const type of ['task-assignment', 'agent-spawn', 'memory-query', 'trust-change', 'claim-event']) { + const peer = mkPeer('alpha'); + const { deps, events } = withVerifier([peer], () => true); + const result = await dispatchInbound('a', jcsMessage(type), { + ...deps, + authorizationMode: mode, + authorizeInbound: () => ({ allowed: false, reason: 'untrusted peer' }), + }); + expect(result, type).toEqual({ accepted: false, reason: 'AUTHORIZATION_DENIED' }); + expect(events, type).toHaveLength(0); + } + }); + + it('legacy and observe refuse a consequential message when the evaluator throws', async () => { + for (const mode of ['legacy', 'observe'] as const) { + const { deps, events } = withVerifier([mkPeer('alpha')], () => true); + const result = await dispatchInbound('a', jcsMessage('agent-spawn'), { + ...deps, + authorizationMode: mode, + authorizeInbound: () => { throw new Error('boom'); }, + }); + expect(result).toEqual({ accepted: false, reason: 'AUTHORIZATION_ERROR' }); + expect(events).toHaveLength(0); + } + }); + + it('observe evaluates and reports denial without blocking a low-risk message', async () => { const peer = mkPeer('alpha'); const { deps, events } = withVerifier([peer], () => true); const authorizeInbound = vi.fn(() => ({ allowed: false, reason: 'would deny' })); - const result = await dispatchInbound('a', jcsMessage(), { + const result = await dispatchInbound('a', jcsMessage('status-broadcast'), { ...deps, authorizationMode: 'observe', authorizeInbound, diff --git a/v3/@claude-flow/plugin-agent-federation/src/application/inbound-dispatcher.ts b/v3/@claude-flow/plugin-agent-federation/src/application/inbound-dispatcher.ts index 0a0cc71bfa..b732da79a5 100644 --- a/v3/@claude-flow/plugin-agent-federation/src/application/inbound-dispatcher.ts +++ b/v3/@claude-flow/plugin-agent-federation/src/application/inbound-dispatcher.ts @@ -26,6 +26,12 @@ import type { FederationNode } from '../domain/entities/federation-node.js'; import { FederationNodeState } from '../domain/value-objects/federation-node-state.js'; /** What gets emitted on the event bus per messageType. */ +/** Message types whose policy denial is enforced even outside enforce mode. */ +const CONSEQUENTIAL_MESSAGE_TYPES: ReadonlySet = new Set([ + 'task-assignment', 'memory-query', 'context-share', 'trust-change', + 'topology-change', 'agent-spawn', 'claim-event', 'agent-handoff', +]); + export const FEDERATION_INBOUND_EVENT_PREFIX = 'federation:inbound'; /** Reasons we reject an inbound message — constant strings, no oracle leak. */ @@ -379,6 +385,10 @@ export async function dispatchInbound( } const authorizationMode = deps.authorizationMode ?? 'legacy'; + // Message types that start work, read memory or change who is trusted. A denial + // for one of these is final in every mode: legacy/observe only soften claim + // checks for the rest, they never deliver what the policy engine refused. + const consequential = CONSEQUENTIAL_MESSAGE_TYPES.has(message.type); if ( authorizationMode !== 'legacy' && authorizationMode !== 'observe' && @@ -408,7 +418,7 @@ export async function dispatchInbound( } authorizationDecision = decision; } catch { - if (authorizationMode === 'enforce') { + if (authorizationMode === 'enforce' || consequential) { await deps.audit.log('message_rejected', { sourceNodeId, metadata: { address, reason: 'AUTHORIZATION_ERROR', messageType: message.type }, @@ -430,7 +440,7 @@ export async function dispatchInbound( } if (authorizationDecision && !authorizationDecision.allowed) { - if (authorizationMode === 'enforce') { + if (authorizationMode === 'enforce' || consequential) { await deps.audit.log('message_rejected', { sourceNodeId, metadata: {