mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-20 04:59:34 +01:00
chore(webview): name a root-absolute request that escapes the proxy
When a web tab's boot module (or any asset it builds at runtime) escapes the `/webview/<cap>/` 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.
This commit is contained in:
1 parent
0b3087918f
commit
0ea97d62ec
4 files changed
+209
-4
No files matched your search
+38
-1
@@ -269,7 +269,7 @@ import {
|
||||
registerCliRegistryRoutes,
|
||||
registerLocalModelRoutes,
|
||||
} from './routes/index.js';
|
||||
import { isLostWebviewFrameNavigation } from './webview-proxy.js';
|
||||
import { escapedWebviewAssetPath, isLostWebviewFrameNavigation } from './webview-proxy.js';
|
||||
import { CronService } from '../cron/cron-service.js';
|
||||
import { caseSessionSettled } from '../case-rename.js';
|
||||
|
||||
@@ -361,6 +361,38 @@ function getOrCreateSelfSignedCert(): { key: string; cert: string } {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* One warn per escaped path per few minutes.
|
||||
*
|
||||
* A page whose boot module 404s retries in a loop, so an undeduped warn would
|
||||
* bury the log it is meant to explain. Capped so a page emitting unbounded
|
||||
* unique paths cannot grow the map without limit.
|
||||
*/
|
||||
const escapedWebviewWarnedAt = new Map<string, number>();
|
||||
const ESCAPED_WEBVIEW_WARN_TTL_MS = 5 * 60_000;
|
||||
|
||||
/**
|
||||
* Name a root-absolute request that escaped a web tab's proxy prefix.
|
||||
*
|
||||
* Nothing is retried or rewritten here — the request genuinely has no capability
|
||||
* to relay to. This exists because that failure is otherwise silent: the tab
|
||||
* shows a blank page or a spinner that never resolves, and the log says nothing.
|
||||
*
|
||||
* @param path - request path already judged as that shape.
|
||||
*/
|
||||
function warnEscapedWebviewAsset(path: string): void {
|
||||
const now = Date.now();
|
||||
const last = escapedWebviewWarnedAt.get(path);
|
||||
if (last !== undefined && now - last < ESCAPED_WEBVIEW_WARN_TTL_MS) return;
|
||||
if (escapedWebviewWarnedAt.size >= 200) escapedWebviewWarnedAt.clear();
|
||||
escapedWebviewWarnedAt.set(path, now);
|
||||
console.warn(
|
||||
`[Webview] ${path} escaped the proxy: a web tab asked for a root-absolute URL that no Codeman route serves. ` +
|
||||
`Its URL is masked, so the Referer cannot identify the dashboard. Usual cause: a URL built at runtime ` +
|
||||
`(dynamic import(), worker, service worker) or an import inside an external script. The tab will look blank or stuck.`
|
||||
);
|
||||
}
|
||||
|
||||
export class WebServer extends EventEmitter {
|
||||
private app: FastifyInstance;
|
||||
private sessions: Map<string, Session> = new Map();
|
||||
@@ -1294,6 +1326,11 @@ export class WebServer extends EventEmitter {
|
||||
// and the relay declines unless the Referer carries a live capability, so
|
||||
// genuinely unknown `/api` paths still get the envelope below.
|
||||
if (await tryWebviewRefererFallback(req, reply, this.basePath)) return reply;
|
||||
// No capability in the Referer, so this cannot be relayed — but if it has
|
||||
// the shape of a dashboard asset, say so once. Silent 404s here are what
|
||||
// turned a boot-module failure into a "blank tab" mystery more than once.
|
||||
const escaped = escapedWebviewAssetPath({ method: req.method, url: req.url, headers: req.headers });
|
||||
if (escaped) warnEscapedWebviewAsset(escaped);
|
||||
// An authenticated web-tab frame (Basic auth, or trusted mode with a cookie)
|
||||
// that navigated itself off its proxy prefix: the runtime shim masks the
|
||||
// prefix so the page's router sees its own path, and a reload of that page
|
||||
|
||||
Reference in new issue
Block a user