Skip to content

[Bug]: Hermetic runs trust the extension to use context.data; a contract-1 extension writes the site's live data/ under --local-review and MCP run_test #976

Closed

Description

@jimhoyd

Security-relevant (data integrity), severity: medium. Found in an adversarial review of #947, #962 and #970.

Runtime revision and environment

origin/main ba9f3204, Node 26.10, macOS.

What happens

A hermetic run (test, audit, MCP run_test, and the --local-review runs of validate and routes) gives the host context.data (a fresh temp dir) and context.hermetic: true, and tells the user so. The local_review event says extensions use "a fresh temporary data directory, never the site's data/". Core never checks that:

Since #962, an MCP run_test with the operator's --host-file and no pin also activates such a host against the agent-edited revision. Before, it refused with revision-pin-required.

The current first-party auth, store and audit extensions do honour context.data. I only checked that by reading the code.

Minimal reproduction

host-legacy.mjs: a composeHost host with one contract-1 extension whose host(context) uses process.env.STORE_DATABASE ?? join(context.site, 'data', 'store.sqlite'), the same path logic as the store at f850492a~1, and appends a line there on each request. The project routes /demo/* to it and has one fixture, GET /demo/x.

rm -rf data; unset PROJECT_SHA256 URLCODE_POLICY URLCODE_ORIGIN
urlcode test --project app --host-file host-legacy.mjs --local-review
#  {"event":"local_review",...,"note":"... extensions use a fresh temporary data directory, never the site's data/ ..."}
#  {"total":1,"failed":0}
cat data/store.sqlite        # WRITE by test /demo/x   <- the site's live data/ was written
urlcode mcp --allow-authoring --project app --host-file host-legacy.mjs   # tools/call run_test
cat data/store.sqlite        # written again, with no operator pin
urlcode test --project app --host-file host-legacy.mjs   # without the flag: revision-pin-required

Observed: all of the above, run on the revision named. Assumed, not tested: an actual skewed install (a global CLI with a site's older add-ons) behaves the same way.

Suggested fix

  • Bump extensionContract for the hermetic obligation, so an older add-on is refused.
  • In a hermetic load, have loadOperatorHost refuse a host unless it confirms the data directory it was given. An older composeHost could not produce that confirmation.
  • Fix the related comment drift: HostContext.data/hermetic (packages/core/src/extensions.ts ~586) and LoadOptions.hermetic still say only test, audit, benchmark and run_tests are hermetic, and that validate and routes use <site>/data.

Activity

  1. added
    bug
    on Sep 29, 2026
  2. jimhoyd commented on Sep 30, 2026

    @jimhoyd
    CollaboratorAuthor

    Review of PR #987 (head af07d30): the hermetic confirmation passes a hand-made registration once any composeHost result is reused.

    SECURITY.md says the confirmation catches "version skew and hand-made registrations", and docs/EXTENSIONS.md and the RIM card say the same. loadOperatorHost (packages/core/src/operator-host.ts around line 120) checks only that the host object carries the confirmation key with this run's directory. It does not check that each registration came from that compose. composeHost confirms an empty compose too (host.ts around line 57), and Object.assign makes the key enumerable, so a spread keeps it.

    Reproduced in the PR worktree with loadOperatorHost(host, app, { hermetic: true }), using the PR test's legacyRegistration (it writes <site>/data/store.sqlite). The host file was:

    const c = await composeHost(import.meta.url, []);
    export default { ...c, extensions: [legacyRegistration(site, process.env.PROJECT_SHA256)] };

    Result: R1 accepted; extensions: 1. A separate run through the real CLI (urlcode test --local-review) exited 0 and wrote the site's live data/store.sqlite. Pushing a hand-written registration onto composeHost([...]).extensions behaves the same.

    Host code is trusted, so this is not a security boundary. But the docs claim more than the check does. Options:

    • reword the docs to say the check catches a host with no composeHost result, or an older composeHost;
    • or record the confirmed registrations (a WeakSet, or the array itself) and compare result.extensions against them.
  3. jimhoyd commented on Sep 30, 2026

    @jimhoyd
    CollaboratorAuthor

    Fixed in #987, commit 1d410c3. The hermetic confirmation is now checked per registration, so a hand-made registration that is spread, pushed or mixed in beside composed ones is refused. The docs now call it a correctness check, not a security boundary. Summary: #987 (comment)

  4. jimhoyd commented on Sep 30, 2026

    @jimhoyd
    CollaboratorAuthor

    Fixed by #987 (merged), including the review follow-ups: per-registration hermetic confirmation and aging the sweep by a directory's newest entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions