endo icon indicating copy to clipboard operation
endo copied to clipboard

feat(ses): shim ArrayBuffer.p.transfer

Open erights opened this issue 1 year ago • 1 comments

Staged on #2419

Closes: #XXXX Refs: https://github.com/endojs/endo/pull/2414 #2418 #2419

Description

#2414 by itself does not work on Node 18 and Node 20 because

  • those platforms do not have Array.prototype.transfer, so #2414 must use structuredClone instead
  • structuredClone does exist on Node >= 18, so it should be on supported platforms (though see #2418 ). However, structuredClone itself is dangerous and so must not be added to the shared intrinsics. As a result, in #2414 , when @endo/pass-style is initialized in a created compartment, it fails to find either Array.prototype.transfer and `structuredClone

To solve this, @kriskowal suggested that we also shim Array.prototype.transfer if needed during lockdown, along with other repairs. We are avoiding similarly shimming Array.prototype.transferToImmutable because it is not yet standard. But Array.prototype.transfer is standard, and so lockdown can globally shim it before hardening the shared intrinsics.

This PR implements @kriskowal 's suggestion.

Security Considerations

none

Scaling Considerations

by itself, none

Documentation Considerations

nothing signicant.

Testing Considerations

See #2418 . Aside from that, none

Compatibility and Upgrade Considerations

Assumes we only support platforms that provide either Array.prototype.transfer itself, or provides structuredClone. See #2418

Update: This PR is now staged on #2419 to fix a stale dependence on Node 12, which would no longer work after this PR.

erights avatar Aug 19 '24 19:08 erights

See https://github.com/endojs/endo/issues/2418

The platform-compatability-test tests are not marked as required, so solving #2418 does not actually block this PR. But it would be nice to get that fixed first.

erights avatar Aug 19 '24 20:08 erights

PTAL

erights avatar Sep 03 '24 22:09 erights

Please consider removing the unnecessary slice call as brand check, and improve support for when the new length doesn't match.

Done

erights avatar Sep 04 '24 00:09 erights