fix(ietf): decode every legal request and refuse per request

Merged
KI
2mo ago
+1363-330

Problem

Several messages a conformant draft-14 to draft-22 peer may send (moxygen and libquicr among them) close the session with PROTOCOL_VIOLATION today, ahead of the Seattle interop on 2026-10-12:

  • A draft-20+ FETCH is decoded with the removed Fetch Type field.
  • Legal request parameters fail decode_params!: AUTHORIZATION TOKEN (0x03) on any request, NEW_GROUP_REQUEST (0x32) and the Range Filters (0x25-0x29), FILL_TIMEOUT (0x0A), LOCATION_FILTER (0x21) and INCLUDE_PROPERTIES (0x35) on FETCH, and any parameter on TRACK_STATUS.
  • INCLUDE_PROPERTIES (0x35) is read length-prefixed; the draft defines a uint8.
  • FORWARD=0 on SUBSCRIBE is a decode error.
  • A repeated AUTHORIZATION TOKEN (which every draft allows) is a duplicate, including in draft-14's generic parameter block, which also refused duplicates of unknown parameters the draft says to allow.

Approach

Decode everything the draft allows, then refuse what we don't serve per request with NOT_SUPPORTED.

  • Param::param_repeat lets a parameter opt into repetition; Vec<T> collects every instance and Opaque consumes a length-prefixed value. decode_params! folds repeats through it; everything else is still Duplicate.
  • SUBSCRIBE: decodes 0x03, 0x25-0x28 (draft-19+), 0x32 (draft-16+, ignored: the draft lets a publisher without dynamic groups ignore it) and 0x35 as a uint8 (Option<bool>, deleting IncludeProperties and its key-parity comment). New forward and range_filters fields; the publisher refuses either before resolving the broadcast.
  • REQUEST_UPDATE: decodes 0x03, 0x25-0x29 and 0x32. Nothing consumes an update yet (see follow-ups).
  • FETCH: draft-20+ decodes namespace, name and params into a new FetchType::Filtered { namespace, track, filter }; drafts 15-19 accept 0x03, 0x0A (18+) and 0x25-0x28 (19+). New range_filters and fill_timeout fields refuse a FETCH that carries either: main now serves standalone and joining FETCH, and neither can be honored (FILL_TIMEOUT=0 means cache only, and any budget ends in Timed-Out gaps we don't write). The encoder writes the draft-20 layout, and the pinned draft-21/22 wire test uses it.
  • TRACK_STATUS decodes as a SUBSCRIBE, which is how every draft defines it. This also fixes draft-14 TRACK_STATUS, which read an AbsoluteStart/Range filter's Location as the parameter count.
  • AUTHORIZATION TOKEN is decoded and ignored on PUBLISH, PUBLISH_NAMESPACE (+ its REQUEST_UPDATE) and SUBSCRIBE_NAMESPACE (both forms). decode_cluster_params loses its negotiated flag, since PUBLISH_NAMESPACE now decodes its own block.
  • Draft-14 message parameter blocks go through a new Parameters::skip, which consumes KVPs by parity without refusing repeats; SETUP keeps the strict Parameters::decode.
  • A parameter from a later draft stays a protocol violation on earlier ones, and a parameter the draft doesn't allow on a message stays fatal.
  • FETCH encoding omits GROUP_ORDER when it is Any (no preference). The merge of main made an absent GROUP_ORDER decode to Any, which re-encoded as a 0 the draft makes a protocol violation; the fuzz seed round trip caught it.
  • js/net mirrors this: repeatable 0x03 and 0x25-0x29, 0x0A, 0x32, 0x35 as a uint8, Subscribe.forward/rangeFilters, FETCH decoded on every draft and refused NOT_SUPPORTED (it was an unhandled bidi type), TRACK_STATUS decoded as SUBSCRIBE.

Tests are built from the draft-20 message figures (no moxygen or libquicr captures were available): per-message decode tests for SUBSCRIBE, REQUEST_UPDATE, FETCH and TRACK_STATUS across drafts, draft gating, repeats, and a publisher test that dispatches each through handle_stream and checks it returns Ok (the session stays open) with a NOT_SUPPORTED refusal on the wire. JS has matching decode and refusal tests.

Impact

  • Public API: none. ietf is private in moq-net and not exported from @moq/net.
  • Wire: conformance fixes only, no draft change.
    • INCLUDE_PROPERTIES (0x35) is now encoded as a uint8 (0x35 0x00) instead of 0x35 0x01 0x00. Our previous encoding was non-conformant; a peer running the old build reads the new form as a malformed value, so mixed old/new draft-20 sessions that opt out of properties break until both update.
    • Draft-20+ FETCH is encoded in the draft-20 layout. We never send FETCH on draft-20, so this only matters for tests and fuzzing.
    • Refusals: SUBSCRIBE with FORWARD=0 or Range Filters, and FETCH with Range Filters, now get NOT_SUPPORTED instead of a session close. A draft-18/19 FETCH with FILL_TIMEOUT is refused NOT_SUPPORTED rather than served without its budget.
    • js/net rejects TRACK_PROPERTY_FILTER (0x29) on SUBSCRIBE and FETCH as a protocol violation, matching Rust.

Decisions

Settled with the maintainer:

  • Range Filters are refused NOT_SUPPORTED, not INVALID_FILTER (which would need a new Error variant for one refusal).
  • TRACK_STATUS accepts whatever SUBSCRIBE accepts, rather than only the parameters each draft lists for it; the request is refused anyway.
  • INCLUDE_PROPERTIES is a strict uint8, with no fallback for the old length-prefixed form.
  • TRACK_PROPERTY_FILTER (0x29) stays fatal on SUBSCRIBE and FETCH, per the draft.
  • NEW_GROUP_REQUEST is ignored. The draft allows that, so nothing further is planned for it.

Follow-ups

  • REQUEST_UPDATE on a subscribe stream is never decoded by the publisher: any bytes after SUBSCRIBE make poll_closed ready, ending the subscription. Covered by quest/m0/ietf-fin-not-cancel.md.
  • Draft-15 says receivers ignore unrecognized message parameters and allow their duplicates, but decode_params! is strict there. The JS draft-14/15 path also refuses duplicate unknown parameters.
  • js/net checks message parameters against one global id table, not per message and draft like Rust's decode_params!, so a parameter legal elsewhere (such as FORWARD on FETCH) slips through. Per-message allowlists would close that.
  • Serving draft-20 FETCH is quest/m1/ietf-fetch-location.md, whose Plan this PR refreshes now that the codec is in place.

Deletes quest/m0/ietf-legal-input.md and every reference to it.

šŸ¤– Generated with Claude Code

(Written by Claude Opus 5.5)