Repository navigation
Refuse a streaming call whose item serializer a filter before the payload filter has set - #72
Merged
Merged
Conversation
…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.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
A health check review found that
PayloadFiltersetsJsonRpcRequestContext.StreamItemSerializerto its sealer whatever it finds there. A filter placed before it (added beforeUsePayload) 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 aJsonElement, which would name the wrong type: the client'sOpenItem<TItem>would refuse it, and a MessagePack codec cannot write one.What this PR does. It fails closed.
PayloadFilternow refuses such a streaming call with anInvalidOperationException, 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 anddocs/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
UsePayloadnow gets-32603for streaming calls instead of untransformed items. The Polhem framework does not stream today and sets no item serializer.Verification
dotnet build0 warnings; 1529 tests pass;check-md-links.shclean.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_ReturnsResultfails when the refusal ignores whether the method streams.InvokeStreamingAsync_ItemSerializerWrappedAfterPayloadFilter_ItemsOpenshows 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
-32603carries no detail withIncludeExceptionDetailsoff. Its findings (refuse before decryption, a duplicated payload filter, every format, the ordinary-method case, wording, CHANGELOG section) are addressed in the last commit.