Skip to content

quic: validate session close error codes - #66302

Open
christianaurichzm wants to merge 1 commit into
nodejs:mainfrom
christianaurichzm:quic-validate-close-code
Open

christianaurichzm wants to merge 1 commit into
nodejs:mainfrom
christianaurichzm:quic-validate-close-code

Conversation

@christianaurichzm

Copy link
Copy Markdown
Contributor

session.close() and session.destroy() only check that options.code is a bigint or a number. MaybeSetCloseError() then casts numbers straight to uint64_t, and bigints are only checked to fit in 64 bits, but QUIC error codes are 62-bit varints.

So an invalid code is sent as some other code. On x64, 1.5 goes out as 1, -1 as 2 ** 62 - 1, and NaN, Infinity and 2n ** 62n reach the peer as NO_ERROR, which makes an error close look like a clean one.

Codes outside 0 to 2n ** 62n - 1n now throw ERR_OUT_OF_RANGE, the same range QuicError uses. The check is in validateCloseOptions(), so it runs before destroy() tears anything down. The existing validate-options test covers the invalid codes for both methods, and its final destroy() now sends the max code and checks that the server gets it unchanged.

`session.close()` and `session.destroy()` only checked that
`options.code` was a bigint or a number. Numbers were then converted
to `uint64_t` unchecked, so fractions were truncated and negative,
non-finite or too large values were undefined behavior. Bigints were
only checked to fit in 64 bits, but QUIC error codes are
variable-length integers limited to 62 bits, so larger codes cannot
be encoded in the `CONNECTION_CLOSE` frame.

Reject codes that are not integers between `0` and `2n ** 62n - 1n`,
the range `QuicError` already enforces, before any close or destroy
side effects.

Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/quic

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. quic Issues and PRs related to the QUIC transport implementation. labels Sep 25, 2026
@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.36%. Comparing base (cc610f1) to head (35352cd).
⚠️ Report is 52 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66302      +/-   ##
==========================================
- Coverage   90.37%   90.36%   -0.01%     
==========================================
  Files         790      790              
  Lines      273856   274287     +431     
  Branches    52394    52503     +109     
==========================================
+ Hits       247495   247869     +374     
- Misses      16853    16893      +40     
- Partials     9508     9525      +17     
Files with missing lines Coverage Δ
lib/internal/quic/quic.js 100.00% <100.00%> (ø)

... and 39 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pimterry pimterry added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 28, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 28, 2026
@panva panva added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. needs-ci PRs that need a full CI run. quic Issues and PRs related to the QUIC transport implementation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants