3 ms·
Hey, Greg. Former Mozillian here. Mozilla's very own Allen Wirfs-Brock started work on this sort of thing back in 2011 or so, called jsmirrors. The idea at t
by cxr 7y ago
Hey, Greg. Former Mozillian here.
Mozilla's very own Allen Wirfs-Brock started work on this sort of thing
back in 2011 or so, called jsmirrors. The idea at the time was to
inform the design of some reflection/sandboxing APIs that might make
their way into the TC39 spec, but nothing really came of it.
Several years later I had a use case, only with security being the
foremost concern, so I did a bunch of redesign and implementation work
on that, including bugfixes and adding good handling of primitives. So
there's already code available (around ~1100 here) for the kind of
membrane described in the Figma post.
(At least it's halfway there; Allen's original work let you poke remote
objects by way of serializing to JSON, and I neglected that area since
it wasn't useful to my immediate use case and would have slowed me
down--it sounds like you'd might need to stick something like that back
in. For my own use as a consumer, I just ended up instead leaning on
implementation-dependent details that I knew I could rely on from the
way SpiderMonkey was hosted in Gecko.)
This was born in Mozilla, so it's already MPL2, and there wouldn't be
any licensing issues.
Caveat: only ever targeted ES5, so changes for new JS features like
proxies, symbols, and other ES6+ stuff almost definitely violates some
invariants, but I couldn't tell you offhand whether that could manifest
as security issues. The tests still pass.
Poke at it if you want:
cd /keybase/public/crussell/projects/jsmirrors && npm test
... or double click tests/harness.app.htm and point it to the jsmirrors/
directory if you aren't comfortable giving unfettered access to
arbitrary pieces of code you find on the Internet (and you shouldn't
be).