Repository navigation
fix(helpers): accept Uint8Array values from other realms - #176
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Proxy-wrapped typed arrays currently cause an unexpected TypeError instead of the documented validation error.
0 open findings
What changed in this PR
This PR updates byte-schema validation to accept genuine cross-realm Uint8Array values.
Changes:
- Uses cross-realm-safe
isUint8Arrayvalidation. - Adds coverage for opaque, string, varOpaque, and struct fields.
- Preserves rejection of spoofed and incompatible values.
- Fix required: handle proxies in
isUint8Arrayso validation returns the expectedXdrError.
| File | Summary |
|---|---|
test/unit/var-opaque.test.ts |
Tests cross-realm values and rejection cases. |
test/unit/struct.test.ts |
Tests cross-realm values in struct fields. |
test/unit/string.test.ts |
Tests cross-realm string values. |
test/unit/opaque.test.ts |
Tests cross-realm fixed opaque values. |
src/core/helpers.ts |
Switches to cross-realm Uint8Array detection. |
🧠 Review effort: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
quietbits
approved these changes
Oct 16, 2026
…oss-realm # Conflicts: # src/core/writer.ts # test/unit/writer.test.ts
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.
What
Closes #169. Stacked on #173, which adds the
isUint8Arrayhelper. This PR targets that branch and should be retargeted tomasteronce #173 merges.assertUint8Arraynow usesisUint8Arrayinstead ofinstanceof Uint8Array. Soopaque,varOpaqueandstringaccept a genuineUint8Arrayfrom another realm (an iframe, anode:vmcontext, Jest'sjsdomenvironment) onencodeandvalidate, including inside struct and union fields. The detached / out-of-bounds check is unchanged.One small behavior change: a
Proxywrapping aUint8Arrayused to passinstanceofand then fail withUint8Array is detached or out of bounds. It now fails earlier withexpected Uint8Array.Tests
opaque,varOpaque,string: encode and validate aUint8Arraybuilt withnode:vm.struct: avarOpaquefield holding a foreignUint8Array.varOpaque: still rejects a spoofedSymbol.toStringTagobject, aProxyaround aUint8Array, and a foreignUint16Array.All five new tests fail without the fix.