feat(ocap-kernel): integrate Snaps network endowment factory#942
Open
feat(ocap-kernel): integrate Snaps network endowment factory#942
Conversation
Add fetch/Request/Headers/Response to default vat endowments via @metamask/snaps-execution-environments's network factory, with per-vat host allowlist threaded through a new VatConfig.network field. Remove the platform-level fetch capability entirely. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Reject file:// URLs in network caveat with a hint to use the fs platform capability (closes a filesystem capability leak) - Match host allowlist on URL.hostname, ignoring ports - Surface logger-transport failures in the notify bridge via console.error so a broken audit trail is visible - Add tests: teardown aborts in-flight fetch, caveated-fetch end-to-end chain, positive-path initVat past the fetch guard, malformed URLs, file:// via Request input Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Coverage Report
File Coverage |
- VatSupervisor: add positive-path assertion (init returns a result) alongside the existing negation to prevent vacuous pass - endowments: replace globalThis.fetch mutation with vi.stubGlobal + unstubAllGlobals in afterEach; removes the require-atomic-updates disable and avoids cross-test bleed - endowments: assert console.error fallback in the notify-swallow test so a silent-swallow regression would fail - network-caveat: add data:/blob: scheme cases to pin the empty- hostname rejection path; rename $scheme it.each label to $label for accuracy Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Closes #936.
Integrates the Snaps
@metamask/snaps-execution-environments/endowmentsnetwork factory into vat globals. Replaces the platform-levelfetchcapability with a per-vat endowment that shipsfetch/Request/Headers/Response, wires teardown for in-flight requests and open body streams, and enforces a per-vat host allowlist (VatConfig.network.allowedHosts) applied at#initVatviamakeHostCaveat.fetchwithout an allowlist fails init — no implicit allow-all.file://URLs are rejected by the caveat with a hint to use thefsplatform capability.Summary
fetch,Request,Headers,Responseto the default vat endowments via the Snaps factory; teardown aggregates intoVatSupervisor.terminate().VatConfig.network: { allowedHosts: string[] }; host matching isURL.hostname-only (ports and schemes ignored).notifycallback to the vat logger atdebug; transport failures surface viaconsole.error.packages/kernel-platforms/src/capabilities/fetch/directory (BREAKING for direct consumers offetchConfigStruct,FetchCapability,makeHostCaveat,makeCaveatedFetch).kernel-node-runtimedropsplatformOptions.fetch.fromFetch;nodejs-test-workers/mock-fetchstubsglobalThis.fetchdirectly;evm-wallet-experimentcluster config and docker e2e helper move toglobals: ['fetch', ...]+network.allowedHosts.docs/kernel-guide.mdendowment table,docs/usage.md, andpackages/evm-wallet-experiment/docs/setup-guide.md.Test plan
network-caveat.test.tscovers host/hostname matching, port-insensitivity,file://rejection (string + Request input), malformed URL propagation, and a positive+negative end-to-end chain throughmakeCaveatedFetch.endowments.test.tsverifies the new globals list, thenotifywiring, logger-transport error containment, and that teardown aborts an in-flightfetch(stubsglobalThis.fetchwith an abort-respecting promise, asserts the abort signal propagates and teardown returns cleanly).VatSupervisor.test.tsexercises both the fetch-without-allowlist throw path and the positive-path wherenetwork.allowedHostsis supplied (asserts absence of the guard error in dispatch).types.test.tsvalidates the newnetworkfield, rejecting non-array and non-string entries.kernel-test/src/endowments.test.tsexercises allowed/disallowed hosts end-to-end through a realVatSupervisorand assertsRequest/Headers/Responseconstructors are available in the vat compartment.🤖 Generated with Claude Code
Note
High Risk
High risk because it changes how outbound network access is granted/enforced (new per-vat allowlist guard) and introduces breaking config/API changes (
platformConfig.fetchremoval,MakeAllowedGlobalssignature change) that affect multiple packages and tests.Overview
Adds Snaps network endowments to vats by including
fetchplus hardenedRequest/Headers/Responsein the default allowed globals and wiring their teardown into vat termination.Enforces a new per-vat outbound host allowlist via
VatConfig.network.allowedHosts;VatSupervisornow rejects vats that requestfetchwithout this config and wrapsfetchwith a hostname caveat (including explicitfile://rejection).BREAKING migration: removes the
fetchplatform capability entirely from@metamask/kernel-platforms, dropsplatformOptions.fetchusage inkernel-node-runtime, updates consumers/tests to requestglobals: ['fetch', ...]+network.allowedHosts, and changesMakeAllowedGlobals/createDefaultEndowmentsto accept a{ logger }options bag (used for Snaps networknotifylogging).Reviewed by Cursor Bugbot for commit fd045f4. Bugbot is set up for automated code reviews on this repo. Configure here.