fix(message,session): reject invalid FETCH Serialization Flags before reading fields (§11.4.4) - #112
Merged
Merged
Conversation
… reading fields (§11.4.4) "When less than 128, the bits represent flags ... Any other value is a PROTOCOL_VIOLATION." FetchObject.Parse read the fields that the bits of a value of 128 or more selected, and only Validate rejected it afterwards. If a stream reset or an oversized Payload Length followed such a value, the read failed with an ordinary error and the session stayed open. Parse now decides on the flags alone, right after reading them, and returns the new message.ErrInvalidFetchFlags. IncomingFetchStream.ReadObject maps that to PROTOCOL_VIOLATION; its separate Validate call is gone, since Parse now covers it. Validate shares the same check. Verified red first: in TestFetchObjectInvalidFlagsCloseSession, the reset and oversized-length cases on the unpatched tree; and TestFetchObjectParseRejectsInvalidFlags against a mutant without the early check. Allocs unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Finishes the last "protocol violations that MUST close the session" item in the draft-20 compliance backlog.
§11.4.4: "When less than 128, the bits represent flags ... [0x8C, 0x10C, 0x20C] ... Any other value is a PROTOCOL_VIOLATION."
Before this change,
FetchObject.Parseread the fields that the bits of a flags value ≥ 128 selected, and onlyValidaterejected the value afterwards. If a stream reset or an oversized Payload Length followed such a value, the read failed with an ordinary error and the session stayed open.Change
Parsechecks the flags right after reading them, and returns the newmessage.ErrInvalidFetchFlagsbefore touching any field.IncomingFetchStream.ReadObjectmaps that error to PROTOCOL_VIOLATION. Its separateValidatecall is gone, sinceParsenow covers it.Validateshares the same check.API: new exported
message.ErrInvalidFetchFlags.Tests
TestFetchObjectInvalidFlagsCloseSessionnow has three cases: invalid flags followed by a whole object, by a stream reset, and by an oversized Payload Length. The reset and oversized-length cases fail on the unpatched tree.TestFetchObjectParseRejectsInvalidFlagsfails when the early check is removed.make bench-quickshows no change in allocs/op.Unrelated, seen while testing
TestSubscribeTracks_ForwardsTrackGainedBySubscribe(relay) failed once during a fullgo test ./...run. The relay forwarded a PUBLISH to the subscriber whose own SUBSCRIBE created the track. It did not reproduce in 30 isolated runs or in 6 package runs, on either this branch ordraft-20, and this PR doesn't touch the relay. It looks like a pre-existing race under load and is worth a separate look.Test plan
go test ./...go test -race ./pkg/moqt/...golangci-lint run ./...🤖 Generated with Claude Code