Elffuss BraidHub

utopia-ia/elffuss-code public

Put the extension sandbox on x2.utopiaia.com

Code on code.elffuss.com now has a sandbox origin: https://x2.utopiaia.com,
another registrable domain, so the sandbox shares no storage, cookies or
process with Code.

- config.js names it for code.elffuss.com, and sandbox/x2/headers.json
  names the same origin for the headers and nginx. A Code host under
  utopiaia.com would be the same site as the sandbox, and gets none.
- headers.mjs --nginx and --site-check use it by default, and the site
  check refuses an origin that headers.json and config.js do not both
  name.
- deploy-sandbox.sh deploys it to /var/www/x2.utopiaia.com by default;
  nginx.conf.example is the vhost for that host. The sandbox's
  frame-ancestors still allow only code.elffuss.com, and its frame-src
  only its own extension-host document.
- Tests: x2_unit (the origin in both files, the production CSP and the
  extension-host query), x2_deploy (the defaults, a mismatched origin
  refused before uploading, --live now on), x2_headers (the vhost names
  the same host), x2_ux X7 (a host with no sandbox is any other host).
- README: where the sandbox lives and the order to publish it.

Changeset00c23ea566f6be5f5f9c5a1b2b5f335691a7e1db3b5f78c3d458b7e45e2455ac
AuthorKikoCis <kikocisneros@gmail.com> · 2026-10-12 09:50 +02:00
CommitterKikoCis <kikocisneros@gmail.com> · 2026-10-12 09:50 +02:00
Parentsfb79c56b6281

Browse the files at this changeset

11 files changed

modified README.md +20 −18
@@ -55,10 +55,9 @@
5555 Color Theme picker), **TextMate grammars**, **snippets** and **language configurations**
5656 (comments, brackets, indentation). You can also install a `.vsix` file.
5757
58-- **No extension code runs** unless you turn it on for one extension (level 2, below,
59- not available on code.elffuss.com yet). Otherwise `main`/`browser` are ignored; the
60- panel says what each extension applies and what would need an extension host
61- (commands, views, debuggers…).
58+- **No extension code runs** unless you turn it on for one extension (level 2, below).
59+ Otherwise `main`/`browser` are ignored; the panel says what each extension applies and
60+ what would need an extension host (commands, views, debuggers…).
6261 - **Your project stays in the browser.** Open VSX only sees what you search for and install.
6362 - Packages are checked against the SHA-256 that Open VSX publishes and kept in IndexedDB.
6463 - Grammars run on the same engine as VS Code (vscode-textmate + Oniguruma), loaded only
@@ -84,7 +83,7 @@
8483 count), *"Runs in Code's sandbox"* (with its commands, keybindings and settings),
8584 *"Needs Node: not available in the browser"*, the parts that *won't appear here* (views,
8685 webviews, debugger…) and *"Tested in Code"* from the runtime census below. Where level 2
87-cannot run (code.elffuss.com today, Firefox, Safari, `?noext2`) the line says so with the
86+cannot run (Firefox, Safari, `?noext2`, a site with no sandbox) the line says so with the
8887 reason, the run button is inert, and the **Works in Code** chip keeps only what works
8988 there. An extension that declares proposed VS Code APIs is marked: Code does not turn those
9089 APIs on, so some of its parts may fail (the census shows many such extensions start). The
@@ -173,17 +172,20 @@
173172 debugger, source control, status bar), the network or the whole project, extensions that
174173 replace typing (Vim, Emacs), `createQuickPick` and `createInputBox`, gutter icons, and
175174 Firefox and Safari in this version.
176-- **Not available on code.elffuss.com yet:** the sandbox needs its own registrable domain
177- first: `web/js/ext2/config.js` refuses a sandbox on the same site as Code (a subdomain of
178- elffuss.com would share cookies and a process), and `deploy-sandbox.sh` checks it before
179- uploading. In order: merge this branch's `deploy.sh` filter for `vendor/x2/` into main
180- (any deploy without it deletes the bundle; `deploy-vendor.sh` refuses until main has
181- it), then `sandbox/x2/nginx.conf.example` (Code's vendor location sets Cache-Control
182- without `always`, so a missing file is never cached as immutable), `deploy-sandbox.sh`,
183- `deploy-vendor.sh` and `deploy.sh` (which refuses to ship a manifest whose build the
184- server lacks). Locally, open Code on `http://127.0.0.1:<port>` with
185- `tests/lib/x2-server.mjs`, which serves the sandbox on `localhost:<port>` (a different
186- site).
175+- **Where the sandbox lives:** for code.elffuss.com, on `https://x2.utopiaia.com`, another
176+ registrable domain. `web/js/ext2/config.js` names it and refuses a sandbox on the same
177+ site as Code (a subdomain of elffuss.com would share cookies and a process);
178+ `sandbox/x2/headers.json` names the same origin for the headers and nginx, and
179+ `deploy-sandbox.sh` checks that both agree before uploading. Code on any other host gets
180+ no sandbox. To publish, in order: the `deploy.sh` filter for `vendor/x2/` on main (any
181+ deploy without it deletes the bundle; `deploy-vendor.sh` refuses until main has it),
182+ `sandbox/x2/nginx.conf.example` for x2.utopiaia.com and Code's vendor location
183+ (Cache-Control without `always`, so a missing file is never cached as immutable),
184+ `deploy-sandbox.sh`, `deploy-vendor.sh`, a read-only check with
185+ `X2_SANDBOX=https://x2.utopiaia.com node tests/x2_headers.mjs`, and `deploy.sh` last
186+ (it refuses to ship a manifest whose build the server lacks). Locally, open Code on
187+ `http://127.0.0.1:<port>` with `tests/lib/x2-server.mjs`, which serves the sandbox on
188+ `localhost:<port>` (a different site).
187189
188190 **What actually runs (runtime census, 2026-10-11).** Of the 500 most downloaded extensions
189191 on Open VSX, 89 have a browser entry. `tests/x2_census.mjs` installed each one from its
@@ -249,8 +251,8 @@
249251 | Suite | What it proves |
250252 |---|---|
251253 | `x2_unit` | protocol validators, escaped markdown on a hostile corpus, conversions, keybindings and reserved chords, globs, headers, manifests, the RPC allowlist, the decoration whitelist, URL display, classification, texts, the package reader, the shipped census |
252-| `x2_headers` | the sandbox documents' exact headers, 404 for anything else, Code never serves `/x2/`, the vendor files' headers and SRI, a missing vendor file not cached (also against a deployment); the generated nginx snippets |
253-| `x2_deploy` | the deploy scripts against a folder that plays the server (fake `git`, `ssh` and `rsync`): only the manifest's files go up and nothing else may be there, a stray or corrupt file stops it, main must protect `vendor/x2/` first, the sandbox must be another site |
254+| `x2_headers` | the sandbox documents' exact headers, 404 for anything else, Code never serves `/x2/`, the vendor files' headers and SRI, a missing vendor file not cached (also against production); the generated nginx snippets, and the sandbox vhost naming x2.utopiaia.com |
255+| `x2_deploy` | the deploy scripts against a folder that plays the server (fake `git`, `ssh` and `rsync`): only the manifest's files go up and nothing else may be there, a stray or corrupt file stops it, main must protect `vendor/x2/` first, the sandbox must be another site and the one `headers.json` and `config.js` name (by default it deploys x2.utopiaia.com) |
254256 | `x2_smoke` | synthetic extensions end to end: commands, formatting, hovers, symbols, diagnostics, decorations, dialogs, the gates, the firewall, tampering, `?noext`/`?noext2`/kill switch |
255257 | `x2_bytes` | the default path and the level 1 states against main before level 2 (above) |
256258 | `x2_canary` | the canary and the drill (above), with positive controls |
modified deploy-sandbox.sh +19 −12
@@ -1,32 +1,39 @@
11 #!/usr/bin/env bash
22 # Sube los dos documentos del recinto de extensiones (sandbox/x2/v1/) a la
3-# carpeta que sirve el dominio del recinto, x2.<dominio-del-recinto>. NUNCA a
4-# la de Code: que el sitio de Code no sirva el recinto es parte del
5-# aislamiento. Las cabeceras (CSP sin ningún host, Permissions-Policy…) las
6-# pone nginx con los fragmentos que genera:
7-# node sandbox/x2/headers.mjs --nginx --sandbox https://x2.<dominio>
8-# (plantilla del vhost: sandbox/x2/nginx.conf.example)
3+# carpeta que sirve el host del recinto, x2.utopiaia.com. NUNCA a la de Code:
4+# que el sitio de Code no sirva el recinto es parte del aislamiento. Las
5+# cabeceras (CSP sin ningún host, Permissions-Policy…) las pone nginx con los
6+# fragmentos que genera:
7+# node sandbox/x2/headers.mjs --nginx
8+# (el vhost: sandbox/x2/nginx.conf.example)
99 #
1010 # export ELFFUSS_HOST=usuario@servidor ELFFUSS_KEY=~/.ssh/tu_clave
11-# export X2_SANDBOX_DEST=/var/www/<carpeta-del-recinto>
12-# export X2_SANDBOX_ORIGIN=https://x2.<dominio-del-recinto>
1311 # ./deploy-sandbox.sh
1412 #
13+# El origen sale de sandbox/x2/headers.json (el recinto de producción) y la
14+# carpeta es /var/www/<host del recinto>. X2_SANDBOX_ORIGIN y X2_SANDBOX_DEST
15+# los cambian (las pruebas lo hacen), pero el paso 0 se niega si ese origen no
16+# es el que nombran headers.json y web/js/ext2/config.js.
17+#
1518 # Orden: este script, luego deploy-vendor.sh, luego deploy.sh (que publica
16-# web/js/ext2/config.js con el dominio del recinto).
19+# web/js/ext2/config.js con el recinto).
1720 set -euo pipefail
1821 cd "$(dirname "$0")"
1922
2023 HOST=${ELFFUSS_HOST:?define ELFFUSS_HOST (usuario@servidor) antes de desplegar}
2124 KEY=${ELFFUSS_KEY:?define ELFFUSS_KEY (ruta a la clave ssh)}
22-DEST=${X2_SANDBOX_DEST:?define X2_SANDBOX_DEST (la carpeta que sirve x2.<dominio-del-recinto>)}
23-ORIGIN=${X2_SANDBOX_ORIGIN:?define X2_SANDBOX_ORIGIN (https://x2.<dominio-del-recinto>)}
25+ORIGIN=${X2_SANDBOX_ORIGIN:-$(node -e "process.stdout.write(JSON.parse(require('fs').readFileSync('sandbox/x2/headers.json','utf8')).environments.production.sandbox||'')")}
26+case "$ORIGIN" in
27+ (https://*.*) ;;
28+ (*) echo "no hay recinto de producción (sandbox/x2/headers.json) ni X2_SANDBOX_ORIGIN: «$ORIGIN»" >&2; exit 1;;
29+esac
30+DEST=${X2_SANDBOX_DEST:-/var/www/${ORIGIN#https://}}
2431 case "$DEST" in
2532 (*elffuss-code*|*/web|*/web/|/) echo "X2_SANDBOX_DEST no puede ser la carpeta de Code: $DEST" >&2; exit 1;;
2633 esac
2734
2835 # 0. el recinto es OTRO SITIO que Code (otro dominio registrable), y
29-# config.js nombra ese mismo origen
36+# headers.json y config.js nombran ese mismo origen
3037 node sandbox/x2/headers.mjs --site-check "$ORIGIN"
3138
3239 # 1. los documentos cuadran con headers.json (hash del script en línea y CSP
modified sandbox/x2/headers.json +1 −1
@@ -6,7 +6,7 @@
66 "code": [
77 "https://code.elffuss.com"
88 ],
9- "sandbox": null
9+ "sandbox": "https://x2.utopiaia.com"
1010 },
1111 "dev": {
1212 "code": [
modified sandbox/x2/headers.mjs +19 −10
@@ -11,12 +11,15 @@
1111 // node sandbox/x2/headers.mjs --pin
1212 // recompute sandbox.html's bootstrap hash and write it to headers.json
1313 // and to the document's meta CSP
14-// node sandbox/x2/headers.mjs --nginx --sandbox https://x2.<domain>
15-// print snippets/x2-sandbox.conf and snippets/x2-exthost.conf (refused
16-// when that origin is the same site as Code)
17-// node sandbox/x2/headers.mjs --site-check https://x2.<domain>
18-// the sandbox origin is another registrable domain than every Code
19-// origin, and web/js/ext2/config.js names that one (deploy-sandbox.sh)
14+// node sandbox/x2/headers.mjs --nginx [--sandbox https://x2.<domain>]
15+// print snippets/x2-sandbox.conf and snippets/x2-exthost.conf for the
16+// production sandbox of headers.json (https://x2.utopiaia.com), or for
17+// the one given (refused when it is not the one headers.json and
18+// config.js name, or is the same site as Code)
19+// node sandbox/x2/headers.mjs --site-check [https://x2.<domain>]
20+// that sandbox origin (by default headers.json's) is another registrable
21+// domain than every Code origin, and both headers.json and
22+// web/js/ext2/config.js name it (deploy-sandbox.sh)
2023 import fs from 'node:fs';
2124 import path from 'node:path';
2225 import crypto from 'node:crypto';
@@ -149,17 +152,21 @@
149152 // registrable domain), or it would share cookies and a process with Code.
150153 // web/js/ext2/config.js refuses a same-site sandbox at run time; this refuses
151154 // it before anything is deployed.
155+export const productionSandbox = () => loadSpec().environments.production.sandbox || null;
156+
152157 export async function siteProblems(sandbox) {
153158 const { sameSite, sandboxOrigin } = await import('../../web/js/ext2/config.js');
154159 const problems = [];
155160 let u;
156161 try { u = new URL(sandbox); } catch { return ['not a URL: ' + sandbox]; }
157162 if (u.protocol !== 'https:' || u.origin !== sandbox.replace(/\/$/, '')) problems.push('the sandbox origin must be https://host, with nothing after it: ' + sandbox);
163+ const named = productionSandbox();
164+ if (named !== u.origin) problems.push(`sandbox/x2/headers.json names ${named || 'no sandbox'} for production, not ${u.origin}`);
158165 for (const code of loadSpec().environments.production.code) {
159166 if (sameSite(code, u.origin)) problems.push(`${u.origin} is the same site as ${code}: use another registrable domain`);
160167 const c = new URL(code);
161168 const configured = sandboxOrigin({ hostname: c.hostname, origin: c.origin, port: c.port });
162- if (configured && configured !== u.origin) problems.push(`web/js/ext2/config.js names ${configured} for ${c.hostname}, not ${u.origin}`);
169+ if (configured !== u.origin) problems.push(`web/js/ext2/config.js names ${configured || 'no sandbox'} for ${c.hostname}, not ${u.origin}`);
163170 }
164171 return problems;
165172 }
@@ -167,16 +174,18 @@
167174 if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
168175 const args = process.argv.slice(2);
169176 if (args.includes('--pin')) pin();
177+ // the origin after a flag, or headers.json's production sandbox when none is given
178+ const after = flag => { const v = args[args.indexOf(flag) + 1]; return v && !v.startsWith('--') ? v : null; };
170179 if (args.includes('--site-check')) {
171- const s = args[args.indexOf('--site-check') + 1] || '';
180+ const s = after('--site-check') || productionSandbox() || '';
172181 const problems = await siteProblems(s);
173182 for (const p of problems) console.error(' ✗ ' + p);
174183 console.log(problems.length ? `${problems.length} problems` : `${s} is another site than Code`);
175184 process.exit(problems.length ? 1 : 0);
176185 }
177186 if (args.includes('--nginx')) {
178- const s = args[args.indexOf('--sandbox') + 1];
179- if (!args.includes('--sandbox') || !/^https:\/\/[a-z0-9.-]+$/.test(s || '')) { console.error('--nginx needs --sandbox https://x2.<domain>'); process.exit(2); }
187+ const s = (args.includes('--sandbox') ? after('--sandbox') : productionSandbox()) || '';
188+ if (!/^https:\/\/[a-z0-9.-]+$/.test(s)) { console.error('--nginx needs a sandbox origin https://x2.<domain> (headers.json or --sandbox)'); process.exit(2); }
180189 const problems = await siteProblems(s);
181190 if (problems.length) { for (const p of problems) console.error(' ✗ ' + p); process.exit(1); }
182191 process.stdout.write(nginx(s));
modified sandbox/x2/nginx.conf.example +18 −16
@@ -1,23 +1,26 @@
1-# nginx for the level 2 extension sandbox of Elffuss Code. A TEMPLATE: replace
2-# SANDBOX_DOMAIN (a registrable domain used only for this) and SANDBOX_DIR
3-# (the folder deploy-sandbox.sh fills), then generate the two header snippets:
1+# nginx for the level 2 extension sandbox of Elffuss Code, on x2.utopiaia.com:
2+# another registrable domain than code.elffuss.com (web/js/ext2/config.js and
3+# sandbox/x2/headers.json name this origin; deploy-sandbox.sh refuses any
4+# other). Its folder is /var/www/x2.utopiaia.com, the one deploy-sandbox.sh
5+# fills, owned by the user that deploys. Generate the two header snippets with
46 #
5-# node sandbox/x2/headers.mjs --nginx --sandbox https://x2.SANDBOX_DOMAIN
7+# node sandbox/x2/headers.mjs --nginx
68 #
79 # and save them as /etc/nginx/snippets/x2-sandbox.conf and x2-exthost.conf.
810 # Order (README, "Extensions that run code"): main's deploy.sh protecting
9-# vendor/x2/ first (deploy-vendor.sh refuses until it does), DNS and
10-# certificate for a domain that is not a subdomain of Code's, this vhost,
11-# nginx -t and reload, deploy-sandbox.sh, deploy-vendor.sh, then deploy.sh
12-# with web/js/ext2/config.js naming the sandbox. Until that last step Code
13-# says "not available on this site" and nothing changes for anyone.
11+# vendor/x2/ first (deploy-vendor.sh refuses until it does), x2.utopiaia.com
12+# resolving to the server that serves Code and its certificate, this vhost
13+# and Code's vendor location (at the end of this file), nginx -t and reload,
14+# deploy-sandbox.sh, deploy-vendor.sh, and deploy.sh last: it publishes
15+# config.js naming this sandbox, and refuses while the server lacks the bundle
16+# the manifest names.
1417
1518 server {
1619 listen 443 ssl http2;
17- server_name x2.SANDBOX_DOMAIN;
18- ssl_certificate /etc/letsencrypt/live/x2.SANDBOX_DOMAIN/fullchain.pem;
19- ssl_certificate_key /etc/letsencrypt/live/x2.SANDBOX_DOMAIN/privkey.pem;
20- root /var/www/SANDBOX_DIR;
20+ server_name x2.utopiaia.com;
21+ ssl_certificate /etc/letsencrypt/live/x2.utopiaia.com/fullchain.pem;
22+ ssl_certificate_key /etc/letsencrypt/live/x2.utopiaia.com/privkey.pem;
23+ root /var/www/x2.utopiaia.com;
2124 access_log off; # the sandbox keeps no log of who loaded it
2225 autoindex off;
2326 server_tokens off;
@@ -30,9 +33,8 @@
3033 }
3134
3235 # the extension-host document: only the exact query the library builds
33- # (escape the dots of the domain in the pattern: x2\.example\.org)
3436 location = /x2/v1/exthost-iframe.html {
35- if ($args !~ "^parentOrigin=https%3A%2F%2Fx2\.SANDBOX_DOMAIN_ESCAPED&vscodeWebWorkerExtHostId=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$") { return 404; }
37+ if ($args !~ "^parentOrigin=https%3A%2F%2Fx2\.utopiaia\.com&vscodeWebWorkerExtHostId=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$") { return 404; }
3638 include snippets/x2-exthost.conf;
3739 try_files $uri =404;
3840 }
@@ -43,7 +45,7 @@
4345
4446 server {
4547 listen 80;
46- server_name x2.SANDBOX_DOMAIN;
48+ server_name x2.utopiaia.com;
4749 access_log off;
4850 return 301 https://$host$request_uri;
4951 }
modified tests/lib/x2-server.mjs +1 −2
@@ -47,8 +47,7 @@
4747 const envInsecure = () => { const v = process.env.X2_INSECURE; return v === 'all' ? 'all' : v === '1' || v === 'exthost' ? 'exthost' : false; };
4848
4949 // codeAliases: other host names that also get Code (with the browser told to
50-// resolve them to 127.0.0.1), to see Code where level 2 has no sandbox, as on
51-// code.elffuss.com today.
50+// resolve them to 127.0.0.1), to see Code on a host config.js gives no sandbox.
5251 export async function startServer({ port = 0, webRoot = path.join(REPO, 'web'), insecure = envInsecure(), tamper = process.env.X2_TAMPER === '1', quiet = true, codeAliases = [] } = {}) {
5352 const requests = []; // { host, method, url }
5453 let codeHost = null, sandboxHost = null, origins = null;
modified tests/x2_deploy.mjs +23 −7
@@ -14,11 +14,13 @@
1414 // server's whole folder is compared with the manifest
1515 // D4 a stray file already on the server makes it fail (full listing, not
1616 // a glob)
17-// D5 deploy-sandbox.sh refuses a sandbox on Code's own site
17+// D5 deploy-sandbox.sh refuses a sandbox on Code's own site, and one that
18+// headers.json and config.js do not name, before any upload
1819 // D6 deploy-sandbox.sh uploads the two documents only, even with a stray
19-// file next to them, and removes anything else on the server
20+// file next to them, and removes anything else on the server; with
21+// nothing set, it deploys x2.utopiaia.com (headers.json) to its folder
2022 // D7 check-output.mjs --live: browsers ask for the bundle only when the
21-// manifest is on and config.js gives Code a sandbox
23+// manifest is on and config.js gives Code a sandbox (it does now)
2224 import fs from 'node:fs';
2325 import os from 'node:os';
2426 import path from 'node:path';
@@ -131,27 +133,41 @@
131133 // D5
132134 r = run('deploy-sandbox.sh', { X2_SANDBOX_DEST: '/var/www/x2-sandbox', X2_SANDBOX_ORIGIN: 'https://x2.elffuss.com' });
133135 ok('D5 deploy-sandbox.sh refuses a sandbox on Code’s own site (x2.elffuss.com), before uploading', r.code === 1 && /same site as https:\/\/code\.elffuss\.com/.test(r.out) && !r.calls.some(c => /^(ssh|rsync) /.test(c)), r.out.slice(0, 300));
136+r = run('deploy-sandbox.sh', { X2_SANDBOX_DEST: '/var/www/x2-sandbox', X2_SANDBOX_ORIGIN: 'https://x2.sandbox-elsewhere.example' });
137+ok('D5 …and a sandbox on another site that headers.json and config.js do not name, before uploading', r.code === 1
138+ && /headers\.json names https:\/\/x2\.utopiaia\.com for production/.test(r.out) && /config\.js names https:\/\/x2\.utopiaia\.com for code\.elffuss\.com/.test(r.out)
139+ && !r.calls.some(c => /^(ssh|rsync) /.test(c)), r.out.slice(0, 300));
134140
135141 // D6
136142 fs.writeFileSync(path.join(repo, 'sandbox/x2/v1/notes.txt'), 'not for the server\n');
137143 const sbx = path.join(server, 'x2-sandbox/x2/v1');
138144 fs.mkdirSync(sbx, { recursive: true });
139145 fs.writeFileSync(path.join(sbx, 'old.html'), 'an old document\n');
140-r = run('deploy-sandbox.sh', { X2_SANDBOX_DEST: '/var/www/x2-sandbox', X2_SANDBOX_ORIGIN: 'https://x2.sandbox-elsewhere.example' });
146+r = run('deploy-sandbox.sh', { X2_SANDBOX_DEST: '/var/www/x2-sandbox', X2_SANDBOX_ORIGIN: 'https://x2.utopiaia.com' });
141147 ok('D6 deploy-sandbox.sh uploads only its two documents (not a stray file next to them) and leaves nothing else on the server', r.code === 0
142148 && JSON.stringify(fs.readdirSync(sbx).sort()) === JSON.stringify(['exthost-iframe.html', 'sandbox.html']), r.out.slice(-300));
149+r = run('deploy-sandbox.sh');
150+const sbxProd = path.join(server, 'x2.utopiaia.com/x2/v1');
151+ok('D6 with no origin or folder set, it deploys x2.utopiaia.com (headers.json) to /var/www/x2.utopiaia.com', r.code === 0
152+ && r.calls.some(c => c.startsWith('rsync ') && c.endsWith(':/var/www/x2.utopiaia.com/x2/v1/'))
153+ && fs.existsSync(sbxProd) && JSON.stringify(fs.readdirSync(sbxProd).sort()) === JSON.stringify(['exthost-iframe.html', 'sandbox.html'])
154+ && /X2_SANDBOX=https:\/\/x2\.utopiaia\.com node tests\/x2_headers\.mjs/.test(r.out), r.out.slice(-300));
143155
144156 // D7
145157 const live = (env = {}) => spawnSync('node', [path.join(repo, 'vendor/vscode-ext2/check-output.mjs'), '--live', path.join(repo, 'web')], { encoding: 'utf8', env: { ...process.env, ...env } }).status;
146158 const today = live();
147159 const cfg = path.join(repo, 'web/js/ext2/config.js');
148160 const cfg0 = fs.readFileSync(cfg, 'utf8');
149-fs.writeFileSync(cfg, cfg0.replace("'code.elffuss.com': null,", "'code.elffuss.com': 'https://x2.sandbox-elsewhere.example',"));
150-const withSandbox = live();
161+const PROD = "'code.elffuss.com': 'https://x2.utopiaia.com',";
162+const cfgNone = cfg0.replace(PROD, "'code.elffuss.com': null,");
163+fs.writeFileSync(cfg, cfgNone);
164+const noSandbox = live();
165+fs.writeFileSync(cfg, cfg0);
151166 const man = path.join(repo, 'web/js/ext2/vendor-manifest.json');
152167 fs.writeFileSync(man, JSON.stringify({ ...manifest, enabled: false }));
153168 const switchedOff = live();
154-ok('D7 check-output --live: not today (config.js gives Code no sandbox), yes once it does, no with the kill switch', today === 3 && withSandbox === 0 && switchedOff === 3, JSON.stringify({ today, withSandbox, switchedOff }));
169+ok('D7 check-output --live: yes today (config.js gives Code x2.utopiaia.com), no without a sandbox for Code, no with the kill switch', cfg0.includes(PROD) && cfgNone !== cfg0
170+ && today === 0 && noSandbox === 3 && switchedOff === 3, JSON.stringify({ today, noSandbox, switchedOff }));
155171
156172 fs.rmSync(T, { recursive: true, force: true });
157173 console.log(fails ? `\n❌ ${fails} failed` : '\n✅ all passed');
modified tests/x2_headers.mjs +11 −2
@@ -2,8 +2,9 @@
22 //
33 // node tests/x2_headers.mjs
44 // against its own test server (tests/lib/x2-server.mjs)
5-// X2_SANDBOX=https://x2.<domain> X2_CODE=https://code.elffuss.com node tests/x2_headers.mjs
6-// against a deployment (after deploy-sandbox.sh, deploy-vendor.sh and deploy.sh)
5+// X2_SANDBOX=https://x2.utopiaia.com X2_CODE=https://code.elffuss.com node tests/x2_headers.mjs
6+// against production, once deploy-sandbox.sh and deploy-vendor.sh ran
7+// (it needs nothing from deploy.sh, so it can check before it too)
78 //
89 // Checks:
910 // H1 both sandbox documents, with their exact query shape: status 200, every
@@ -154,6 +155,14 @@
154155 const vendorBlock = /location \^~ \/vendor\/x2\/ \{[\s\S]*?\}/.exec(example)?.[0] || '';
155156 ok('H6 the template for Code’s vendor location adds Cache-Control only to successful responses (no always)',
156157 /add_header Cache-Control "public, max-age=31536000, immutable";/.test(vendorBlock) && !/Cache-Control[^\n]*always/.test(vendorBlock), vendorBlock.replace(/\s+/g, ' ').slice(0, 200));
158+ // el vhost del recinto nombra el mismo host que headers.json (y config.js)
159+ const prodHost = new URL(spec.environments.production.sandbox).hostname;
160+ const esc = prodHost.replace(/\./g, '\\.');
161+ const names = [...example.matchAll(/^\s*server_name ([^;]+);/gm)].map(m => m[1]);
162+ ok(`H6 the sandbox vhost of the template is ${prodHost}: server name, certificate, folder and the extension-host query`,
163+ names.length === 2 && names.every(n => n === prodHost)
164+ && example.includes(`/etc/letsencrypt/live/${prodHost}/fullchain.pem`) && example.includes(`root /var/www/${prodHost};`)
165+ && example.includes(`parentOrigin=https%3A%2F%2F${esc}&vscodeWebWorkerExtHostId=`), JSON.stringify(names));
157166 }
158167
159168 await srv?.close();
modified tests/x2_unit.mjs +20 −1
@@ -210,6 +210,17 @@
210210 }
211211 }
212212 ok('ninguna directiva de red nombra un host (ni \'self\')', noHost);
213+// producción: lo que pondrá nginx en x2.utopiaia.com
214+const prodO = originsFor('production');
215+const cspS = cspFor('sandbox.html', prodO), cspE = cspFor('exthost-iframe.html', prodO);
216+const uuid0 = '0123abcd-0123-4abc-8abc-0123456789ab';
217+ok('producción: el recinto solo enmarca su documento del host de extensiones, y solo Code enmarca el recinto',
218+ prodO.sandbox === 'https://x2.utopiaia.com' && / frame-src https:\/\/x2\.utopiaia\.com\/x2\/v1\/exthost-iframe\.html;/.test(cspS)
219+ && /frame-ancestors https:\/\/code\.elffuss\.com$/.test(cspS) && /frame-ancestors 'self' https:\/\/code\.elffuss\.com$/.test(cspE), cspS.slice(-160));
220+ok('producción: el host de extensiones solo con la consulta exacta, con x2.utopiaia.com como padre',
221+ queryAllowed('exthost-iframe.html', `?parentOrigin=${encodeURIComponent('https://x2.utopiaia.com')}&vscodeWebWorkerExtHostId=${uuid0}`, prodO)
222+ && !queryAllowed('exthost-iframe.html', `?parentOrigin=${encodeURIComponent('https://x2.utopiaiaXcom')}&vscodeWebWorkerExtHostId=${uuid0}`, prodO)
223+ && !queryAllowed('exthost-iframe.html', `?parentOrigin=${encodeURIComponent('https://code.elffuss.com')}&vscodeWebWorkerExtHostId=${uuid0}`, prodO));
213224 ok('frame-ancestors del host de extensiones incluye \'self\' y Code', /frame-ancestors 'self' http:\/\/127\.0\.0\.1:1234/.test(cspFor('exthost-iframe.html', dev)));
214225 ok('frame-src del recinto: solo su documento', /frame-src http:\/\/localhost:1234\/x2\/v1\/exthost-iframe\.html(;|$)/.test(cspFor('sandbox.html', dev)));
215226 ok('meta CSP sin frame-ancestors', !/frame-ancestors/.test(expectedMeta('sandbox.html')));
@@ -226,7 +237,15 @@
226237 ok('manifiesto roto no pasa', !validManifest({ ...vm, files: vm.files.slice(1) }) && !validManifest({ ...vm, buildId: '../x' }));
227238 ok('config: 127.0.0.1 → localhost del mismo puerto', sandboxOrigin({ hostname: '127.0.0.1', port: '8000', origin: 'http://127.0.0.1:8000' }) === 'http://localhost:8000');
228239 ok('config: localhost y hosts desconocidos → nada', sandboxOrigin({ hostname: 'localhost', port: '8000', origin: 'http://localhost:8000' }) === null && sandboxOrigin({ hostname: 'evil.test', port: '', origin: 'https://evil.test' }) === null);
229-ok('config: producción sin dominio todavía → nada', sandboxOrigin({ hostname: 'code.elffuss.com', port: '', origin: 'https://code.elffuss.com' }) === null);
240+ok('config: producción → x2.utopiaia.com, otro sitio que code.elffuss.com', sandboxOrigin({ hostname: 'code.elffuss.com', port: '', origin: 'https://code.elffuss.com' }) === 'https://x2.utopiaia.com'
241+ && !sameSite('https://x2.utopiaia.com', 'https://code.elffuss.com'));
242+// el mismo origen en los dos sitios que lo nombran: config.js (la página) y headers.json (cabeceras y nginx)
243+ok('config: headers.json nombra el mismo recinto de producción que config.js, para cada origen de Code',
244+ !!spec.environments.production.sandbox && spec.environments.production.code.every(o => { const u = new URL(o); return sandboxOrigin({ hostname: u.hostname, port: u.port, origin: u.origin }) === spec.environments.production.sandbox; }),
245+ JSON.stringify(spec.environments.production));
246+ok('config: el dominio viejo de Code (code.elffuss.utopiaia.com, mismo sitio que el recinto) no tiene recinto',
247+ sandboxOrigin({ hostname: 'code.elffuss.utopiaia.com', port: '', origin: 'https://code.elffuss.utopiaia.com' }) === null
248+ && sandboxOrigin({ hostname: 'code.elffuss.utopiaia.com', port: '', origin: 'https://code.elffuss.utopiaia.com' }, { 'code.elffuss.utopiaia.com': 'https://x2.utopiaia.com' }) === null);
230249 // el recinto tiene que ser OTRO SITIO: un subdominio del mismo dominio registrable (otro origen) no vale
231250 const prod = { hostname: 'code.elffuss.com', port: '', origin: 'https://code.elffuss.com' };
232251 ok('config: un recinto del mismo sitio que Code (x2.elffuss.com, también por http) se rechaza; otro dominio, no',
modified tests/x2_ux.mjs +8 −8
@@ -28,9 +28,9 @@
2828 // what will work and offer the code button
2929 // X3 also: "Install without its code" in the consent of a mixed extension,
3030 // and the dialogs' primary button at 4.5:1 or more
31-// X7 where level 2 cannot start (Code served as code.elffuss.com): the
32-// lines say so, the run button is inert with the reason, and the filter
33-// hides what only brings code
31+// X7 where level 2 cannot start (Code served on a host config.js gives no
32+// sandbox): the lines say so, the run button is inert with the reason,
33+// and the filter hides what only brings code
3434 // X8 keyboard: F6 and Code's palette reach a notification and come back,
3535 // focus never falls to the page, a notification without buttons waits
3636 // while hovered or focused, the quick pick and input box keep Tab inside
@@ -310,9 +310,9 @@
310310 }
311311
312312 // ── X7: donde el nivel 2 no puede arrancar: Code en un host sin recinto en
313-// config.js, como code.elffuss.com hoy (aquí «code.localhost», que el navegador
314-// trata como contexto seguro y resuelve a sí mismo; config.js da a los dos lo
315-// mismo: ningún recinto) ──
313+// config.js (aquí «code.localhost», que el navegador trata como contexto
314+// seguro y resuelve a sí mismo; code.elffuss.com sí tiene el suyo,
315+// x2.utopiaia.com) ──
316316 {
317317 const alias = 'code.localhost';
318318 const srv2 = await startServer({ codeAliases: [alias] });
@@ -326,8 +326,8 @@
326326 await p2.goto(origin2 + '/?test-opfs', { waitUntil: 'domcontentloaded' });
327327 await p2.waitForFunction(() => !!window.monaco?.editor?.getEditors?.().length, null, { timeout: 30000 });
328328 const rt = await p2.evaluate(async () => (await import('/js/ext2/vendor.js')).runtimeInfo());
329- const sameAsProd = await p2.evaluate(async () => { const c = await import('/js/ext2/config.js'); return c.sandboxOrigin({ hostname: 'code.elffuss.com', origin: 'https://code.elffuss.com', port: '' }) === null && c.sandboxOrigin(location) === null; });
330- ok('X7 premise: Code on a host with no sandbox (as code.elffuss.com today): level 2 is not available on this site', rt.available === false && rt.reason === 'site' && sameAsProd, JSON.stringify(rt));
329+ const premise = await p2.evaluate(async () => { const c = await import('/js/ext2/config.js'); return c.sandboxOrigin(location) === null && c.sandboxOrigin({ hostname: 'code.elffuss.com', origin: 'https://code.elffuss.com', port: '' }) === 'https://x2.utopiaia.com'; });
330+ ok('X7 premise: Code on a host config.js gives no sandbox (code.elffuss.com has x2.utopiaia.com): level 2 is not available on this site', rt.available === false && rt.reason === 'site' && premise, JSON.stringify(rt));
331331 await panel(p2);
332332 await search(p2, 'elffuss-ux');
333333 await until(async () => (await p2.locator('#ext-results .ext-row').count()) === fixtures.length);
modified web/js/ext2/config.js +6 −4
@@ -4,11 +4,13 @@
44 // recinto a otro sitio.
55 //
66 // El recinto tiene que ser OTRO SITIO (otro dominio registrable): así no
7-// comparte almacenamiento, cookies ni proceso con Code. En producción el
8-// dominio aún no existe (decisión del dueño): hasta entonces, el nivel 2 dice
9-// «no disponible en este sitio» y Code sigue exactamente igual.
7+// comparte almacenamiento, cookies ni proceso con Code. En producción vive en
8+// x2.utopiaia.com (utopiaia.com no es elffuss.com). El mismo origen está en
9+// sandbox/x2/headers.json, que da las cabeceras y el nginx del recinto, y
10+// deploy-sandbox.sh se niega si los dos no coinciden. Un host que no esté aquí
11+// no tiene recinto: el nivel 2 dice «no disponible en este sitio».
1012 const TABLA = {
11- 'code.elffuss.com': null,
13+ 'code.elffuss.com': 'https://x2.utopiaia.com',
1214 // desarrollo y pruebas: el mismo servidor sirve el recinto en «localhost»,
1315 // que es otro sitio que 127.0.0.1. Abrir Code en http://localhost no vale
1416 // (sería el mismo sitio que el recinto): se usa 127.0.0.1.