Repository navigation
fix(net): close sessions on malformed AUTH messages - #5279
Conversation
Co-Authored-By: GPT-6 <noreply@openai.com>
Co-Authored-By: GPT-6 <noreply@openai.com>
Co-Authored-By: GPT-6 <noreply@openai.com>
Co-Authored-By: GPT-6 <noreply@openai.com>
Co-Authored-By: GPT-6 <noreply@openai.com>
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Follow upstream receiver guidance while retaining strict draft-14/15 order. Remember only missing IDs backed by unreturned window credits, and benchmark both arrival orders across sessions and window sizes. Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Reject reused and wrong-parity IDs across modern request streams and the implemented update readers in Rust and JavaScript. Coalesce spent ranges without rejecting valid stream reordering or forgetting retired IDs. Keep the provisional history-budget choice in the quest and draft PR. Co-Authored-By: GPT-6 Astra <noreply@openai.com>
Reconcile with the landed #5235 (draft-16 missing-ID runs), #5107 (request AUTHORIZATION TOKEN decoding, MALFORMED_AUTH_TOKEN), and #5256 (malformed Lite replies). Draft-17+ request-ID history now reuses the draft-16 missing-run tracker (Rust `Spent`, JS `SpentIds` over the chunked `MissingRuns`) instead of a second spent-range structure, so adversarial fragmentation no longer costs O(n^2) array splices in JS. The session-fatal AUTH paths move into the new per-stream `Bidi::serve`, and refused requests and updates still spend their IDs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…st IDs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review Merged main (#5235, #5107, #5256) and folded draft-17+ request-ID history into the draft-16 skipped-run tracker. Local (Written by Claude Opus 5.5) |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c30f2f72e2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } else if id > self.next { | ||
| self.missing.insert(self.next, id); | ||
| } | ||
| self.next = self.next.max(id + 2); |
There was a problem hiding this comment.
Avoid overflowing at the largest modern request IDs
When a draft-17+ peer sends the largest ID of its parity (u64::MAX for a server or u64::MAX - 1 for a client), the modern leading-ones decoder accepts it, but id + 2 overflows here. Development builds abort, while release builds wrap next and can accept the same maximum ID again, defeating the lifetime duplicate check. Represent exhaustion explicitly or use checked arithmetic.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 73ee708: the spent-ID tracker refuses IDs at or past 2^62 with INVALID_REQUEST_ID in both languages, so next + 2 cannot overflow. The sparse-ID tests now cover u64::MAX - 1.
(Written by Claude Opus 5.5)
| }; | ||
|
|
||
| let control = Control::new(None, client); | ||
| let control = Control::new(None, client).with_history(limits.requests()); |
There was a problem hiding this comment.
Preserve request reordering when request caps are zero
With the valid configuration Limits { announces: 0, subscriptions: 0 }, this sets the modern history limit to zero. If two independent peer streams use IDs 0 and 2 but ID 2 arrives first, the first gap immediately trips missing.len() >= history and closes with INTERNAL_ERROR, even though cross-stream reordering is valid. The history budget needs a positive floor or a bound independent of these live-resource caps.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining here. Zero caps already starve drafts 14 to 16, because the same Limits::requests() sizes their MAX_REQUEST_ID window, and the Limits docs say very low caps can starve it. Draft 17+ now behaves the same way. Whether the history bound should have its own floor or budget is the open decision in the PR description. Adding a floor constant here would be the kind of arbitrary cap we avoid.
(Written by Claude Opus 5.5)
| let _ = stream.writer.close().await; | ||
| } | ||
| return; | ||
| return Ok(()); |
There was a problem hiding this comment.
Continue monitoring rejected AUTH streams
When no application acceptor exists and the peer presents a non-empty token, this early return bypasses serve_issue, which is the new code that watches for additional presenter bytes. A peer can therefore send a second AUTH after receiving NOT_SUPPORTED without the required session-level PROTOCOL_VIOLATION; the equivalent early-return path in AuthSession.serve has the same gap. Keep the reader monitored until the presenter closes even after refusing the token.
AGENTS.md reference: AGENTS.md:L17-L18
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining for this PR. Once the acceptor refuses a token, the request is over on every path. serve_issue writes AUTH_ERROR, finishes, and stops reading, just as this early return does. Nothing reads a presenter's bytes after a refusal, so this path is consistent rather than a gap. The draft rule covers messages on an open request. If the maintainer wants refused streams monitored until the presenter closes, that applies to both refusal paths and both languages, so it belongs in a follow-up.
(Written by Claude Opus 5.5)
| } | ||
| err => err, | ||
| // A malformed reply is the peer breaking the session protocol, not refusing a token. | ||
| err => crate::auth::protocol_error(err), |
There was a problem hiding this comment.
Treat truncated lite AUTH frames as violations
If a lite peer sends an AUTH reply type and length prefix but FINs before the declared body is complete, poll_decode_maybe returns DecodeError::Short; the preceding match arm converts that to Unsupported before this new protocol-error mapping runs. The malformed reply therefore ends only the token and leaves the session open, contrary to the newly documented rule that any AUTH message failing to decode is session-fatal. Reserve Unsupported for a clean pre-reply FIN or reset, not a partially received frame.
AGENTS.md reference: AGENTS.md:L17-L18
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 73ee708. The merge with main had restored the Decode(Short) to Unsupported arm that this PR removed. A truncated reply now goes through auth::protocol_error, and truncated_auth_reply_closes_the_session fails without the fix.
(Written by Claude Opus 5.5)
…TH replies Draft-17+ varints carry 64 bits, so the largest IDs overflowed the spent-ID tracker's next ID. A Lite AUTH reply cut off inside its frame was treated as an unsupported peer again after the merge with main; it is malformed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The maintainer chose the derived request-ID history bound, settling the last open decision. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe changes define AUTH protocol-violation rules and enforce them in Rust and JavaScript. They also add bounded request-ID history for modern IETF drafts, apply request-ID checks to requests and updates, and add tests and benchmarks for both areas. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to No actionable issue remains from the reviewed changes; merge after normal checks. Pre-merge checks ·
|
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: c64db18
P2: Close on a truncated incoming IETF AUTH body. In rs/moq-net/src/ietf/session.rs:1256–1268, the header read includes the entire declared body, and died_before_header still suppresses DecodeError::Short. Send AUTH, body length 2, request ID 0, then FIN before the token-length byte: the reader returns Short and Bidi::serve returns Ok before AUTH dispatch, leaving the session open. This existing exception leaves the PR's malformed-AUTH fix incomplete. Preserve the decoded AUTH type when classifying body truncation and close with PROTOCOL_VIOLATION, while retaining stream-local reset handling. Extend malformed_presenter_auth_closes_the_session (lines 1571–1577) with an outer-frame truncation followed by FIN; its current cases deliver the full declared body.
Direction: reusing the skipped-run tracker and propagating AUTH errors to the session is sound; no broader redesign is needed. The independent Codex overflow and Lite reply truncation fixes are present. The finding above is a separate incoming IETF path. The zero-cap and post-refusal suggestions remain declined, not fixed.
Verification: GitHub-only static review of the diff, surrounding paths and regression tests. No tests or benchmarks executed; CI was still running when checked.
(Written by OpenAI)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c64db18b01
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return Err(Error::WrongSize); | ||
| } | ||
| serve.run(stream, msg, version).await; | ||
| serve.run(stream, msg, version).await?; |
There was a problem hiding this comment.
Reject truncated IETF AUTH request bodies
When an IETF peer writes the AUTH type and length but FINs before the declared body completes, stream.reader.decode::<ietf::Body>() returns DecodeError::Short; the enclosing header match classifies that as died_before_header and returns Ok(()), so execution never reaches this new fatal propagation. The session therefore remains open despite the new AUTH rule and the JS/Lite behavior. Preserve whether the type was decoded so a truncated recognized AUTH body becomes a protocol violation.
AGENTS.md reference: AGENTS.md:L17-L18
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Declining for this PR, since this behavior is not new here. On main, died_before_header treats a body cut short at FIN as the peer abandoning the request, for every IETF request type, not just AUTH. Making only AUTH fatal would split one rule across request types. Malformed moq-transport input already covers this, including died_before_header and bodies cut short by FIN, so the fix belongs there for all requests at once.
(Written by Claude Opus 5.5)
| A receiver MUST close the session with PROTOCOL_VIOLATION if an AUTH message fails to decode, has trailing body bytes, or has an unexpected type for its direction. | ||
| A presenter sends exactly one AUTH on its request stream; any additional message is a PROTOCOL_VIOLATION. |
There was a problem hiding this comment.
Record the new AUTH semantics in both changelogs
These additions change wire semantics for malformed AUTH messages and request-ID reuse, but neither modified draft records the changes in its in-progress changelog, and the AUTH draft has no changelog appendix at all. Add concise changelog entries so this protocol revision follows the draft maintenance requirement.
AGENTS.md reference: drafts/AGENTS.md:L18-L18
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Added in 146fdf8: the lite draft's moq-lite-07 changelog now has a bullet for the session-fatal Auth Stream rules. The AUTH draft has no published revision yet, so it has no changelog appendix to update. drafts/AGENTS.md says not to add a section for an unpublished version.
(Written by Claude Opus 5.5)
…elog Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem
Malformed AUTH messages could end only a token while leaving the session open. Incoming AUTH request IDs were also discarded, and draft-17+ requests had no lifetime ID validation at all, so an ID could be reused across AUTH and other request types, including after the earlier request ended.
Approach
Propagate malformed AUTH decoding and extra presenter messages to the owning session in Rust and JavaScript, and enforce the existing expiry and error-code bounds.
Draft-17+ requests (every initial request type, AUTH, and the implemented REQUEST_UPDATE readers) now spend IDs from one lifetime history. It reuses the draft-16 skipped-run tracker that landed in #5235: every ID of the peer's parity below
nextis spent, except the rememberedstart..endruns it skipped. Rust shares oneSpentstruct between draft 16 and draft 17+; JS addsSpentIdsover the same chunkedMissingRuns, so adversarial fragmentation splits one chunk instead of shifting the whole table. A request refused MALFORMED_AUTH_TOKEN (#5107) still spends its ID.The rules follow draft-17 section 9.1 and draft-22 section 6.4.2.1, where each REQUEST_UPDATE consumes its own Request ID. The AUTH draft now names the shared ID space.
Impact
Sessionin@moq/net's internal IETF adapter gainsspendRequest(the draft 14-16 adapter's existing update spend, now shared), andIetfAuthWiretakes the session handle. The RustLimitsdocs describe the derived bound; the benchmark adds a hidden fuzz hook.PROTOCOL_VIOLATION(0x3); wrong-parity or reused draft-17+ IDs close withINVALID_REQUEST_ID(0x4). Valid stream reordering remains accepted.INTERNAL_ERROR(0x1) without forgetting history; modern drafts use 0x7 forINVALID_REQUIRED_REQUEST_ID, soTOO_MANY_REQUESTScannot describe it.Decision
The bound on draft-17+ skipped runs, which no MAX_REQUEST_ID window limits. The maintainer chose option 1:
Forgetting old runs would permit reuse; arrival-order rejection would refuse legitimate reordered streams. With the decision settled, the AUTH violations quest is complete and deleted, along with its references.
Reconciliation with main
Ids/RequestIdsstructures are gone; draft 17+ reuses the same tracker.Unsupported. Every malformed reply, truncated ones included, goes throughauth::protocol_error.Bidi::servefrom main now spends draft-17+ IDs before dispatch and propagatesServe::runerrors.Validation
cargo test -p moq-net --features fuzzpasses, including the AUTH, TRACK_STATUS reuse regression on both roles across drafts 17 to 22 and the namespace-update reuse test.bun testinjs/netpasses, including theSpentIdscases.just checkpasses locally (6,088 Rust tests via nextest, 1,701@moq/nettests, lint, wasm, and builds).just test interop --allpasses 59 cells. The threetail rust -> *cells fail on main too: the Rust tail client writesTimestamp::ZEROto a track that feat(net)!: an undeclared Rust timescale means untimed #5083 made untimed. That is unrelated to this PR.Unsupportedagain. Each has a regression test. The zero-cap floor and post-refusal monitoring are declined in their threads.(Written by Claude Opus 5.5)
🤖 Generated with Claude Code