feat(permissions): foolproof per-module isolation via sibling v8::Contexts
Implements the foolproof design called out in denoland/orchid#64: each
module covered by the new `--deny-module-isolated` flag is compiled,
instantiated, and evaluated in its own `v8::Context` with no `Deno`
binding. The trusted realm sees the isolated module's exports via a
synthetic-module bridge; the isolated module's code has *no* closure
path to the unwrapped ops — its `globalThis`, lexical scope, and op
references are all from a separate realm.
This closes every escape hatch the stack-based `--deny-module` flag had:
* async boundaries (the originating module is no longer "on the stack")
* confused deputy (allowed module B can be called by denied A)
* eval / new Function (arbitrary stack at the op site)
* V8 inlining / tail calls dropping frames
deno_core (new public APIs):
* `compile_module_in` / `instantiate_module_in` /
`evaluate_module_in` / `module_namespace_in` — the four-step ES
module lifecycle inside a specified `v8::Context`.
* `create_module_namespace_bridge` — build a synthetic module in
realm A whose exports are bound to `v8::Global` handles drawn
from realm B's module namespace. Cross-realm transfer is safe
because `create_sibling_context` matches security tokens.
* `JsRuntime::install_isolated_module(specifier, source)` — the
high-level wrapper: creates a sibling realm, runs the four-step
lifecycle there, builds a bridge in the main realm, and registers
the bridge in the main `ModuleMap` under the specifier so the
main realm's import resolution finds it.
CLI:
* `--deny-module-isolated=<file-url-or-path>` — repeatable. Resolves
each value at startup (relative paths against cwd), reads the
source from disk, and feeds it to `install_isolated_module` before
the main module starts loading.
End-to-end demo (`tests/specs/permission/deny_module_isolated`):
* `main.js` imports `./helper.js`. With
`--deny-module-isolated=./helper.js`, the helper runs in a sibling
realm: `typeof globalThis.Deno === "undefined"`, `Deno` lexical
lookup throws `ReferenceError: Deno is not defined`, and the
helper's attempt to call `Deno.statSync` fails. Yet the helper's
exports (`describeEnv`, `tryReadSelf`) are visible from the main
realm, so the program runs normally.
The existing stack-based `--deny-module` is kept intact for backward
compatibility; the new `--deny-module-isolated` flag is the
foolproof variant.
Confused-deputy caveat: an isolated module that explicitly *exports*
a function which captures an op closure is still an exported
capability — trust delegation is now object-capability-shaped (the
trusted realm chose to import that capability) rather than ambient.
That matches the SES / object-capability model.
Tests added:
* 5 deno_core unit tests covering sibling-context isolation,
cross-realm synthetic-module bridging, and the high-level
`install_isolated_module` end-to-end path.
* 2 spec tests demonstrating the CLI behavior and the rejection of
unsupported (non-`file:`) specifiers.
Closes denoland/orchid#64
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>