Skip to content

fix(net): close sessions on malformed AUTH messages - #5279

Merged
kixelated merged 18 commits into
mainfrom
quest/m1/auth/violations
Oct 12, 2026
Merged

kixelated merged 18 commits into
mainfrom
quest/m1/auth/violations

Conversation

@kixelated

@kixelated kixelated commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

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 next is spent, except the remembered start..end runs it skipped. Rust shares one Spent struct between draft 16 and draft 17+; JS adds SpentIds over the same chunked MissingRuns, 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

  • Public API: none. Session in @moq/net's internal IETF adapter gains spendRequest (the draft 14-16 adapter's existing update spend, now shared), and IetfAuthWire takes the session handle. The Rust Limits docs describe the derived bound; the benchmark adds a hidden fuzz hook.
  • Wire: no framing, field, negotiation, or assigned-code changes. Malformed AUTH closes with PROTOCOL_VIOLATION (0x3); wrong-parity or reused draft-17+ IDs close with INVALID_REQUEST_ID (0x4). Valid stream reordering remains accepted.
  • Resource behavior: draft-17+ skipped runs are capped at twice the sum of the announcement and subscription caps (220,000 by default in both languages). Contiguous or merely reordered traffic leaves no runs. One more gap past the cap closes with INTERNAL_ERROR (0x1) without forgetting history; modern drafts use 0x7 for INVALID_REQUIRED_REQUEST_ID, so TOO_MANY_REQUESTS cannot describe it.

Decision

The bound on draft-17+ skipped runs, which no MAX_REQUEST_ID window limits. The maintainer chose option 1:

  1. ✅ Derive it from the existing request capacity. No new constant or config, and legitimate peers never approach it.
  2. A separate configurable history budget, with matching language and binding API work.
  3. Unbounded history, letting memory grow with adversarial or abandoned requests.

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

Validation

  • cargo test -p moq-net --features fuzz passes, including the AUTH, TRACK_STATUS reuse regression on both roles across drafts 17 to 22 and the namespace-update reuse test.
  • bun test in js/net passes, including the SpentIds cases.
  • just check passes locally (6,088 Rust tests via nextest, 1,701 @moq/net tests, lint, wasm, and builds).
  • just test interop --all passes 59 cells. The three tail rust -> * cells fail on main too: the Rust tail client writes Timestamp::ZERO to a track that feat(net)!: an undeclared Rust timescale means untimed #5083 made untimed. That is unrelated to this PR.
  • Codex on c30f2f7: fixed the 64-bit ID overflow (IDs at or past 2^62 are refused in both languages) and the truncated Lite reply, which the merge had made Unsupported again. 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

kixelated and others added 14 commits October 10, 2026 09:29
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>
@kixelated

Copy link
Copy Markdown
Collaborator Author

@codex review

Merged main (#5235, #5107, #5256) and folded draft-17+ request-ID history into the draft-16 skipped-run tracker. Local just check passes. just test interop --all passes 59 cells; the only failures are the three tail rust -> * cells, where the Rust tail publisher writes a timestamp to an untimed track. That comes from #5083 on main and is unrelated to this PR.

(Written by Claude Opus 5.5)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T19:45:22.893096Z c64db18 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

kixelated and others added 3 commits October 12, 2026 08:59
…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>
@kixelated
kixelated marked this pull request as ready for review October 12, 2026 19:39
@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fe8a5a3c-5c19-4aa3-9a8d-d3c6de7bcc3b

📥 Commits

Reviewing files that changed from the base of the PR and between d17b84e and 146fdf8.


📒 Files selected for processing (33)
  • drafts/draft-lcurley-moq-auth.md
  • drafts/draft-lcurley-moq-lite.md
  • js/net/bench/request-ids.ts
  • js/net/src/auth.test.ts
  • js/net/src/auth_session.ts
  • js/net/src/goaway-requests.test.ts
  • js/net/src/ietf/adapter.ts
  • js/net/src/ietf/auth.ts
  • js/net/src/ietf/connection.test.ts
  • js/net/src/ietf/connection.ts
  • js/net/src/ietf/publisher.test.ts
  • js/net/src/ietf/publisher.ts
  • js/net/src/ietf/request_ids.test.ts
  • js/net/src/ietf/subscriber.ts
  • js/net/src/integration.test.ts
  • js/net/src/lite/auth.ts
  • js/net/src/lite/connection.ts
  • quest/m1/auth/README.md
  • quest/m1/auth/violations.md
  • quest/m1/lite-malformed-close.md
  • rs/moq-net/benches/request-ids.rs
  • rs/moq-net/src/auth.rs
  • rs/moq-net/src/fuzz.rs
  • rs/moq-net/src/ietf/auth.rs
  • rs/moq-net/src/ietf/control.rs
  • rs/moq-net/src/ietf/mod.rs
  • rs/moq-net/src/ietf/publisher.rs
  • rs/moq-net/src/ietf/session.rs
  • rs/moq-net/src/ietf/subscriber.rs
  • rs/moq-net/src/lite/publisher.rs
  • rs/moq-net/src/lite/session.rs
  • rs/moq-net/src/session.rs
  • rs/moq-net/tests/subscribe_tracks.rs

💤 Files with no reviewable changes (2)
  • quest/m1/auth/violations.md
  • quest/m1/auth/README.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.



Walkthrough

The 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 146fd

No actionable issue remains from the reviewed changes; merge after normal checks.

Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 70.69% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 58 functions across 28 files. (3 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly identifies the primary change: closing sessions when AUTH messages are malformed. It is concise and directly related to the changeset.
Description check Passed The description accurately explains malformed AUTH handling, request-ID validation, protocol errors, implementation scope, and validation results. It is directly related to the changeset.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

Full details: Docstring Coverage

Explanation

Docstring coverage is 70.69% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 58 functions across 28 files. (3 skipped: 3 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches
✨ Simplify code
  • Commit to this branch
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 Clippy (1.98.1)

Clippy execution timed out



Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment on lines +92 to +93
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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@kixelated
kixelated added this pull request to the merge queue Oct 12, 2026
Merged via the queue into main with commit 947494c Oct 12, 2026
9 checks passed
@kixelated
kixelated deleted the quest/m1/auth/violations branch October 12, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant