# Vendored files

The sandbox site serves five built files from Scramjet, copied byte-for-byte from the npm tarballs.
Nothing is installed: they aren't in any package.json, and no install script ever ran.
`vendor/VENDOR.json` is the machine-readable pin list (package, version, tarball integrity, provenance
commit, per-file bytes and sha256). `site.ts` reads it; `build.ts` and the dev server (`server.ts`) refuse
to run when a byte differs or an unpinned file sits in `vendor/`, and the `sandbox` e2e suite fails the
same way. `update-vendor.ts` re-checks or updates the pins.

Fetched 2026-12-03 from registry.npmjs.org. Each tarball's sha512 matched the registry's `dist.integrity`.

| Package | Version | Published | Licence | Tarball integrity (sha512) |
|---|---|---|---|---|
| `@mercuryworkshop/scramjet` | 2.1.0 | 2026-11-21 04:01 UTC | AGPL-3.0-only | `sha512-z2d0Lfak0KnuTKVJLBeAWuvW8DWXOwvGCwlBYoIwacVbSeNwoQcU06vRtY/ke1gbUtiRkhCT6VOL/cc8M1Yo3w==` |
| `@mercuryworkshop/scramjet-controller` | 0.1.0 | 2026-11-21 04:01 UTC | AGPL-3.0-only | `sha512-okVNrzkazV1sgF49jPAlE08lAvd9cegj/1dQoomkvulaooTD/fy7I1V6II6qhbvWU64OOE787k9G6cxxadH4jg==` |

Both carry npm SLSA provenance from GitHub Actions in `MercuryWorkshop/scramjet` at commit
`2b2adc6e649446b55c37f8fc910556386ab50a81` (refs `refs/tags/v2.1.0` and `refs/tags/controller-v0.1.0`).
Both are older than the 48 h `minimumReleaseAge` in `pnpm-workspace.yaml` (12 days at vendoring time).
Neither package has install scripts (`preinstall`/`install`/`postinstall`); their `scripts` are build
and lint commands for their own repo.

## Files

| Served at | From (in the tarball) | Bytes | sha256 |
|---|---|---|---|
| `/scramjet/scramjet.js` | `scramjet/package/dist/scramjet.js` | 227493 | `5c4d7c2b2ac778ee3821623cec9a7909091fa537327c6f6fd12312524b3d38b7` |
| `/scramjet/scramjet.wasm` | `scramjet/package/dist/scramjet.wasm` | 583429 | `eebfdac7435e8f4939c9109e3834fb7f3a67e7c3780f46a3ff61f7a68ddc01cd` |
| `/controller/controller.api.js` | `scramjet-controller/package/dist/controller.api.js` | 25802 | `7b517399cd6df20ef6d8089adb4c72cb08e53894e34d6a39aead093563478ea4` |
| `/controller/controller.inject.js` | `scramjet-controller/package/dist/controller.inject.js` | 6421 | `8cc89fce200c20c79f5e3fb9608555fcc9e0c2f53eccad79cc97855b4296ab1f` |
| `/controller/controller.sw.js` | `scramjet-controller/package/dist/controller.sw.js` | 4576 | `805309725993d31a8e540c20c575dcc176a86e7fdfc6b9d69ccf4ee8f94c736d` |

That's the minimal set. Not vendored: the source maps, the ESM and `_bundled` builds, and every
transport (Wisp, epoxy, libcurl, wisp-js): our transport is HTTP over postMessage to the app
(`src/sandbox.js`), and WebSockets use the browser's own `WebSocket`. `proxy-transports` is already
inlined in `scramjet.js` and `controller.api.js`.

## What's bundled inside

Per the source maps (`docs/research/scramjet-audit.md`, "Packages"):

- `scramjet.js` (IIFE, global `$scramjet`): Scramjet's client, fetch handler, cookie jar and rewriter
  glue, with htmlparser2 12.0.0 (MIT, with Mercury's pnpm patch), dom-serializer 2.0.0 (MIT),
  domhandler 5.0.3, domelementtype 2.3.0 and 3.0.0, entities 4.5.0 and 8.0.0 (BSD-2-Clause), and
  `@mercuryworkshop/proxy-transports` 1.0.2 (MIT). `idb` and `parse-domain` are declared dependencies
  but aren't in the bundle.
- `scramjet.wasm`: the Rust HTML/JS/CSS rewriter (`packages/core/rewriter` in the Scramjet repo, oxc
  0.95.0 and ~200 crates from its `Cargo.lock`, mostly MIT/Apache-2.0).
- `controller.api.js` (global `$scramjetController`): the controller page side, with semver 7.7.3 (ISC),
  `@fastify/deepmerge` 3.2.1 (MIT), `proxy-transports` 1.0.2 and Mercury's in-repo `packages/rpc`.
- `controller.inject.js`: loaded into each proxied document; connects it to the controller.
- `controller.sw.js`: the service worker side (`shouldRoute`, `route`); `src/sw.js` imports it.

Their licence texts are in `THIRD-PARTY-NOTICES` (served as `/THIRD-PARTY-NOTICES.txt`).

## Review notes (2026-12-03)

- No hard-coded network endpoints in any of the five files (no `http(s)://` hosts). Their `eval`,
  `importScripts`, `sendBeacon` and `WebSocket(` references are the hooks Scramjet installs in
  proxied realms to rewrite those APIs.
- The controller persists its cookie jar in IndexedDB (`__scramjet_controller`) and syncs it over a
  BroadcastChannel. `src/sandbox.js` wipes all of this origin's storage when a session starts with no
  other session open.
- `controller.sw.js` calls `skipWaiting()` and `clients.claim()`, and broadcasts `swrevive` 100 ms after
  every start; see the revive fix in `src/sw.js` and `src/sandbox.js`.
- An independent supply-chain audit: docs/research/scramjet-audit.md. It found the five files identical
  to the npm tarballs and the signed CI builds, nothing suspicious, and three medium findings, handled
  as below.

## Audit findings and what we did

- **M1, `scramjet.wasm` isn't reproducible** (CI built it with an unpinned nightly toolchain, and its
  JS bridge gives it full reach into the sandbox page). **Accepted for the experimental deploy on
  `trench-sandbox.pages.dev`** (2026-12-03) under the user's threat model: the wasm only runs on the
  sandbox origin, a separate site from the app with no app secrets on it; the product is burner-wallet
  only; the provenance ties the tarball to the tagged commit's CI run. **Before any public release**:
  rebuild `scramjet.wasm` from commit `2b2adc6e` in a throwaway VM or container (cargo runs build
  scripts from ~200 crates, so not on a dev machine) with rustc `1.102.0-nightly (c7d5ba59d 2026-11-20)`
  (`nightly-2026-11-21`), `wasm-bindgen-cli 0.2.105`, the `r58playz/wasm-snip` commit current on
  2026-11-21 and a binaryen release from that week. If it hashes to `eebfdac7…`, keep the npm binary;
  otherwise ship our build and pin its hash. Generate the crate licence texts (`cargo about`) in the
  same VM.
- **M2, every proxied page sees the whole cookie jar** (HttpOnly too) and Scramjet stores it in
  IndexedDB. Sessions are throwaway: `src/sandbox.js` wipes cookies (the controller's IndexedDB),
  localStorage, sessionStorage, every IndexedDB, Cache Storage and the OPFS root when a session starts
  with no other open, and when the last one closes. The service worker keeps nothing on disk. The
  browser window says "Don't log in to anything important here".
- **M3, every proxied page has a raw request primitive.** All policy lives app-side
  (`src/browser/relay.ts`): http(s) only, no credentials in URLs, no local names or private / loopback /
  link-local / CGNAT / multicast IP literals; names that resolve there are refused after DNS by the
  Helper's rebinding guard and the companion's own lookup; a per-session rate limit with a queue;
  `purpose: "browser"` so the edge carries only its allowlisted API hosts; strict shape and size checks
  on every message from the sandbox frame (`src/browser/sandbox-protocol.ts`). `src/sw.js` puts a CSP on
  every proxied response (`connect-src 'self' data: blob:`, `object-src 'none'`) so code that escapes
  Scramjet's hooks can't reach the network except through the logged transport.
- **L1, licences**: `LICENSE` (AGPL-3.0), `/source.html` (upstream repo at the commit, our own source
  served unminified, optional repository link from `TRENCH_SOURCE_URL`) and `THIRD-PARTY-NOTICES`.
- **L4, vendoring skips pnpm's checks**: the pins plus the test above, and `update-vendor.ts`.

## Source

Scramjet: https://github.com/MercuryWorkshop/scramjet (the controller is `packages/controller`). The
AGPL requires us to offer the corresponding source to users of the deployed site: `/source.html`
links it, and our own files are served unminified.

## Updating

`node sandbox/update-vendor.ts --check` re-downloads the pinned versions and confirms the registry,
integrity, provenance and files still match. To move to new versions:

```
node sandbox/update-vendor.ts @mercuryworkshop/scramjet@<v> @mercuryworkshop/scramjet-controller@<v>
```

It uses Node built-ins only and runs no package code. It refuses versions younger than 48 h or with
install scripts, requires the SLSA provenance to name `MercuryWorkshop/scramjet` at the matching tag,
checks the tarball's sha512 against `dist.integrity`, then extracts only the pinned files and rewrites
`vendor/VENDOR.json`. It doesn't verify the attestation's signature: run `npm audit signatures` in a
scratch install for that. Then read the diff of the files (and of the source maps' `sourcesContent`),
update this file and `THIRD-PARTY-NOTICES`, and run `node scripts/e2e.ts sandbox`. Scramjet's API churns
(v3 is on `main`): expect porting work.
