Elffuss BraidHub

utopia-ia/elffuss-code public

main · 6.9 KiBRenderedRawPermalink
1# Level 2 vendor bundle
2
3The runtime that lets Elffuss Code run the code of VS Code web extensions:
4a headless VS Code (`@codingame/monaco-vscode-api` 37.3.11, VS Code 1.138.0)
5that runs inside a sandbox iframe on a separate site with no network. Code's
6own JavaScript stays buildless; only this bundle is built, and only here.
7
8This folder is the only place in the repository where npm runs.
9
10## What it produces
11
12Three single-file ES modules, gzipped, plus the licences of what they bundle:
13
14| File | Role |
15|---|---|
16| `sandbox-main.js.gz` | VS Code services, extension manager, hidden mirror editor |
17| `exthost-worker.js.gz` | the extension host, which runs extension code in a worker |
18| `editor-worker.js.gz` | VS Code's editor worker for the mirror editor |
19| `LICENSES.txt` | every bundled package's licence |
20
21They go to `web/vendor/x2/<buildId>/`, which git ignores. The `buildId` is the
22first 16 hex characters of a sha256 over the files' hashes, so it changes
23exactly when the bytes change. The build also writes
24`web/js/ext2/vendor-manifest.json` (committed, a few KB): sizes, the sha256 of
25each raw file and an SRI value for each `.gz`. Code's page checks both before
26it hands a byte to the sandbox (`web/js/ext2/vendor.js`).
27
28Not shipped: jschardet (LGPL-2.1), the code-page tables of
29`@vscode/iconv-lite-umd`, `@vscode/diff` (a wasm binary and its own worker)
30and VS Code's keyboard layout tables. `src/stubs/` replaces them with small
31stand-ins; the sandbox only ever sees UTF-8 text and never receives key
32events.
33
34## Build
35
36```sh
37cd vendor/vscode-ext2
38npm ci --ignore-scripts # .npmrc also sets ignore-scripts
39node build.mjs
40```
41
42`build.mjs` refuses to run on any Node version other than `.node-version`, or
43when an installed package differs from the lockfile. It fails, writing
44nothing, when:
45
46- the path sweep finds anything (below);
47- an entry produces more than one file;
48- the three `.gz` files together exceed 2.8 MB (`BUDGET_GZ` in `postbuild.mjs`).
49
50The `.gz` files are written by `postbuild.mjs` itself (level 9, no time stamp,
51no OS byte). Their bytes depend on Node's zlib, so they are reproducible for
52the pinned Node version on the same CPU architecture; the raw files, and so
53the `buildId`, do not depend on zlib.
54
55## Checks
56
57```sh
58node verify-repro.mjs # two clean builds in different folders: byte-identical, equal to the committed manifest
59node sweep.mjs # sweep the built folder named by the manifest
60node sweep.mjs --list <dir> # print every generic hit with its context, to review an allowlist change
61node check-output.mjs # the built folder against the manifest: only its files, SRI, sha256, sweep
62```
63
64`verify-repro.mjs` needs 15 GB of free disk and puts its temporary folders
65under `$X2_REPRO_TMP` (default: the system temp folder).
66
67The sweep fails on the user name, the home folder, the build folder or the
68repository folder anywhere in the output, including inside base64 `data:`
69URLs. Generic patterns (home prefixes of macOS, Linux and Windows, file URLs
70and source-map comments) are allowed only when the exact hit is listed in
71`sweep-allowlist.json` with its count. A hit is identified by the sha256 of
72the literal it sits in (up to 40 characters either side, cut at quotes and
73line breaks), so renamed minified code around it does not change the list,
74but any new literal, or a different count, fails the build. Today's allowed
75hits are VS Code's own help-text example paths and its file-URL checks.
76
77## Where it is served from
78
79From Code's own origin, `https://code.elffuss.com/vendor/x2/<buildId>/…`, with:
80
81```
82location ^~ /vendor/x2/ { default_type application/octet-stream; gzip off;
83 add_header Cache-Control "public, max-age=31536000, immutable";
84 add_header X-Content-Type-Options nosniff always; }
85```
86
87`application/octet-stream` keeps browsers from decoding the `.gz` on their own:
88the page decompresses it with `DecompressionStream`, then checks the sha256 of
89the raw bytes. That works whatever transfer compression a proxy adds.
90
91Cache-Control has no `always`, so nginx adds it only to successful responses.
92With `always`, a 404 for a build that is not on the server yet would be cached
93as immutable for a year; because the `buildId` is a content hash, uploading
94the same bytes afterwards would not reach the browsers that cached the
95failure: only a new `buildId` would. `tests/x2_headers.mjs` (H5) checks that a
96missing file is not cached that way, also against a deployment.
97
98Nothing is published to npm or a CDN, and nothing large goes into git.
99
100## Deploy
101
1020. **Merge first.** Only this branch's `deploy.sh` protects `vendor/x2/` from
103 its `rsync --delete`; a Code deploy from a tree without that filter (main
104 today) deletes the uploaded bundle. `deploy-vendor.sh` refuses to run until
105 `main`'s `deploy.sh` has the filter.
1061. `./deploy-vendor.sh` (repository root; reads `ELFFUSS_HOST` and
107 `ELFFUSS_KEY`, like `deploy.sh`). It checks the local folder against the
108 manifest (`check-output.mjs`: exactly the manifest's files and nothing
109 else), uploads only those files with `rsync --ignore-existing` (never
110 `--delete`), then requires the server's folder to hold exactly those files
111 with the manifest's sha256 sums.
1122. `./deploy.sh`, which ships the manifest naming the new `buildId`. A normal
113 deploy neither uploads nor deletes anything under `vendor/x2/`. Once level
114 2 is live (the manifest enabled and `web/js/ext2/config.js` naming a
115 sandbox for Code), it refuses to ship a manifest whose build the server
116 does not hold, byte for byte (`check-output.mjs --manifest-sums`, from the
117 manifest alone).
118
119If a browser still finds a build missing (a partial upload, a pruned
120rollback), level 2 fails closed and the default path is unaffected; the
121failure is not cached as long as Cache-Control has no `always` (above). Old
122builds stay until a manual prune keeps the last three; reverting the
123manifest and redeploying is the rollback. Setting `"enabled": false` in the
124manifest is the global kill switch.
125
126## Upgrade checklist
127
1281. Bump the exact versions in `package.json` (all `@codingame/*` packages
129 and the `monaco-editor` alias together).
1302. `npm install --ignore-scripts`, then `node build.mjs`,
131 `node verify-repro.mjs` and `node sweep.mjs`. Review any allowlist change
132 with `--list`.
1333. Check that the library's `webWorkerExtensionHostIframe.html` still matches
134 `sandbox/x2/v1/exthost-iframe.html` apart from the CSP meta, and that its
135 inline-script hash is unchanged.
1364. Diff the API-surface snapshot (`tests/x2-surface.json`, rewritten with
137 `node tests/x2_smoke.mjs --update`) and review the RPC allowlist
138 (`web/js/ext2/rpc-allowlist.json`): every actor must be either allowed or
139 listed in `deniedActors`, and `node tests/x2_unit.mjs` fails until it is.
1405. Run all suites in both modes, plus the canary.
1416. Re-run the runtime census (`tests/x2_census.mjs`).
142
143No library source is patched on disk; every hook is a runtime wrap in
144`web/js/ext2/sandbox-relay.js`.