Repository navigation
fix: send only a byte view's own bytes over structured-clone transports - #287
Merged
Merged
Conversation
At the structuredClonable and jsonCompatibleWithBytes levels, byte views were handed to the transport as-is. Structured clone copies a view's entire backing buffer, so a MessagePort peer received memory the sender never passed: the bytes around a subarray or typed array view, or Node's whole shared Buffer pool for any small Buffer. Copy out the view's range on the sending side whenever it doesn't cover its whole buffer. #201's copy runs on the receiving side, so it can't stop a peer from reading the raw message.
🦋 Changeset detectedLatest commit: 92cf9de The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
|
LGTM |
|
✅ Approved — The fix is small and correct. It copies only partial views, leaves views that cover their whole buffer unchanged, and tests both the plain Buffer path and the type-marked path. No issues found. The decision is advisory: this comment never approves, blocks or requests changes on the pull request. ✅ All checks passed📋 Code Quality: ✅ LGTMThe fix in
📝 Documentation: ✅ LGTMThe changeset entry describes the fix accurately and at the right level of detail. No documentation issues found. Reviewed commit: |
kentonv
approved these changes
Oct 26, 2026
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.
Previously a byte view sent over a
MessagePortsession carried its entire backing buffer. Structured clone copies the wholeArrayBufferbehind a view, so the peer could read the bytes around a subarray or typed array view, and any small NodeBuffershipped the sender's whole shared pool (64 KB on Node 24). #201's copy runs on the receiving side, so it can't stop a peer from reading the raw message.Now the sender copies out just the view's bytes whenever the view doesn't cover its whole buffer, at both the
structuredClonableandjsonCompatibleWithByteslevels. Views that already cover their buffer are sent unchanged. WebSocket and HTTP batch sessions were never affected, since base64 encodes only the view.