CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
web-shell-static.d.ts59 linesDownload Raw Back to serve
1/**2 * @license3 * Copyright 2025 Qwen Team4 * SPDX-License-Identifier: Apache-2.05 */6import type { Application, Request } from 'express';7export { resolveWebShellDir } from './web-shell-resolver.js';8/**9 * Build the Web Shell CSP. `frame-ancestors` defaults to `'none'` (the caller10 * also sets `X-Frame-Options: DENY`) to block clickjacking. When the daemon is11 * started with `--allow-origin chrome-extension://<id>`, those extension12 * origins are allowed to frame the shell so the extension can host the UI in a13 * Chrome side panel (issue #5626); X-Frame-Options is dropped in that case14 * since it can't express an allowlist.15 */16export declare function buildWebShellCsp(frameAncestors?: readonly string[]): string;17/** Default (no-framing) Web Shell CSP. */18export declare const WEB_SHELL_CSP: string;19/**20 * True when the request is a top-level document navigation (address-bar21 * load, link click, or refresh) rather than a programmatic fetch/XHR.22 *23 * Mirrors the `bypass` discriminator in `packages/web-shell/vite.config.ts`24 * so the daemon's SPA fallback claims exactly the requests the dev proxy25 * would have served `index.html` for — and leaves API fetches (which carry26 * `Accept: application/json`) to fall through to the JSON routes / 404.27 */28export declare function isDocumentNavigation(req: Request): boolean;29/**30 * Mount the Web Shell static assets BEFORE `bearerAuth`. The shell carries no31 * secrets and a browser cannot attach an `Authorization` header to a32 * `<script src>` subresource or an address-bar navigation, so gating these33 * would just break the UI. The front-end's own API calls still carry the34 * bearer via `getDaemonAuthHeaders()`.35 *36 *  - `GET /assets/*` — hashed, immutable build chunks (long-cache).37 *  - `GET /` — the HTML shell, always (so `curl /` shows the UI too).38 *39 * Caller must have already verified `webShellDir` exists.40 */41export declare function mountWebShellAssets(app: Application, webShellDir: string, frameAncestors?: readonly string[]): void;42/**43 * Mount the SPA deep-link fallback (for navigations like `/session/<id>`).44 * Registered AFTER all API routes — just before the error handler — so real45 * routes, INCLUDING their `bearerAuth` 401s, always win and only genuine 40446 * misses fall through to the shell.47 *48 * This is what keeps a token-gated daemon honest: a navigation with an49 * attacker-controlled `Accept: text/html` to an authed route (e.g.50 * `/capabilities`, `/health` on a non-loopback bind) hits that route's real51 * response / 401, not this shell. Because real routes run first, no per-path52 * denylist is needed.53 *54 * Only GET/HEAD document navigations are claimed; API fetches send55 * `Accept: application/json`, fail `isDocumentNavigation`, and fall through to56 * the standard JSON 404.57 */58export declare function mountWebShellSpaFallback(app: Application, webShellDir: string, frameAncestors?: readonly string[]): void;59 
basant307/AI_Governance_Project · CoolFace