From 0ea97d62ecd9cbe0cf1adb83eb6e2c81b0291630 Mon Sep 17 00:00:00 2001 From: ArizeSky <97787713+ArizeSky@users.noreply.github.com> Date: Mon, 16 Nov 2026 10:09:37 +0800 Subject: [PATCH] chore(webview): name a root-absolute request that escapes the proxy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a web tab's boot module (or any asset it builds at runtime) escapes the `/webview//` prefix, the request reaches Codeman's 404 with nothing to relay to: the frame's document URL is masked, so its `Referer` carries no capability and the existing fallback declines. The tab then shows a blank page or a spinner that never resolves, and the log says nothing — the failure mode that made the DeepSeek Harness tab un-diagnosable twice. Classify that shape conservatively on the 404 path (asset-shaped `Sec-Fetch-Dest`, same-origin `Referer` at the masked landing path, not `/api`, not one of Codeman's own files) and log the path once per five minutes. Nothing is relayed or rewritten: this only turns a silent blank tab into one grep. Also document the boundary in `docs/web-tabs.md` — the root-absolute URLs the proxy never sees (runtime-built `import()`, imports inside external `.js`, static imports in inline scripts, service-worker registration, `url()` in external stylesheets) — so the next occurrence starts from the list instead of from zero. --- docs/web-tabs.md | 22 ++++++++++- src/web/server.ts | 39 ++++++++++++++++++- src/web/webview-proxy.ts | 78 +++++++++++++++++++++++++++++++++++++- test/webview-proxy.test.ts | 74 ++++++++++++++++++++++++++++++++++++ 4 files changed, 209 insertions(+), 4 deletions(-) diff --git a/docs/web-tabs.md b/docs/web-tabs.md index 0ace6a95..271bcb02 100644 --- a/docs/web-tabs.md +++ b/docs/web-tabs.md @@ -144,9 +144,17 @@ per-device (`localStorage`), since that is workspace layout rather than config. Worth knowing, because it is where this feature does its least obvious work. Three layers cooperate so a dashboard talking to its own backend just works: -1. `` handles relative URLs in the markup. +1. `` handles relative URLs in the markup. A page that ships its own + **relative** base (``, what a Vite build emits) has it resolved + against the proxy prefix first: the page's URL is masked a few paragraphs below, + a base is resolved against that URL, so `./` would otherwise point at Codeman's + root and 404 every module script behind an otherwise-painted page. 2. Attribute rewriting handles root-absolute `src`/`href`/`action` in the page the - proxy serves. + proxy serves — and root-absolute dynamic `import("/...")` specifiers in the + initial HTML. The import is the one URL no other layer can reach: `` does + not apply to a `/`-rooted specifier and it is not a `fetch()`. SvelteKit's inline + bootstrap is exactly this shape; without the rewrite the module loads from + Codeman's root, 404s, and the app sits on its own loading spinner forever. 3. A small injected script rebases URLs built at **runtime**, which the first two cannot see: `fetch('/api/data')` and `new WebSocket('/live')`, but equally `card.innerHTML = ''`, `img.src = '/api/slide'`, and @@ -190,6 +198,16 @@ then every API call fails, which looks like the dashboard being broken. EventSource, normal markup, the DOM sinks a page uses to build markup at runtime, and `url()` inside stylesheets. Something that constructs requests by an unusual route can still slip through. Symptom: the page renders but a panel stays empty. +- **Root-absolute URLs the proxy never sees.** Only the HTML is rewritten, and only + literal `/`-rooted specifiers in it. Still escape: an `import()` built at runtime + (`import('/' + name)`), an import written inside an external `.js`, a static + `import x from "/x"` in an inline script, `navigator.serviceWorker.register("/sw.js")`, + and `url(/img.png)` inside an external stylesheet. They cannot be relayed either — + the masked frame's `Referer` carries no capability — so the failure is quiet: a + blank page, or a spinner that never resolves. Codeman now logs + `[Webview] escaped the proxy` (once per path per five minutes) when such a + request reaches its 404, which is the fastest way to tell this class apart from a + dashboard that is genuinely broken. - **A root-absolute `url()` inside an inline `