Conversation
A foreign payload that carries a top level data key passes the request gate today bcs the legacy check treats any packet with a pattern or data key as native, so handlers receive the raw payload instead of a wrapped packet, Kamil outlined the safe shape in nestjs#17672: an allowlist of envelope keys like nestjs#17670 uses on the response side, shipped as an opt-in deserializer option, bcs the stricter rule would still change what native packets deliver With strictRequestEnvelope on, a packet counts as foreign when it carries any key outside the request envelope (id, pattern, data), so { type: 'alert', data: ... } gets wrapped with the channel pattern, bare { data: X } packets stay native, and with the option off nothing changes for existing users KafkaRequestDeserializer and NatsRequestJSONDeserializer inherit the option through the base constructor, nestjs#17670 gave the response deserializer the same allowlist, this keeps both deserializers consistent
Member
|
if the default is off, why do we need that need flag in the first place? if someone runs into this issue they can just: class StrictDeserializer extends IncomingRequestDeserializer {
isExternal(value: any) {
if (!value || typeof value !== 'object') return true;
const keys = Object.keys(value);
return keys.length === 0 || keys.some(k => !['id', 'pattern', 'data'].includes(k));
}
}and pass their own deserializer |
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.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
the request deserializer treats any packet carrying a
patternor adatakey as a native Nest packet, so a foreign payload like{ type: 'alert', data: { ... } }reaches handlers unmodified and the handler silently reads the innerdatawhile the rest of the payload is lostthe response side already rejects foreign JSON through an envelope-keys check (#17670), but the request side can't take the same treatment as a default flip bcs bare
{ data: X }packets are native today, as Kamil laid out when closing #17672Issue Number: #17672, #17669
Steps to reproduce
git checkout master -- packages/microservices/deserializers/incoming-request.deserializer.tsandnpx vitest run packages/microservices/test/deserializers/What is the new behavior?
IncomingRequestDeserializeraccepts an options object,new IncomingRequestDeserializer({ strictRequestEnvelope: true }). with the option on,isExternalmirrors the response-side check: a packet counts as foreign when it carries any key outside the request envelope (id,pattern,data), so{ type: 'alert', data: ... }gets wrapped with the channel pattern and the handler receives the full payloadwith the option off (the default) nothing changes for existing users,
KafkaRequestDeserializerandNatsRequestJSONDeserializerinherit the option through the base constructor, and bare{ data: X }packets stay native in both modesDoes this PR introduce a breaking change?
Other information
follows the shape Kamil suggested in #17672: the same
ENVELOPE_KEYSallowlist #17670 uses on the response side, shipped as an opt-in deserializer option, which keeps the two deserializers consistent