Skip to content

Refuse a streaming call whose item serializer a filter before the payload filter has set - #72

Merged
jeff377 merged 3 commits into
mainfrom
claude/payload-filter-item-order
Dec 2, 2026
Merged

jeff377 merged 3 commits into
mainfrom
claude/payload-filter-item-order

Conversation

@jeff377

@jeff377 jeff377 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A health check review found that PayloadFilter sets JsonRpcRequestContext.StreamItemSerializer to its sealer whatever it finds there. A filter placed before it (added before UsePayload) that transforms the items, redacting fields for instance, had its function replaced. The items still went out sealed, but untransformed, and nothing said so.

Why not compose the two. The sealer writes the item's runtime type into the envelope's type. The earlier function returns a JsonElement, which would name the wrong type: the client's OpenItem<TItem> would refuse it, and a MessagePack codec cannot write one.

What this PR does. It fails closed. PayloadFilter now refuses such a streaming call with an InvalidOperationException, answered as -32603, before it opens the request, so the refused call costs no key, no decryption and no sequence number. The message says to add the transforming filter after the payload filter and wrap the function it finds, or to add the payload filter once if it was added twice. Calls of methods that do not stream, and callers that do not read a stream, are unaffected.

The other order is not detected. A filter after the payload filter that replaces its function, instead of wrapping it, still sends the items unencrypted, and the server cannot check it: the dispatcher cannot tell who set the function. The documents keep saying so.

IJsonRpcFilter, JsonRpcRequestContext.StreamItemSerializer, PayloadFilter, the README extension points and docs/security.md (both languages) describe the order; the CHANGELOG records it under Security, marked Behavior change, since a transformation lost without a word may be a redaction.

Downstream

  • No wire change, no public API change.
  • A host that sets an item serializer in a filter before UsePayload now gets -32603 for streaming calls instead of untransformed items. The Polhem framework does not stream today and sets no item serializer.

Verification

  • dotnet build 0 warnings; 1529 tests pass; check-md-links.sh clean.

  • InvokeStreamingAsync_ItemSerializerSetBeforePayloadFilter_IsRefused (-32603, the method did not run, in the plain, encoded and encrypted formats) fails when the refusal is disabled or limited to encrypted calls; InvokeStreamingAsync_OrdinaryMethodWithItemSerializerSetBefore_ReturnsResult fails when the refusal ignores whether the method streams. InvokeStreamingAsync_ItemSerializerWrappedAfterPayloadFilter_ItemsOpen shows the documented order working: the wrapper sees every item and the encrypted items still open.

  • Adversarial review: nothing blocking. Nothing in this package or the Polhem framework sets an item serializer before the payload filter, and -32603 carries no detail with IncludeExceptionDetails off. Its findings (refuse before decryption, a duplicated payload filter, every format, the ordinary-method case, wording, CHANGELOG section) are addressed in the last commit.

…load filter has set

PayloadFilter set JsonRpcRequestContext.StreamItemSerializer to its sealer whatever it found there, so a
filter placed before it that transformed the items, redacting them for instance, had its function
replaced and its work lost without a word. Composing the two is not possible as such: the sealer names
the item's runtime type in the envelope, which a JsonElement from the earlier function would not match,
and a MessagePack codec cannot write one. The payload filter now refuses such a call, with an
InvalidOperationException answered as -32603, before the method runs, and the documents say that a
filter that transforms items runs after it and wraps the function it finds.
…-item-order

# Conflicts:
#	CHANGELOG.md
#	CHANGELOG.zh-TW.md
…, and test every format

The check now runs before the envelope is read, so a refused call costs no key, no decryption and no
sequence number. The message says the payload filter may have been added twice. Tests refuse the call in
every format and leave a method that does not stream alone. The CHANGELOG entry moves under Security,
since a transformation lost without a word may be a redaction, and the security document says the server
does not check the other order rather than that nothing detects it.
@jeff377
jeff377 enabled auto-merge (squash) December 2, 2026 02:34
@jeff377
jeff377 merged commit b8784dc into main Dec 2, 2026
4 checks passed
@jeff377
jeff377 deleted the claude/payload-filter-item-order branch December 2, 2026 02:35
@sonarqubecloud

sonarqubecloud Bot commented Dec 2, 2026

Copy link
Copy Markdown

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.

1 participant