diff --git a/docs/lld/17-preview-pane.md b/docs/lld/17-preview-pane.md index ef02ec8a..196af689 100644 --- a/docs/lld/17-preview-pane.md +++ b/docs/lld/17-preview-pane.md @@ -339,3 +339,15 @@ An admin's REPL listens on the machine's real network, where the site itself is, A server that the Genie agent starts with its `bash` action does not survive that action (the shell and everything it started are killed when the call ends: its description says to use `terminal_type` for a program that must keep running). The Preview of such a program says "Nothing is listening" or "Your program has stopped" because it is gone. **The registry names a home by its directory name (2026-11-23).** `SessionRegistry` keeps the home as `donadjdc` (`Config.HomeOf`), while the Preview's token and the route table carry the path `/home/openrepl/donadjdc`. The first version of `homeBackend` asked the registry for the path only, so it never found the session and fell back to the stale route: the Preview still went to the worker after the session moved back to the gateway (reproduced on a local gateway and worker: the worker answered `no process of donadjdc was found`). It now asks for the path and for its base name. The test uses the registry's real naming and fails without the fix. + +## The preview host (2026-11-23) + +`SiteSettings.PreviewBaseURL` (Site settings > Workspaces > Preview, "Preview base URL"; a host name such as `preview.openrepl.com` (kept as typed and sent to the page as typed; a host name alone takes the scheme and the port of the site the page was opened from, in `previewBase()`; the server derives a scheme only to compare host names) with no path, checked by `cleanPreviewBaseURL`, read as an origin by `previewBaseURL()`, and refused when its host name equals the one of `OPENREPL_PUBLIC_URL` (host names are compared, never scheme or port, so a local test uses `preview.localhost:`); empty by default) moves the frames of the Preview to an origin of their own: `https://preview.openrepl.com//f/index.html` and `https://preview.openrepl.com//p//...` instead of `https://openrepl.com/preview//...`. Empty keeps every address as it was. + +- **A thin layer over the routes that exist** (`server/previewhost.go`, `Server.wrapPreviewHost`, the outermost handler of the site, of the gateway and of a worker): on a request whose Host is the preview host the path is turned into the site's own form (`/preview//...`) and the request is marked (`gateway.MarkPreviewHost`). The token, the storage (`/s`), the libraries (`/preview/lib/...`), the programs (`/p/`) and the routing to the worker that runs the workspace are the ones of the site. Nothing of the site is reachable on that host: whatever the path, it ends below `/preview/` (a path that is no token is "the preview ended", 410), and the root is 404. `/preview//...` is accepted on the host too; the site's own `/preview//...` is unchanged (old links, a worker's own port). +- **The form follows the request,** not a global flag (the same server answers both): `previewPath` makes the prefix a program's links are rewritten to and the storage URL (`//p/`, `//s` on the host), `publicPath` the redirect that adds the trailing slash. +- **Gateway and workers:** the gateway forwards the request in the site's form with a trusted header (`X-Openrepl-Preview-Host: 1`, `trusted.HeaderPreviewHost`, set in `RemoteBackend.direct`, stripped from every client request); a worker believes it only on a request that came over the tunnel (`onPreviewHost`). The value of the setting reaches the workers in `WorkerConfig.PreviewBaseURL` like the other site rules. +- **The page** (`js/src/page/27-preview.js`): the history of a tab keeps the site's form; `pub()` makes the address a frame opens (`frame.src`), `popUrl()` the one of "open in a tab" and "copy address", `pathOf()` brings an address the frame reports back to the site's form. `window.site_settings.previewBaseURL` comes from `settings.js` (`SiteSettings.public()`). +- **To use it:** point the host's DNS at the OpenREPL server, give it a certificate, and keep the Host header on the way (a proxy such as Cloudflare must pass it). The frames are sandboxed without cookies and without the site's origin, so the host adds isolation and takes nothing from the site's cookies. +- **Tests:** `server/previewhost_test.go` (host compare, the layer, both forms, the file route on both hosts), `server/preview_base_url_test.go`, `server/worker_config_test.go`, `gateway/previewhost_test.go`, `js/test/preview-host.test.mjs`. Not run: a browser test of the pane on a real second host. +- **Not covered:** a Genie agent step that builds a Preview address itself (none was found in the code); the site's own CSP, if one is set in front (Cloudflare), must allow the preview origin in a frame. diff --git a/src/gateway/previewhost.go b/src/gateway/previewhost.go new file mode 100644 index 00000000..13726001 --- /dev/null +++ b/src/gateway/previewhost.go @@ -0,0 +1,22 @@ +package gateway + +import ( + "context" + "net/http" +) + +// A Preview request that arrived on the preview host (SiteSettings.PreviewBaseURL: //... there). The server rewrites its path to the site's own form +// (/preview//...) before it routes it; this mark says it came by the host, so that the addresses a program's pages are rewritten to, and a +// worker (which gets the mark as a trusted header), stay in the host's form. +type previewHostKey struct{} + +// MarkPreviewHost marks r as a request of the preview host. +func MarkPreviewHost(r *http.Request) *http.Request { + return r.WithContext(context.WithValue(r.Context(), previewHostKey{}, true)) +} + +// IsPreviewHost says whether r arrived on the preview host. +func IsPreviewHost(r *http.Request) bool { + v, _ := r.Context().Value(previewHostKey{}).(bool) + return v +} diff --git a/src/gateway/previewhost_test.go b/src/gateway/previewhost_test.go new file mode 100644 index 00000000..9a45cbf5 --- /dev/null +++ b/src/gateway/previewhost_test.go @@ -0,0 +1,27 @@ +package gateway + +import ( + "net/http/httptest" + "testing" + + "trusted" +) + +// A worker gets the mark of the preview host only from the gateway: the header a client sent is dropped, the mark of the request is forwarded +func TestTheMarkOfThePreviewHostReachesAWorkerAndAClientsCopyDoesNot(t *testing.T) { + b := &RemoteBackend{cfg: RemoteConfig{ID: "w1"}} + forged := httptest.NewRequest("GET", "/preview/T/f/x", nil) + forged.Header.Set(trusted.HeaderPreviewHost, "1") + b.direct(forged) + if forged.Header.Get(trusted.HeaderPreviewHost) != "" { + t.Error("a client's copy of the header reached the worker") + } + marked := MarkPreviewHost(httptest.NewRequest("GET", "/preview/T/f/x", nil)) + b.direct(marked) + if marked.Header.Get(trusted.HeaderPreviewHost) != "1" { + t.Error("the mark did not reach the worker") + } + if IsPreviewHost(httptest.NewRequest("GET", "/", nil)) { + t.Error("an unmarked request is not of the preview host") + } +} diff --git a/src/gateway/remote.go b/src/gateway/remote.go index 1f7a11f1..329f4d71 100644 --- a/src/gateway/remote.go +++ b/src/gateway/remote.go @@ -126,6 +126,9 @@ func (b *RemoteBackend) direct(req *http.Request) { if id, ok := req.Context().Value(identityKey{}).(trusted.Identity); ok { trusted.Set(req.Header, id) } + if IsPreviewHost(req) { + req.Header.Set(trusted.HeaderPreviewHost, "1") + } if _, ok := req.Header["User-Agent"]; !ok { req.Header.Set("User-Agent", "") // do not add Go's default } diff --git a/src/js/src/page/27-preview.js b/src/js/src/page/27-preview.js index 1123e32a..3acde65d 100644 --- a/src/js/src/page/27-preview.js +++ b/src/js/src/page/27-preview.js @@ -239,7 +239,27 @@ function describe(p) { if (m) return "127.0.0.1:" + m[1] + (m[2] && m[2] !== "/" ? m[2] : ""); return p; } -function pathOf(href) { try { var u = new URL(href, location.href); return u.pathname + u.search + u.hash; } catch (e) { return href; } } +// The preview host (docs/lld/17-preview-pane.md "The preview host"): when the admin set SiteSettings.PreviewBaseURL the frames and the tabs of the +// Preview open there, as //f/, not as this site's /preview//f/. The history of a tab keeps the site's form, so +// that nothing else here has to know: pub() makes the address a frame or a tab opens, and pathOf() brings a reported address back. +function previewBase() { + var b = window.site_settings && window.site_settings.previewBaseURL; + if (typeof b !== "string") return ""; + b = b.trim().replace(/\/+$/, ""); + if (!b) return ""; + // as typed: a host name alone takes the scheme and the port of the page (preview.localhost on http://localhost:8080 is http://preview.localhost:8080) + if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(b)) b = location.protocol + "//" + b + (location.port && !/(:\d+|\])$/.test(b) ? ":" + location.port : ""); + return b; +} +function pub(p) { var b = previewBase(); return b ? b + p.replace(/^\/preview\//, "/") : p; } +function popUrl(p) { var b = previewBase(); return b ? pub(p) : location.origin + p; } +function pathOf(href) { + try { + var u = new URL(href, location.href), b = previewBase(), path = u.pathname; + if (b && u.hostname === new URL(b).hostname && !/^\/preview\//.test(path)) path = "/preview" + path; + return path + u.search + u.hash; + } catch (e) { return href; } +} function renew(p) { return token ? p.replace(/^\/preview\/[^/]+\//, "/preview/" + token.value + "/") : p; } // ---- tabs, history, the status line --------------------------------------------------------------------------------- @@ -302,7 +322,7 @@ function selectTab(k) { var frame = frameFor(target); frame.setAttribute("data-url", ""); if (target.kind === "n") { load(); hideError(); render(); focusAddress(); return; } - if (tb.hist.length) { navTo = renew(tb.hist[tb.idx]); frame.setAttribute("data-url", navTo); setStatus("loading"); frame.src = navTo; } else load(); + if (tb.hist.length) { navTo = renew(tb.hist[tb.idx]); frame.setAttribute("data-url", navTo); setStatus("loading"); frame.src = pub(navTo); } else load(); hideError(); render(); } @@ -312,7 +332,7 @@ function closeTab(k) { var was = k === cur; cur = Math.min(cur > k ? cur - 1 : cur, tabs.length - 1); target = tabs[cur].t; - if (was) { var tb = tabs[cur]; if (tb.hist.length) { navTo = renew(tb.hist[tb.idx]); var f = frameFor(target); f.setAttribute("data-url", navTo); f.src = navTo; } else load(); } + if (was) { var tb = tabs[cur]; if (tb.hist.length) { navTo = renew(tb.hist[tb.idx]); var f = frameFor(target); f.setAttribute("data-url", navTo); f.src = pub(navTo); } else load(); } render(); } @@ -648,8 +668,8 @@ function navigateTo(t) { tb.hist = tb.hist.slice(0, tb.idx + 1); tb.hist.push(url); tb.idx = tb.hist.length - 1; navTo = url; frame.setAttribute("data-url", url); - frame.src = url; - if (popout && !popout.closed) { try { popout.location.href = location.origin + url; } catch (e) {} } + frame.src = pub(url); + if (popout && !popout.closed) { try { popout.location.href = popUrl(url); } catch (e) {} } render(); }, function (e) { message("The preview is not available.
" + esc(e && e.message ? e.message : e), null); @@ -739,7 +759,7 @@ function goHist(tb) { navTo = renew(tb.hist[tb.idx]); frame.setAttribute("data-url", navTo); setStatus("loading"); hideError(); clearLogs(); - frame.src = navTo; + frame.src = pub(navTo); setAddress(describe(navTo)); render(); } @@ -759,7 +779,7 @@ function toggleMenu(force) { function copyAddress() { var tb = tab(); - var url = tb && tb.hist.length ? location.origin + renew(tb.hist[tb.idx]) : ""; + var url = tb && tb.hist.length ? popUrl(renew(tb.hist[tb.idx])) : ""; var done = function () { if (window.notify) window.notify("Address copied.", { type: "success" }); }; if (!url) return; if (navigator.clipboard && navigator.clipboard.writeText) navigator.clipboard.writeText(url).then(done, function () {}); @@ -769,7 +789,7 @@ function popOut() { if (!target || target.kind === "n") return; getToken().then(function (tok) { var tb = tab(); - var url = location.origin + (tb && tb.hist.length ? renew(tb.hist[tb.idx]) : urlFor(target, tok)); + var url = popUrl(tb && tb.hist.length ? renew(tb.hist[tb.idx]) : urlFor(target, tok)); popout = window.open(url, "openrepl-preview", "popup=yes,width=1000,height=720"); if (!popout) { message("The window was blocked.
Allow pop-ups for this site, then try again.", null); return; } var frame = frameFor(target); frame.removeAttribute("src"); @@ -821,8 +841,8 @@ function load() { var url = urlFor(target, tok); navTo = ""; frame.setAttribute("data-url", url); - frame.src = url; - if (popout && !popout.closed) { try { popout.location.href = location.origin + url; } catch (e) {} } + frame.src = pub(url); + if (popout && !popout.closed) { try { popout.location.href = popUrl(url); } catch (e) {} } }, function (e) { message("The preview is not available.
" + esc(e && e.message ? e.message : e), null); }); @@ -855,8 +875,8 @@ function reload() { var tb = tab(); if (tb && tb.hist.length) { url = renew(tb.hist[tb.idx]); navTo = url; frame.setAttribute("data-url", url); } // the page now shown, not the first one setStatus("loading"); hideError(); clearLogs(); - if (popout && !popout.closed) { try { popout.location.href = location.origin + url; } catch (e) {} } - frame.src = url; // the same address again reloads the page + if (popout && !popout.closed) { try { popout.location.href = popUrl(url); } catch (e) {} } + frame.src = pub(url); // the same address again reloads the page } function syncButton() { @@ -925,7 +945,7 @@ function show(t) { placePane(); setAddress(); applySize(); - if (target) { var tb = tab(); if (tb && tb.hist.length && !t.sub) { var f = frameFor(target); navTo = renew(tb.hist[tb.idx]); f.setAttribute("data-url", navTo); setStatus("loading"); f.src = navTo; setAddress(describe(navTo)); } else load(); } + if (target) { var tb = tab(); if (tb && tb.hist.length && !t.sub) { var f = frameFor(target); navTo = renew(tb.hist[tb.idx]); f.setAttribute("data-url", navTo); setStatus("loading"); f.src = pub(navTo); setAddress(describe(navTo)); } else load(); } else { message("Nothing to show yet.
Run a program that listens on a port, or open an .html or Markdown file, a picture or a PDF.", null); setStatus("message"); } render(); mobileTab(true); @@ -993,7 +1013,7 @@ function init() { el("preview-close").addEventListener("click", closePane); el("preview-newtab").addEventListener("click", function () { if (!target || target.kind === "n") return; - getToken().then(function (tok) { window.open(urlFor(target, tok), "_blank", "noopener"); }); + getToken().then(function (tok) { window.open(popUrl(urlFor(target, tok)), "_blank", "noopener"); }); }); window.addEventListener("resize", function () { if (open) applySize(); }); var mt = el("mobile-view-terminal"); diff --git a/src/js/test/preview-host.test.mjs b/src/js/test/preview-host.test.mjs new file mode 100644 index 00000000..57128f06 --- /dev/null +++ b/src/js/test/preview-host.test.mjs @@ -0,0 +1,68 @@ +// The addresses of the Preview with a preview host (js/src/page/27-preview.js, docs/lld/17-preview-pane.md "The preview host"): the history of a tab keeps +// the site's form (/preview//...), pub() makes the address a frame or a tab opens, and pathOf() brings an address the frame reports back. +// The four small functions are taken out of the page script and run with a pretend page. +import test from "node:test"; +import assert from "node:assert/strict"; +import fs from "node:fs"; +import vm from "node:vm"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +const here = path.dirname(fileURLToPath(import.meta.url)); +const source = fs.readFileSync(path.join(here, "..", "src", "page", "27-preview.js"), "utf8"); + +function fn(name) { + const start = source.indexOf("function " + name + "("); + assert.ok(start >= 0, name + " is not in the page script"); + let depth = 0, i = source.indexOf("{", start); + for (let j = i; j < source.length; j++) { + if (source[j] === "{") depth++; + if (source[j] === "}" && --depth === 0) return source.slice(start, j + 1); + } + throw new Error("no end of " + name); +} + +function page(base, loc = { protocol: "https:", host: "openrepl.test", port: "" }) { + const ctx = { window: { site_settings: base === undefined ? {} : { previewBaseURL: base } }, location: { origin: loc.protocol + "//" + loc.host, href: loc.protocol + "//" + loc.host + "/", protocol: loc.protocol, port: loc.port }, URL }; + vm.createContext(ctx); + vm.runInContext(["previewBase", "pub", "popUrl", "pathOf"].map(fn).join("\n"), ctx); + return ctx; +} + +test("without a preview host the addresses are the site's own, as before", () => { + for (const base of [undefined, "", null]) { + const p = page(base); + assert.equal(p.pub("/preview/T/f/index.html"), "/preview/T/f/index.html"); + assert.equal(p.popUrl("/preview/T/p/8000/"), "https://openrepl.test/preview/T/p/8000/"); + assert.equal(p.pathOf("https://openrepl.test/preview/T/f/a.html?x=1#h"), "/preview/T/f/a.html?x=1#h"); + } +}); + +test("with a preview host a frame opens //..., without /preview", () => { + const p = page("https://preview.example.test"); + assert.equal(p.pub("/preview/T/f/index.html"), "https://preview.example.test/T/f/index.html"); + assert.equal(p.pub("/preview/T/p/8000/x?y=1"), "https://preview.example.test/T/p/8000/x?y=1"); + assert.equal(p.popUrl("/preview/T/f/index.html"), "https://preview.example.test/T/f/index.html"); + // a trailing slash of the setting is no double slash + assert.equal(page("https://preview.example.test/").pub("/preview/T/f/a.html"), "https://preview.example.test/T/f/a.html"); +}); + +test("an address the frame reports on the preview host is brought back to the site's form, the history keeps one form", () => { + const p = page("https://preview.example.test"); + assert.equal(p.pathOf("https://preview.example.test/T/f/a.html?render=md#top"), "/preview/T/f/a.html?render=md#top"); + assert.equal(p.pathOf("https://preview.example.test/T/p/8000/"), "/preview/T/p/8000/"); + // already in the site's form (the host accepts it too), or from the site itself + assert.equal(p.pathOf("https://preview.example.test/preview/T/f/a.html"), "/preview/T/f/a.html"); + assert.equal(p.pathOf("https://openrepl.test/preview/T/f/a.html"), "/preview/T/f/a.html"); + assert.equal(p.pathOf("/preview/T/f/b.html"), "/preview/T/f/b.html"); + // the host name is compared, not the scheme or the port + assert.equal(p.pathOf("http://preview.example.test:8080/T/f/a.html"), "/preview/T/f/a.html"); +}); + +test("a host name alone takes the scheme and the port of the page; one with a scheme is used as typed", () => { + const local = { protocol: "http:", host: "localhost:8080", port: "8080" }; + assert.equal(page("preview.localhost", local).pub("/preview/T/f/index.html"), "http://preview.localhost:8080/T/f/index.html"); + assert.equal(page("preview.localhost:9000", local).pub("/preview/T/f/index.html"), "http://preview.localhost:9000/T/f/index.html"); + assert.equal(page("https://preview.example.test", local).pub("/preview/T/f/a.html"), "https://preview.example.test/T/f/a.html"); + assert.equal(page("preview.example.test").pub("/preview/T/f/a.html"), "https://preview.example.test/T/f/a.html"); +}); diff --git a/src/resources/js/admin-site.js b/src/resources/js/admin-site.js index 5ca4b63c..efce5d14 100644 --- a/src/resources/js/admin-site.js +++ b/src/resources/js/admin-site.js @@ -85,6 +85,7 @@ snapshotIntervalMinutes: int(form.snapEvery.value), previewLinkGuestMinutes: int(form.previewLifeGuest.value), previewLinkUserMinutes: int(form.previewLifeUser.value), + previewBaseURL: form.previewBaseURL.value.trim(), shareLinkGuestMinutes: int(form.shareLifeGuest.value), shareLinkUserMinutes: int(form.shareLifeUser.value), sessionCleanupHours: int(form.sessionCleanup.value), @@ -179,6 +180,7 @@ snapshotIntervalMinutes: s.snapshotIntervalMinutes || 0, previewLinkGuestMinutes: s.previewLinkGuestMinutes || 0, previewLinkUserMinutes: s.previewLinkUserMinutes || 0, + previewBaseURL: s.previewBaseURL || '', shareLinkGuestMinutes: s.shareLinkGuestMinutes || 0, shareLinkUserMinutes: s.shareLinkUserMinutes || 0, sessionCleanupHours: s.sessionCleanupHours || 0, @@ -537,6 +539,8 @@ form.previewLifeUser = h('input', { type: 'number', class: 'field', id: 'f-preview-life-user', min: '10', max: '1440', step: '1', placeholder: '180', 'aria-label': 'Minutes a preview link works for signed-in users', oninput: update }); form.previewLifeUser.value = settings.previewLinkUserMinutes || ''; form.previewLifeUser.style.maxWidth = '9rem'; + form.previewBaseURL = h('input', { type: 'text', class: 'field', id: 'f-preview-base-url', placeholder: 'preview.openrepl.com', 'aria-label': 'Preview base URL', oninput: update }); + form.previewBaseURL.value = settings.previewBaseURL || ''; form.shareLifeGuest = h('input', { type: 'number', class: 'field', id: 'f-share-life-guest', min: '10', max: '10080', step: '1', placeholder: '60', 'aria-label': 'Most minutes a share link works for guests', oninput: update }); form.shareLifeGuest.value = settings.shareLinkGuestMinutes || ''; form.shareLifeGuest.style.maxWidth = '9rem'; @@ -1226,6 +1230,7 @@ row('Genie may act in the Preview', 'Genie\'s agent can click, type, press keys, scroll, choose, go to other pages, run an expression and change the storage of the page the Preview shows. Off: it can still read the page, its console and its calls. It asks the user first in any case.', previewAgent.node), row('Minutes a preview link works for guests', 'From 10 to 1440 (a day). Leave it empty for 60 (1 hour). A pane gets a new link by itself before the old one ends; a link opened in a tab of its own, or copied, stops at its end. A change applies to links made after it.', form.previewLifeGuest), row('Minutes a preview link works for signed-in users', 'From 10 to 1440. Leave it empty for 180 (3 hours).', form.previewLifeUser), + row('Preview base URL', 'Optional. The host the preview frames open on, for example preview.openrepl.com (a host name alone takes the scheme and the port of the site the page is opened from, for example http://preview.localhost:8080 when the site is http://localhost:8080). It must not have the same host name as this site. No path. Frames then open as /<token>/…; leave it empty to keep this site\'s /preview/<token>/… addresses. Point that host at this OpenREPL server and keep its Host header.', form.previewBaseURL), row('Longest a share link works for guests (minutes)', 'From 10 to 10080 (7 days). Leave it empty for 60 (1 hour). The owner chooses the time in the Share popover and may add time up to this: guests 30 minutes or 1 hour; signed-in users also 4 hours, 24 hours and 7 days, as far as this allows.', form.shareLifeGuest), row('Longest a share link works for signed-in users (minutes)', 'From 10 to 10080 (7 days, as long as a sign-in lasts). Leave it empty for 10080.', form.shareLifeUser), row('Longest a code link works (days)', 'From 1 to 365. Leave it empty for 30 (a month). It is the latest day the calendar offers when someone makes a code link (Share, Share code), and the day it starts on when that is shorter than a month. The server removes ended links every week. A change applies to links made after it.', form.snippetMax), diff --git a/src/server/node_languages.go b/src/server/node_languages.go index d5c53dc5..bfcbb895 100644 --- a/src/server/node_languages.go +++ b/src/server/node_languages.go @@ -292,6 +292,7 @@ func (server *Server) workerConfigWith(disabled []string) *tunnel.WorkerConfig { MaintenanceMessage: s.Maintenance.Message, DisabledLanguages: append([]string(nil), disabled...), Egress: s.EgressOn, + PreviewBaseURL: s.PreviewBaseURL, } data, _ := json.Marshal(cfg) h := fnv.New64a() diff --git a/src/server/preview.go b/src/server/preview.go index 5eddb8b9..21e0116a 100644 --- a/src/server/preview.go +++ b/src/server/preview.go @@ -139,7 +139,7 @@ func (server *Server) handlePreview(rw http.ResponseWriter, req *http.Request) { http.Error(rw, why, http.StatusForbidden) return } - st := &livepreview.StorageInfo{Store: previewStore, Home: home, Viewer: viewer, URL: "/preview/" + token + "/s"} + st := &livepreview.StorageInfo{Store: previewStore, Home: home, Viewer: viewer, URL: previewPath(req, token) + "/s"} if svc := storeService(); svc != nil && !GetSiteSettings().StoreOff { st.Tools = svc.PreviewHead(filepath.Base(home), path[:i]) // the tools of the preview this visitor has on (Eruda, vConsole): scripts of this site } @@ -210,14 +210,14 @@ func (server *Server) previewProgram(rw http.ResponseWriter, req *http.Request, } if len(seg) == 1 { // the program's pages use relative links: the address ends in a slash - target := req.URL.Path + "/" + target := publicPath(req, req.URL.Path) + "/" if req.URL.RawQuery != "" { target += "?" + req.URL.RawQuery } http.Redirect(rw, req, target, http.StatusMovedPermanently) return } - prefix := "/preview/" + token + "/p/" + seg[0] + prefix := previewPath(req, token) + "/p/" + seg[0] livepreview.Proxy(rw, req, seg[1], livepreview.Options{ Home: home, Port: port, Prefix: prefix, Dial: previewDialer(home), Jar: previewJar, Viewer: viewer, Hook: livepreview.HTMLHookWith(prefix, st, livepreview.ProgramScope(port)), }) diff --git a/src/server/preview_base_url_test.go b/src/server/preview_base_url_test.go new file mode 100644 index 00000000..f89e6a69 --- /dev/null +++ b/src/server/preview_base_url_test.go @@ -0,0 +1,54 @@ +package server + +import "testing" + +func TestThePreviewBaseURLIsKeptAsTypedAndTheOriginIsDerived(t *testing.T) { + // the setting keeps what the admin typed (trimmed, lower case); the origin adds the scheme: http for a local host, else https + for in, want := range map[string][2]string{ + "": {"", ""}, " ": {"", ""}, + "preview.example.com": {"preview.example.com", "https://preview.example.com"}, + "Preview.Example.com/": {"preview.example.com", "https://preview.example.com"}, + "localhost:9000": {"localhost:9000", "http://localhost:9000"}, + "preview.localhost:8080": {"preview.localhost:8080", "http://preview.localhost:8080"}, + "https://preview.example.test": {"https://preview.example.test", "https://preview.example.test"}, + "http://preview.example.test/": {"http://preview.example.test", "http://preview.example.test"}, + "http://localhost:9000": {"http://localhost:9000", "http://localhost:9000"}, + } { + got, err := cleanPreviewBaseURL(in) + if err != nil || got != want[0] { + t.Errorf("%q: kept as %q %v, want %q", in, got, err, want[0]) + } + if o := (SiteSettings{PreviewBaseURL: in}).previewBaseURL(); o != want[1] { + t.Errorf("%q: origin %q, want %q", in, o, want[1]) + } + } + for _, bad := range []string{"preview.example.test/path", "ftp://x.test", "https://x.test/path", "https://x.test/?q=1", "https://u:p@x.test", "https://x.test/#f", "//x.test"} { + if got, err := cleanPreviewBaseURL(bad); err == nil { + t.Errorf("%q must be refused, got %q", bad, got) + } + } + if _, err := (SiteSettings{PreviewBaseURL: "https://x.test/path"}).normalize(); err == nil { + t.Error("settings with a path in the preview base URL must not normalize") + } + // the host name must differ from the site's own (OPENREPL_PUBLIC_URL), whatever the scheme, port or spelling of either + for _, site := range []string{"openrepl.com", "http://openrepl.com", "https://openrepl.com", "https://OpenREPL.com:8443"} { + t.Setenv("OPENREPL_PUBLIC_URL", site) + for _, base := range []string{"openrepl.com", "http://openrepl.com", "https://openrepl.com:9000"} { + if _, err := (SiteSettings{PreviewBaseURL: base}).normalize(); err == nil { + t.Errorf("%q against the site %q must be refused", base, site) + } + } + if _, err := (SiteSettings{PreviewBaseURL: "preview.openrepl.com"}).normalize(); err != nil { + t.Errorf("a separate host name against %q: %v", site, err) + } + } + t.Setenv("OPENREPL_PUBLIC_URL", "") + // it reaches the page (settings.js) and the workers, and a change is told in the log of changes + s := SiteSettings{PreviewBaseURL: "https://preview.example.test"} + if s.public().PreviewBaseURL != "https://preview.example.test" { + t.Error("the page does not get it") + } + if ch := settingsChanges(SiteSettings{}, s); len(ch) == 0 { + t.Error("the change is not told") + } +} diff --git a/src/server/previewhost.go b/src/server/previewhost.go new file mode 100644 index 00000000..5e19166a --- /dev/null +++ b/src/server/previewhost.go @@ -0,0 +1,81 @@ +package server + +import ( + "net/http" + "net/url" + "strings" + + "gateway" + "trusted" +) + +// The preview host (SiteSettings.PreviewBaseURL, for example https://preview.openrepl.com): the frames of the Preview can be served from an origin of +// their own, with the addresses //f/ and //p//... instead of /preview//... on the site. +// +// It is a thin layer in front of the routes that exist: on that host every path is turned into the site's own form (/preview//...) and marked +// (gateway.MarkPreviewHost), then served by the same handlers, so the token, the storage, the libraries, the programs and the routing to the worker that +// runs the workspace are the ones of the site. Only the preview is reachable on that host: whatever the path, it ends up below /preview/ (a path that +// is no token ends as "the preview ended" or 404), never at the site's pages, the admin or the terminals. The site's own /preview//... stays as +// it was (old links, a worker's own port), and /preview//... is accepted on the host as well. + +// sameHost says whether the Host header of a request names the host of base: the host names are compared, not the scheme or the port. +func sameHost(hostHeader, base string) bool { + u, err := url.Parse(base) + if err != nil || u.Hostname() == "" { + return false + } + h, err := url.Parse("//" + hostHeader) + return err == nil && strings.EqualFold(h.Hostname(), u.Hostname()) +} + +// wrapPreviewHost is the outermost layer of the site (and of a worker): see above. prefix is the path the site is mounted at ("/"). +func (server *Server) wrapPreviewHost(next http.Handler, prefix string) http.Handler { + if prefix == "" { + prefix = "/" + } + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + base := GetSiteSettings().previewBaseURL() + if base == "" || !sameHost(r.Host, base) { + next.ServeHTTP(w, r) + return + } + p := r.URL.Path + if !strings.HasPrefix(p, prefix+"preview/") { + if p == "/" || p == "" { + http.NotFound(w, r) + return + } + r2 := *r + u := *r.URL + u.Path = strings.TrimSuffix(prefix, "/") + "/preview/" + strings.TrimPrefix(p, "/") + u.RawPath = "" + r2.URL = &u + r = &r2 + } + next.ServeHTTP(w, gateway.MarkPreviewHost(r)) + }) +} + +// onPreviewHost says whether a request arrived on the preview host: here (the mark of wrapPreviewHost), or at the gateway (the trusted header a +// worker believes only on a request that came over the tunnel). +func onPreviewHost(r *http.Request) bool { + return gateway.IsPreviewHost(r) || (isTrusted(r) && r.Header.Get(trusted.HeaderPreviewHost) == "1") +} + +// previewPath is the address of a preview below its token as the request names it: /preview/ on the site, / on the preview host. +func previewPath(r *http.Request, token string) string { + if onPreviewHost(r) { + return "/" + token + } + return "/preview/" + token +} + +// publicPath is the path of a request in the form its visitor used: the internal /preview//... turned back to //... on the preview host. +func publicPath(r *http.Request, p string) string { + if onPreviewHost(r) { + if i := strings.Index(p, "/preview/"); i >= 0 { + return p[:i] + "/" + p[i+len("/preview/"):] + } + } + return p +} diff --git a/src/server/previewhost_test.go b/src/server/previewhost_test.go new file mode 100644 index 00000000..2f2a8a54 --- /dev/null +++ b/src/server/previewhost_test.go @@ -0,0 +1,145 @@ +package server + +import ( + "net/http" + "net/http/httptest" + "os" + "path/filepath" + "strings" + "testing" + "time" + + "gateway" + "livepreview" + "trusted" + "utils" +) + +func TestSameHostComparesTheHostNameOnly(t *testing.T) { + for _, c := range []struct { + host, base string + want bool + }{ + {"preview.example.test", "https://preview.example.test", true}, + {"PREVIEW.example.test:443", "https://preview.example.test", true}, + {"preview.example.test", "https://openrepl.com", false}, + {"localhost:9000", "http://localhost:9000", true}, + {"localhost:8000", "http://localhost:9000", true}, // the port is not compared + {"[::1]:8000", "http://[::1]:9000", true}, + {"preview.localhost:8000", "http://localhost:9000", false}, + {"preview.example.test", "", false}, + } { + if got := sameHost(c.host, c.base); got != c.want { + t.Errorf("%q against %q: %v", c.host, c.base, got) + } + } +} + +// the preview host: every path of that host ends below /preview/, marked; the site's own host is left alone +func TestThePreviewHostIsAThinLayerOverThePreviewRoutes(t *testing.T) { + withSecret(t) + old := GetSiteSettings() + defer SaveSiteSettings(old) + if err := SaveSiteSettings(SiteSettings{PreviewBaseURL: "https://preview.example.test"}); err != nil { + t.Fatal(err) + } + var seen string + var marked bool + h := (&Server{}).wrapPreviewHost(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + seen, marked = r.URL.Path, gateway.IsPreviewHost(r) + w.WriteHeader(204) + }), "/") + do := func(host, path string) int { + r := httptest.NewRequest("GET", "http://"+host+path, nil) + rec := httptest.NewRecorder() + seen, marked = "", false + h.ServeHTTP(rec, r) + return rec.Code + } + if c := do("preview.example.test", "/TOKEN/f/index.html"); c != 204 || seen != "/preview/TOKEN/f/index.html" || !marked { + t.Errorf("a file on the host: %d %q %v", c, seen, marked) + } + if c := do("preview.example.test", "/TOKEN/p/8000/x"); seen != "/preview/TOKEN/p/8000/x" || !marked || c != 204 { + t.Errorf("a program on the host: %q %v", seen, marked) + } + if do("preview.example.test", "/preview/TOKEN/f/a.html"); seen != "/preview/TOKEN/f/a.html" || !marked { + t.Errorf("the site's form is accepted on the host: %q %v", seen, marked) + } + // nothing of the site is reachable there: /admin becomes /preview/admin (a token that is none), the root is 404 + if do("preview.example.test", "/admin"); seen != "/preview/admin" || !marked { + t.Errorf("/admin on the host: %q", seen) + } + if c := do("preview.example.test", "/"); c != http.StatusNotFound || seen != "" { + t.Errorf("the root of the host: %d %q", c, seen) + } + // the site's own host: untouched, not marked + if c := do("openrepl.test", "/preview/TOKEN/f/index.html"); c != 204 || seen != "/preview/TOKEN/f/index.html" || marked { + t.Errorf("the site: %d %q %v", c, seen, marked) + } + if do("openrepl.test", "/admin"); seen != "/admin" || marked { + t.Errorf("the site's /admin: %q %v", seen, marked) + } + // no base set: the host means nothing + SaveSiteSettings(SiteSettings{}) + if do("preview.example.test", "/TOKEN/f/index.html"); seen != "/TOKEN/f/index.html" || marked { + t.Errorf("no base URL: %q %v", seen, marked) + } +} + +// a worker believes the mark only over the tunnel +func TestTheAddressesAFileOrProgramLinksToFollowTheForm(t *testing.T) { + plain := httptest.NewRequest("GET", "/preview/T/f/x", nil) + if previewPath(plain, "T") != "/preview/T" || publicPath(plain, "/preview/T/p/8000") != "/preview/T/p/8000" { + t.Error("the site's own form") + } + host := gateway.MarkPreviewHost(httptest.NewRequest("GET", "/preview/T/f/x", nil)) + if previewPath(host, "T") != "/T" || publicPath(host, "/preview/T/p/8000") != "/T/p/8000" { + t.Errorf("the host's form: %q %q", previewPath(host, "T"), publicPath(host, "/preview/T/p/8000")) + } + // the trusted header of the gateway, on a request that did not come over the tunnel, means nothing + forged := httptest.NewRequest("GET", "/preview/T/f/x", nil) + forged.Header.Set(trusted.HeaderPreviewHost, "1") + if previewPath(forged, "T") != "/preview/T" { + t.Error("a client's copy of the header was believed") + } +} + +// the whole route on the host: a file of the workspace is served at //f/, and the site's form still works +func TestAFileIsServedOnThePreviewHostAndOnTheSite(t *testing.T) { + withSecret(t) + old := GetSiteSettings() + defer SaveSiteSettings(old) + SaveSiteSettings(SiteSettings{PreviewBaseURL: "https://preview.example.test"}) + home := filepath.Join(t.TempDir(), "guest-abc") + os.MkdirAll(home, 0o755) + os.WriteFile(filepath.Join(home, "index.html"), []byte("

mine

"), 0o644) + tok, err := livepreview.NewToken(utils.Secret(), home, time.Now(), time.Hour) + if err != nil { + t.Fatal(err) + } + s := &Server{} + h := s.wrapPreviewHost(http.HandlerFunc(s.handlePreview), "/") + get := func(host, path string) *httptest.ResponseRecorder { + rec := httptest.NewRecorder() + h.ServeHTTP(rec, httptest.NewRequest("GET", "http://"+host+path, nil)) + return rec + } + for _, c := range []struct{ host, path string }{ + {"preview.example.test", "/" + tok + "/f/index.html"}, + {"preview.example.test", "/preview/" + tok + "/f/index.html"}, + {"openrepl.test", "/preview/" + tok + "/f/index.html"}, + } { + rec := get(c.host, c.path) + if rec.Code != 200 || !strings.Contains(rec.Body.String(), "

mine

") { + t.Errorf("%s%s: %d %q", c.host, c.path, rec.Code, rec.Body.String()) + } + } + // the site's host has no // form + if rec := get("openrepl.test", "/"+tok+"/f/index.html"); rec.Code == 200 { + t.Error("the site answered the host's form") + } + // a token that ended is the same "ended" page on the host + if rec := get("preview.example.test", "/bad.token/f/index.html"); rec.Code != http.StatusGone { + t.Errorf("a bad token on the host: %d", rec.Code) + } +} diff --git a/src/server/server.go b/src/server/server.go index c690672e..6a112b9b 100755 --- a/src/server/server.go +++ b/src/server/server.go @@ -429,15 +429,15 @@ func (server *Server) setupHandlers(ctx context.Context, cancel context.CancelFu if err != nil { return nil, err } - return server.wrapControls(gw, pathPrefix), nil + return server.wrapPreviewHost(server.wrapControls(gw, pathPrefix), pathPrefix), nil } if server.options.Mode == ModeWorker { // The gateway applies the switches before it forwards a terminal; the // worker applies them, from the gateway's config, to its own visitors. - return server.wrapWorkerControls(siteHandler, pathPrefix), nil + return server.wrapPreviewHost(server.wrapWorkerControls(siteHandler, pathPrefix), pathPrefix), nil } - return server.wrapControls(siteHandler, pathPrefix), nil + return server.wrapPreviewHost(server.wrapControls(siteHandler, pathPrefix), pathPrefix), nil } func (server *Server) setupHTTPServer(handler http.Handler) (*http.Server, error) { diff --git a/src/server/settings.go b/src/server/settings.go index f06d7900..1b0b516c 100644 --- a/src/server/settings.go +++ b/src/server/settings.go @@ -7,6 +7,8 @@ import ( "log" "math" "net/http" + "net/url" + "os" "regexp" "sort" "strings" @@ -93,6 +95,10 @@ type SiteSettings struct { // for a new one before it ends; a link opened in a tab of its own ends with it. PreviewLinkGuestMinutes int `json:"previewLinkGuestMinutes"` PreviewLinkUserMinutes int `json:"previewLinkUserMinutes"` + // PreviewBaseURL is an optional separate origin for preview frames, for example + // https://preview.openrepl.com. It has no path: frames use //... there. + // Empty keeps previews on this site's /preview//... route. + PreviewBaseURL string `json:"previewBaseURL"` // ShareLinkGuestMinutes and ShareLinkUserMinutes are the longest a share link of a live session may work (the time chosen // in the Share popover, with the time added), in minutes, from 10 to 10080 (7 days); 0 means the built-in 60 (guest: 1 // hour) and 10080 (signed in: 7 days, as long as a sign-in lasts). @@ -326,6 +332,22 @@ func (s SiteSettings) normalize() (SiteSettings, error) { return s, fmt.Errorf("the time a preview link works for %s must be between %d and %d minutes (or empty)", name, minPreviewLinkMinutes, maxPreviewLinkMinutes) } } + base, err := cleanPreviewBaseURL(s.PreviewBaseURL) + if err != nil { + return s, err + } + s.PreviewBaseURL = base + if base != "" { + pubRaw := strings.TrimSpace(os.Getenv("OPENREPL_PUBLIC_URL")) + if pubRaw != "" && !strings.Contains(pubRaw, "://") { + pubRaw = defaultScheme(pubRaw) + pubRaw // a bare host name, as with the preview base URL + } + if pub, perr := url.Parse(pubRaw); perr == nil && pub.Hostname() != "" { + if bu, _ := parsePreviewBase(base); bu != nil && strings.EqualFold(bu.Hostname(), pub.Hostname()) { + return s, fmt.Errorf("the preview base URL must not have the same host name as this site (OPENREPL_PUBLIC_URL); use a separate host name") + } + } + } if s.StoreLimitMB != 0 && (s.StoreLimitMB < 100 || s.StoreLimitMB > 1048576) { return s, fmt.Errorf("the size of the App Store must be between 100 and 1048576 MB (or empty)") } @@ -649,6 +671,8 @@ type publicSettings struct { PreviewOff bool `json:"previewOff"` PreviewGuestsOff bool `json:"previewGuestsOff"` PreviewAgentOff bool `json:"previewAgentOff"` + // the separate origin of the preview frames (empty: this site's /preview//... addresses), see previewhost.go + PreviewBaseURL string `json:"previewBaseURL"` // the page reports the agent's failed steps (genie_log.go) unless an admin switched that off GenieEventsOff bool `json:"genieEventsOff"` // the models a stuck task may be tried again with, in order (GenieSettings.EscalationModels) @@ -918,6 +942,66 @@ func (s SiteSettings) previewLinkLife(guest bool) time.Duration { return time.Duration(m) * time.Minute } +// previewBaseURL is the origin of the preview host (scheme and host, as the pages and the workers use it), or "" when previews +// stay below this site's /preview route. The setting is kept as the admin typed it (preview.openrepl.com); the scheme is derived +// here (defaultScheme) unless one was typed. Settings are normalized before use, but this defensive parse also keeps a bad old +// record on the compatible path. +func (s SiteSettings) previewBaseURL() string { + u, err := parsePreviewBase(s.PreviewBaseURL) + if err != nil || u == nil { + return "" + } + return u.Scheme + "://" + strings.ToLower(u.Host) +} + +// defaultScheme is the scheme for a host typed without one: http for a local development host +// (localhost, 127.0.0.1, [::1], *.localhost, *.test), https for everything else. +func defaultScheme(host string) string { + h := strings.ToLower(host) + if i := strings.IndexAny(h, "/?#"); i >= 0 { + h = h[:i] + } + if strings.HasPrefix(h, "[") { + if j := strings.Index(h, "]"); j >= 0 { + h = h[:j+1] + } + } else if i := strings.LastIndex(h, ":"); i >= 0 { + h = h[:i] + } + if h == "localhost" || h == "127.0.0.1" || h == "[::1]" || strings.HasSuffix(h, ".localhost") || strings.HasSuffix(h, ".test") { + return "http://" + } + return "https://" +} + +// cleanPreviewBaseURL checks the setting and returns it as typed (trimmed, lower case, no trailing slash): no scheme is added to it. +func cleanPreviewBaseURL(raw string) (string, error) { + raw = strings.TrimSpace(raw) + if raw == "" { + return "", nil + } + if _, err := parsePreviewBase(raw); err != nil { + return "", err + } + return strings.ToLower(strings.TrimRight(raw, "/")), nil +} + +// parsePreviewBase reads the setting as a URL: a host typed without a scheme gets one (http for a local host, else https). nil for "". +func parsePreviewBase(raw string) (*url.URL, error) { + raw = strings.TrimSpace(raw) + if raw == "" { + return nil, nil + } + if !strings.Contains(raw, "://") && !strings.HasPrefix(raw, "//") { + raw = defaultScheme(raw) + raw + } + u, err := url.Parse(raw) + if err != nil || u.Scheme == "" || u.Hostname() == "" || (u.Scheme != "https" && u.Scheme != "http") || u.User != nil || (u.Path != "" && u.Path != "/") || u.RawQuery != "" || u.Fragment != "" { + return nil, fmt.Errorf("the preview base URL must be a host name such as preview.openrepl.com (a scheme is optional; http for a local host, https otherwise), without a path, query or fragment") + } + return u, nil +} + // maxEditorFileMB is the limit in force: the one set, or the built-in 16. func (s SiteSettings) maxEditorFileMB() int { if s.MaxEditorFileMB < minEditorFileMB || s.MaxEditorFileMB > maxEditorFileMB { @@ -944,6 +1028,7 @@ func (s SiteSettings) public() publicSettings { PreviewOff: s.PreviewOff, PreviewGuestsOff: s.PreviewGuestsOff, PreviewAgentOff: s.PreviewAgentOff, + PreviewBaseURL: s.PreviewBaseURL, // as typed: the page adds the scheme and port of the site it was opened from GenieEventsOff: s.GenieEventsOff, EscalationModels: s.Genie.EscalationModels, GenieAuto: s.Genie.autoPublic(), @@ -1223,6 +1308,9 @@ func settingsChanges(a, b SiteSettings) []string { if a.PreviewGuestsOff != b.PreviewGuestsOff { out = append(out, "preview for guests "+onoff(!b.PreviewGuestsOff)) } + if a.previewBaseURL() != b.previewBaseURL() { + out = append(out, "preview base URL "+orStr(b.previewBaseURL(), "this site")) + } if a.previewLinkLife(true) != b.previewLinkLife(true) { out = append(out, fmt.Sprintf("preview link works %d minutes for guests", int(b.previewLinkLife(true).Minutes()))) } diff --git a/src/server/worker_config.go b/src/server/worker_config.go index 860d672b..624f8399 100644 --- a/src/server/worker_config.go +++ b/src/server/worker_config.go @@ -35,6 +35,7 @@ func applyWorkerConfig(c *tunnel.WorkerConfig) { Maintenance: Maintenance{Enabled: c.Maintenance, Message: c.MaintenanceMessage}, DisabledLanguages: c.DisabledLanguages, EgressOn: c.Egress, + PreviewBaseURL: c.PreviewBaseURL, } if s.Announcement.Level == "" { s.Announcement.Level = "info" diff --git a/src/server/worker_config_test.go b/src/server/worker_config_test.go index f4b9b73a..b97f7e44 100644 --- a/src/server/worker_config_test.go +++ b/src/server/worker_config_test.go @@ -162,3 +162,23 @@ func TestTheInternetSwitchReachesTheWorkers(t *testing.T) { t.Fatal("a worker kept the switch after the gateway turned it off") } } + +// the preview host reaches the workers with the other site rules, and changes the revision a worker compares +func TestThePreviewBaseURLReachesTheWorkers(t *testing.T) { + adminTestServer(t) + s := &Server{} + before := s.gatewayWorkerConfig() + SaveSiteSettings(SiteSettings{PreviewBaseURL: "https://preview.example.test"}) + got := s.gatewayWorkerConfig() + if got.PreviewBaseURL != "https://preview.example.test" || got.Revision == before.Revision { + t.Fatalf("the base URL must be in the config and change its revision: %+v", got) + } + applyWorkerConfig(&tunnel.WorkerConfig{Revision: 11, PreviewBaseURL: "https://preview.example.test"}) + if GetSiteSettings().previewBaseURL() != "https://preview.example.test" { + t.Fatal("a worker did not follow the gateway's preview host") + } + applyWorkerConfig(&tunnel.WorkerConfig{Revision: 12}) + if GetSiteSettings().previewBaseURL() != "" { + t.Fatal("a worker kept the preview host after the gateway cleared it") + } +} diff --git a/src/trusted/trusted.go b/src/trusted/trusted.go index 2d43a7c6..c575854f 100644 --- a/src/trusted/trusted.go +++ b/src/trusted/trusted.go @@ -20,6 +20,9 @@ const ( HeaderHomeID = "X-Openrepl-Home-Id" HeaderPriv = "X-Openrepl-Priv" HeaderSession = "X-Openrepl-Session" + // HeaderPreviewHost is "1" on a Preview request the gateway took on the preview host (//... there): the gateway forwards it in the + // site's own form (/preview//...), and the worker, which makes the addresses a page links to, must make them in the host's form. + HeaderPreviewHost = "X-Openrepl-Preview-Host" ) // Identity is who a forwarded request belongs to, as decided by the gateway. diff --git a/src/tunnel/protocol.go b/src/tunnel/protocol.go index 09211ac2..7467cb61 100644 --- a/src/tunnel/protocol.go +++ b/src/tunnel/protocol.go @@ -97,6 +97,7 @@ type WorkerConfig struct { MaintenanceMessage string `json:"maintenance_message,omitempty"` DisabledLanguages []string `json:"disabled_languages,omitempty"` Egress bool `json:"egress,omitempty"` // internet for signed-in users' REPLs through the proxy (LLD 16 "Egress") + PreviewBaseURL string `json:"preview_base_url,omitempty"` } // StoreUpdate is the App Store's catalog as the gateway hands it to a worker (the tunnel does not look inside it). Rev identifies