Elffuss BraidHub

utopia-ia/elffuss-code public

main · 6.9 KiBSourceRawPermalink

Level 2 vendor bundle

The runtime that lets Elffuss Code run the code of VS Code web extensions: a headless VS Code (@codingame/monaco-vscode-api 37.3.11, VS Code 1.138.0) that runs inside a sandbox iframe on a separate site with no network. Code's own JavaScript stays buildless; only this bundle is built, and only here.

This folder is the only place in the repository where npm runs.

What it produces

Three single-file ES modules, gzipped, plus the licences of what they bundle:

FileRole
sandbox-main.js.gzVS Code services, extension manager, hidden mirror editor
exthost-worker.js.gzthe extension host, which runs extension code in a worker
editor-worker.js.gzVS Code's editor worker for the mirror editor
LICENSES.txtevery bundled package's licence

They go to web/vendor/x2/<buildId>/, which git ignores. The buildId is the first 16 hex characters of a sha256 over the files' hashes, so it changes exactly when the bytes change. The build also writes web/js/ext2/vendor-manifest.json (committed, a few KB): sizes, the sha256 of each raw file and an SRI value for each .gz. Code's page checks both before it hands a byte to the sandbox (web/js/ext2/vendor.js).

Not shipped: jschardet (LGPL-2.1), the code-page tables of @vscode/iconv-lite-umd, @vscode/diff (a wasm binary and its own worker) and VS Code's keyboard layout tables. src/stubs/ replaces them with small stand-ins; the sandbox only ever sees UTF-8 text and never receives key events.

Build

cd vendor/vscode-ext2
npm ci --ignore-scripts        # .npmrc also sets ignore-scripts
node build.mjs

build.mjs refuses to run on any Node version other than .node-version, or when an installed package differs from the lockfile. It fails, writing nothing, when:

The .gz files are written by postbuild.mjs itself (level 9, no time stamp, no OS byte). Their bytes depend on Node's zlib, so they are reproducible for the pinned Node version on the same CPU architecture; the raw files, and so the buildId, do not depend on zlib.

Checks

node verify-repro.mjs          # two clean builds in different folders: byte-identical, equal to the committed manifest
node sweep.mjs                 # sweep the built folder named by the manifest
node sweep.mjs --list <dir>    # print every generic hit with its context, to review an allowlist change
node check-output.mjs          # the built folder against the manifest: only its files, SRI, sha256, sweep

verify-repro.mjs needs 15 GB of free disk and puts its temporary folders under $X2_REPRO_TMP (default: the system temp folder).

The sweep fails on the user name, the home folder, the build folder or the repository folder anywhere in the output, including inside base64 data: URLs. Generic patterns (home prefixes of macOS, Linux and Windows, file URLs and source-map comments) are allowed only when the exact hit is listed in sweep-allowlist.json with its count. A hit is identified by the sha256 of the literal it sits in (up to 40 characters either side, cut at quotes and line breaks), so renamed minified code around it does not change the list, but any new literal, or a different count, fails the build. Today's allowed hits are VS Code's own help-text example paths and its file-URL checks.

Where it is served from

From Code's own origin, https://code.elffuss.com/vendor/x2/<buildId>/…, with:

location ^~ /vendor/x2/ { default_type application/octet-stream; gzip off;
  add_header Cache-Control "public, max-age=31536000, immutable";
  add_header X-Content-Type-Options nosniff always; }

application/octet-stream keeps browsers from decoding the .gz on their own: the page decompresses it with DecompressionStream, then checks the sha256 of the raw bytes. That works whatever transfer compression a proxy adds.

Cache-Control has no always, so nginx adds it only to successful responses. With always, a 404 for a build that is not on the server yet would be cached as immutable for a year; because the buildId is a content hash, uploading the same bytes afterwards would not reach the browsers that cached the failure: only a new buildId would. tests/x2_headers.mjs (H5) checks that a missing file is not cached that way, also against a deployment.

Nothing is published to npm or a CDN, and nothing large goes into git.

Deploy

  1. Merge first. Only this branch's deploy.sh protects vendor/x2/ from its rsync --delete; a Code deploy from a tree without that filter (main today) deletes the uploaded bundle. deploy-vendor.sh refuses to run until main's deploy.sh has the filter.
  2. ./deploy-vendor.sh (repository root; reads ELFFUSS_HOST and ELFFUSS_KEY, like deploy.sh). It checks the local folder against the manifest (check-output.mjs: exactly the manifest's files and nothing else), uploads only those files with rsync --ignore-existing (never --delete), then requires the server's folder to hold exactly those files with the manifest's sha256 sums.
  3. ./deploy.sh, which ships the manifest naming the new buildId. A normal deploy neither uploads nor deletes anything under vendor/x2/. Once level 2 is live (the manifest enabled and web/js/ext2/config.js naming a sandbox for Code), it refuses to ship a manifest whose build the server does not hold, byte for byte (check-output.mjs --manifest-sums, from the manifest alone).

If a browser still finds a build missing (a partial upload, a pruned rollback), level 2 fails closed and the default path is unaffected; the failure is not cached as long as Cache-Control has no always (above). Old builds stay until a manual prune keeps the last three; reverting the manifest and redeploying is the rollback. Setting "enabled": false in the manifest is the global kill switch.

Upgrade checklist

  1. Bump the exact versions in package.json (all @codingame/* packages and the monaco-editor alias together).
  2. npm install --ignore-scripts, then node build.mjs, node verify-repro.mjs and node sweep.mjs. Review any allowlist change with --list.
  3. Check that the library's webWorkerExtensionHostIframe.html still matches sandbox/x2/v1/exthost-iframe.html apart from the CSP meta, and that its inline-script hash is unchanged.
  4. Diff the API-surface snapshot (tests/x2-surface.json, rewritten with node tests/x2_smoke.mjs --update) and review the RPC allowlist (web/js/ext2/rpc-allowlist.json): every actor must be either allowed or listed in deniedActors, and node tests/x2_unit.mjs fails until it is.
  5. Run all suites in both modes, plus the canary.
  6. Re-run the runtime census (tests/x2_census.mjs).

No library source is patched on disk; every hook is a runtime wrap in web/js/ext2/sandbox-relay.js.