Skip to content

fix(helpers): accept Uint8Array values from other realms - #176

Merged
Ryang-21 merged 3 commits into
masterfrom
fix/byte-schemas-cross-realm
Oct 16, 2026
Merged

Ryang-21 merged 3 commits into
masterfrom
fix/byte-schemas-cross-realm

Conversation

@Ryang-21

Copy link
Copy Markdown
Contributor

What

Closes #169. Stacked on #173, which adds the isUint8Array helper. This PR targets that branch and should be retargeted to master once #173 merges.

assertUint8Array now uses isUint8Array instead of instanceof Uint8Array. So opaque, varOpaque and string accept a genuine Uint8Array from another realm (an iframe, a node:vm context, Jest's jsdom environment) on encode and validate, including inside struct and union fields. The detached / out-of-bounds check is unchanged.

One small behavior change: a Proxy wrapping a Uint8Array used to pass instanceof and then fail with Uint8Array is detached or out of bounds. It now fails earlier with expected Uint8Array.

Tests

  • opaque, varOpaque, string: encode and validate a Uint8Array built with node:vm.
  • struct: a varOpaque field holding a foreign Uint8Array.
  • varOpaque: still rejects a spoofed Symbol.toStringTag object, a Proxy around a Uint8Array, and a foreign Uint16Array.

All five new tests fail without the fix.

Copilot AI lite review requested due to automatic review settings October 16, 2026 00:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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 isUint8Array validation.
  • Adds coverage for opaque, string, varOpaque, and struct fields.
  • Preserves rejection of spoofed and incompatible values.
  • Fix required: handle proxies in isUint8Array so validation returns the expected XdrError.
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.

@Ryang-21
Ryang-21 requested a review from quietbits October 16, 2026 20:21
Base automatically changed from fix/writer-input-validation to master October 16, 2026 22:58
…oss-realm

# Conflicts:
#	src/core/writer.ts
#	test/unit/writer.test.ts
@Ryang-21
Ryang-21 merged commit bdf75de into master Oct 16, 2026
7 checks passed
@Ryang-21
Ryang-21 deleted the fix/byte-schemas-cross-realm branch October 16, 2026 23:19
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.

Byte schemas reject Uint8Array values from other JS realms on encode/validate

3 participants