utopia-ia/elffuss-code public
Changesets · Branches · Tags · Compare
| Changeset | 00c23ea566f6be5f5f9c5a1b2b5f335691a7e1db3b5f78c3d458b7e45e2455ac |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-10-12 09:50 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-10-12 09:50 +02:00 |
| Parents | fb79c56b6281 |
11 files changed
modified README.md +20 −18
| @@ -55,10 +55,9 @@ | ||
| 55 | 55 | Color Theme picker), **TextMate grammars**, **snippets** and **language configurations** |
| 56 | 56 | (comments, brackets, indentation). You can also install a `.vsix` file. |
| 57 | 57 | |
| 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…). | |
| 62 | 61 | - **Your project stays in the browser.** Open VSX only sees what you search for and install. |
| 63 | 62 | - Packages are checked against the SHA-256 that Open VSX publishes and kept in IndexedDB. |
| 64 | 63 | - Grammars run on the same engine as VS Code (vscode-textmate + Oniguruma), loaded only |
| @@ -84,7 +83,7 @@ | ||
| 84 | 83 | count), *"Runs in Code's sandbox"* (with its commands, keybindings and settings), |
| 85 | 84 | *"Needs Node: not available in the browser"*, the parts that *won't appear here* (views, |
| 86 | 85 | 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 | |
| 88 | 87 | reason, the run button is inert, and the **Works in Code** chip keeps only what works |
| 89 | 88 | there. An extension that declares proposed VS Code APIs is marked: Code does not turn those |
| 90 | 89 | APIs on, so some of its parts may fail (the census shows many such extensions start). The |
| @@ -173,17 +172,20 @@ | ||
| 173 | 172 | debugger, source control, status bar), the network or the whole project, extensions that |
| 174 | 173 | replace typing (Vim, Emacs), `createQuickPick` and `createInputBox`, gutter icons, and |
| 175 | 174 | 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). | |
| 187 | 189 | |
| 188 | 190 | **What actually runs (runtime census, 2026-10-11).** Of the 500 most downloaded extensions |
| 189 | 191 | on Open VSX, 89 have a browser entry. `tests/x2_census.mjs` installed each one from its |
| @@ -249,8 +251,8 @@ | ||
| 249 | 251 | | Suite | What it proves | |
| 250 | 252 | |---|---| |
| 251 | 253 | | `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) | | |
| 254 | 256 | | `x2_smoke` | synthetic extensions end to end: commands, formatting, hovers, symbols, diagnostics, decorations, dialogs, the gates, the firewall, tampering, `?noext`/`?noext2`/kill switch | |
| 255 | 257 | | `x2_bytes` | the default path and the level 1 states against main before level 2 (above) | |
| 256 | 258 | | `x2_canary` | the canary and the drill (above), with positive controls | |
modified deploy-sandbox.sh +19 −12
| @@ -1,32 +1,39 @@ | ||
| 1 | 1 | #!/usr/bin/env bash |
| 2 | 2 | # 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) | |
| 9 | 9 | # |
| 10 | 10 | # 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> | |
| 13 | 11 | # ./deploy-sandbox.sh |
| 14 | 12 | # |
| 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 | +# | |
| 15 | 18 | # 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). | |
| 17 | 20 | set -euo pipefail |
| 18 | 21 | cd "$(dirname "$0")" |
| 19 | 22 | |
| 20 | 23 | HOST=${ELFFUSS_HOST:?define ELFFUSS_HOST (usuario@servidor) antes de desplegar} |
| 21 | 24 | 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://}} | |
| 24 | 31 | case "$DEST" in |
| 25 | 32 | (*elffuss-code*|*/web|*/web/|/) echo "X2_SANDBOX_DEST no puede ser la carpeta de Code: $DEST" >&2; exit 1;; |
| 26 | 33 | esac |
| 27 | 34 | |
| 28 | 35 | # 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 | |
| 30 | 37 | node sandbox/x2/headers.mjs --site-check "$ORIGIN" |
| 31 | 38 | |
| 32 | 39 | # 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 @@ | ||
| 6 | 6 | "code": [ |
| 7 | 7 | "https://code.elffuss.com" |
| 8 | 8 | ], |
| 9 | - "sandbox": null | |
| 9 | + "sandbox": "https://x2.utopiaia.com" | |
| 10 | 10 | }, |
| 11 | 11 | "dev": { |
| 12 | 12 | "code": [ |
modified sandbox/x2/headers.mjs +19 −10
| @@ -11,12 +11,15 @@ | ||
| 11 | 11 | // node sandbox/x2/headers.mjs --pin |
| 12 | 12 | // recompute sandbox.html's bootstrap hash and write it to headers.json |
| 13 | 13 | // 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) | |
| 20 | 23 | import fs from 'node:fs'; |
| 21 | 24 | import path from 'node:path'; |
| 22 | 25 | import crypto from 'node:crypto'; |
| @@ -149,17 +152,21 @@ | ||
| 149 | 152 | // registrable domain), or it would share cookies and a process with Code. |
| 150 | 153 | // web/js/ext2/config.js refuses a same-site sandbox at run time; this refuses |
| 151 | 154 | // it before anything is deployed. |
| 155 | +export const productionSandbox = () => loadSpec().environments.production.sandbox || null; | |
| 156 | + | |
| 152 | 157 | export async function siteProblems(sandbox) { |
| 153 | 158 | const { sameSite, sandboxOrigin } = await import('../../web/js/ext2/config.js'); |
| 154 | 159 | const problems = []; |
| 155 | 160 | let u; |
| 156 | 161 | try { u = new URL(sandbox); } catch { return ['not a URL: ' + sandbox]; } |
| 157 | 162 | 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}`); | |
| 158 | 165 | for (const code of loadSpec().environments.production.code) { |
| 159 | 166 | if (sameSite(code, u.origin)) problems.push(`${u.origin} is the same site as ${code}: use another registrable domain`); |
| 160 | 167 | const c = new URL(code); |
| 161 | 168 | 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}`); | |
| 163 | 170 | } |
| 164 | 171 | return problems; |
| 165 | 172 | } |
| @@ -167,16 +174,18 @@ | ||
| 167 | 174 | if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { |
| 168 | 175 | const args = process.argv.slice(2); |
| 169 | 176 | 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; }; | |
| 170 | 179 | if (args.includes('--site-check')) { |
| 171 | - const s = args[args.indexOf('--site-check') + 1] || ''; | |
| 180 | + const s = after('--site-check') || productionSandbox() || ''; | |
| 172 | 181 | const problems = await siteProblems(s); |
| 173 | 182 | for (const p of problems) console.error(' ✗ ' + p); |
| 174 | 183 | console.log(problems.length ? `${problems.length} problems` : `${s} is another site than Code`); |
| 175 | 184 | process.exit(problems.length ? 1 : 0); |
| 176 | 185 | } |
| 177 | 186 | 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); } | |
| 180 | 189 | const problems = await siteProblems(s); |
| 181 | 190 | if (problems.length) { for (const p of problems) console.error(' ✗ ' + p); process.exit(1); } |
| 182 | 191 | 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 | |
| 4 | 6 | # |
| 5 | -# node sandbox/x2/headers.mjs --nginx --sandbox https://x2.SANDBOX_DOMAIN | |
| 7 | +# node sandbox/x2/headers.mjs --nginx | |
| 6 | 8 | # |
| 7 | 9 | # and save them as /etc/nginx/snippets/x2-sandbox.conf and x2-exthost.conf. |
| 8 | 10 | # 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. | |
| 14 | 17 | |
| 15 | 18 | server { |
| 16 | 19 | 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; | |
| 21 | 24 | access_log off; # the sandbox keeps no log of who loaded it |
| 22 | 25 | autoindex off; |
| 23 | 26 | server_tokens off; |
| @@ -30,9 +33,8 @@ | ||
| 30 | 33 | } |
| 31 | 34 | |
| 32 | 35 | # the extension-host document: only the exact query the library builds |
| 33 | - # (escape the dots of the domain in the pattern: x2\.example\.org) | |
| 34 | 36 | 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; } | |
| 36 | 38 | include snippets/x2-exthost.conf; |
| 37 | 39 | try_files $uri =404; |
| 38 | 40 | } |
| @@ -43,7 +45,7 @@ | ||
| 43 | 45 | |
| 44 | 46 | server { |
| 45 | 47 | listen 80; |
| 46 | - server_name x2.SANDBOX_DOMAIN; | |
| 48 | + server_name x2.utopiaia.com; | |
| 47 | 49 | access_log off; |
| 48 | 50 | return 301 https://$host$request_uri; |
| 49 | 51 | } |
modified tests/lib/x2-server.mjs +1 −2
| @@ -47,8 +47,7 @@ | ||
| 47 | 47 | const envInsecure = () => { const v = process.env.X2_INSECURE; return v === 'all' ? 'all' : v === '1' || v === 'exthost' ? 'exthost' : false; }; |
| 48 | 48 | |
| 49 | 49 | // 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. | |
| 52 | 51 | export async function startServer({ port = 0, webRoot = path.join(REPO, 'web'), insecure = envInsecure(), tamper = process.env.X2_TAMPER === '1', quiet = true, codeAliases = [] } = {}) { |
| 53 | 52 | const requests = []; // { host, method, url } |
| 54 | 53 | let codeHost = null, sandboxHost = null, origins = null; |
modified tests/x2_deploy.mjs +23 −7
| @@ -14,11 +14,13 @@ | ||
| 14 | 14 | // server's whole folder is compared with the manifest |
| 15 | 15 | // D4 a stray file already on the server makes it fail (full listing, not |
| 16 | 16 | // 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 | |
| 18 | 19 | // 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 | |
| 20 | 22 | // 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) | |
| 22 | 24 | import fs from 'node:fs'; |
| 23 | 25 | import os from 'node:os'; |
| 24 | 26 | import path from 'node:path'; |
| @@ -131,27 +133,41 @@ | ||
| 131 | 133 | // D5 |
| 132 | 134 | r = run('deploy-sandbox.sh', { X2_SANDBOX_DEST: '/var/www/x2-sandbox', X2_SANDBOX_ORIGIN: 'https://x2.elffuss.com' }); |
| 133 | 135 | 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)); | |
| 134 | 140 | |
| 135 | 141 | // D6 |
| 136 | 142 | fs.writeFileSync(path.join(repo, 'sandbox/x2/v1/notes.txt'), 'not for the server\n'); |
| 137 | 143 | const sbx = path.join(server, 'x2-sandbox/x2/v1'); |
| 138 | 144 | fs.mkdirSync(sbx, { recursive: true }); |
| 139 | 145 | 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' }); | |
| 141 | 147 | 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 |
| 142 | 148 | && 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)); | |
| 143 | 155 | |
| 144 | 156 | // D7 |
| 145 | 157 | 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; |
| 146 | 158 | const today = live(); |
| 147 | 159 | const cfg = path.join(repo, 'web/js/ext2/config.js'); |
| 148 | 160 | 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); | |
| 151 | 166 | const man = path.join(repo, 'web/js/ext2/vendor-manifest.json'); |
| 152 | 167 | fs.writeFileSync(man, JSON.stringify({ ...manifest, enabled: false })); |
| 153 | 168 | 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 })); | |
| 155 | 171 | |
| 156 | 172 | fs.rmSync(T, { recursive: true, force: true }); |
| 157 | 173 | console.log(fails ? `\n❌ ${fails} failed` : '\n✅ all passed'); |
modified tests/x2_headers.mjs +11 −2
| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | // |
| 3 | 3 | // node tests/x2_headers.mjs |
| 4 | 4 | // 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) | |
| 7 | 8 | // |
| 8 | 9 | // Checks: |
| 9 | 10 | // H1 both sandbox documents, with their exact query shape: status 200, every |
| @@ -154,6 +155,14 @@ | ||
| 154 | 155 | const vendorBlock = /location \^~ \/vendor\/x2\/ \{[\s\S]*?\}/.exec(example)?.[0] || ''; |
| 155 | 156 | ok('H6 the template for Code’s vendor location adds Cache-Control only to successful responses (no always)', |
| 156 | 157 | /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)); | |
| 157 | 166 | } |
| 158 | 167 | |
| 159 | 168 | await srv?.close(); |
modified tests/x2_unit.mjs +20 −1
| @@ -210,6 +210,17 @@ | ||
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | 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)); | |
| 213 | 224 | 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))); |
| 214 | 225 | ok('frame-src del recinto: solo su documento', /frame-src http:\/\/localhost:1234\/x2\/v1\/exthost-iframe\.html(;|$)/.test(cspFor('sandbox.html', dev))); |
| 215 | 226 | ok('meta CSP sin frame-ancestors', !/frame-ancestors/.test(expectedMeta('sandbox.html'))); |
| @@ -226,7 +237,15 @@ | ||
| 226 | 237 | ok('manifiesto roto no pasa', !validManifest({ ...vm, files: vm.files.slice(1) }) && !validManifest({ ...vm, buildId: '../x' })); |
| 227 | 238 | 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'); |
| 228 | 239 | 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); | |
| 230 | 249 | // el recinto tiene que ser OTRO SITIO: un subdominio del mismo dominio registrable (otro origen) no vale |
| 231 | 250 | const prod = { hostname: 'code.elffuss.com', port: '', origin: 'https://code.elffuss.com' }; |
| 232 | 251 | 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 @@ | ||
| 28 | 28 | // what will work and offer the code button |
| 29 | 29 | // X3 also: "Install without its code" in the consent of a mixed extension, |
| 30 | 30 | // 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 | |
| 34 | 34 | // X8 keyboard: F6 and Code's palette reach a notification and come back, |
| 35 | 35 | // focus never falls to the page, a notification without buttons waits |
| 36 | 36 | // while hovered or focused, the quick pick and input box keep Tab inside |
| @@ -310,9 +310,9 @@ | ||
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | // ── 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) ── | |
| 316 | 316 | { |
| 317 | 317 | const alias = 'code.localhost'; |
| 318 | 318 | const srv2 = await startServer({ codeAliases: [alias] }); |
| @@ -326,8 +326,8 @@ | ||
| 326 | 326 | await p2.goto(origin2 + '/?test-opfs', { waitUntil: 'domcontentloaded' }); |
| 327 | 327 | await p2.waitForFunction(() => !!window.monaco?.editor?.getEditors?.().length, null, { timeout: 30000 }); |
| 328 | 328 | 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)); | |
| 331 | 331 | await panel(p2); |
| 332 | 332 | await search(p2, 'elffuss-ux'); |
| 333 | 333 | 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 @@ | ||
| 4 | 4 | // recinto a otro sitio. |
| 5 | 5 | // |
| 6 | 6 | // 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». | |
| 10 | 12 | const TABLA = { |
| 11 | - 'code.elffuss.com': null, | |
| 13 | + 'code.elffuss.com': 'https://x2.utopiaia.com', | |
| 12 | 14 | // desarrollo y pruebas: el mismo servidor sirve el recinto en «localhost», |
| 13 | 15 | // que es otro sitio que 127.0.0.1. Abrir Code en http://localhost no vale |
| 14 | 16 | // (sería el mismo sitio que el recinto): se usa 127.0.0.1. |