* Add embed rendering for Control UI assistant output * Add changelog entry for embed rendering * Harden canvas path resolution and stage isolation * Secure assistant media route and preserve UI avatar override * Fix chat media and history regressions * Harden embed iframe URL handling * Fix embed follow-up review regressions * Restore offloaded chat attachment persistence * Harden hook and media routing * Fix embed review follow-ups * feat(ui): add configurable embed sandbox mode * fix(gateway): harden assistant media and auth rotation * fix(gateway): restore websocket pairing handshake flows * fix(gateway): restore ws hello policy details * Restore dropped control UI shell wiring * Fix control UI reconnect cleanup regressions * fix(gateway): restore media root and auth getter compatibility * feat(ui): rename public canvas tag to embed * fix(ui): address remaining media and gateway review issues * fix(ui): address remaining embed and attachment review findings * fix(ui): restore stop control and tool card inputs * fix(ui): address history and attachment review findings * fix(ui): restore prompt contribution wiring * fix(ui): address latest history and directive reviews * fix(ui): forward password auth for assistant media * fix(ui): suppress silent transcript tokens with media * feat(ui): add granular embed sandbox modes * fix(ui): preserve relative media directives in history * docs(ui): document embed sandbox modes * fix(gateway): restrict canvas history hoisting to tool entries * fix(gateway): tighten embed follow-up review fixes * fix(ci): repair merged branch type drift * fix(prompt): restore stable runtime prompt rendering * fix(ui): harden local attachment preview checks * fix(prompt): restore channel-aware approval guidance * fix(gateway): enforce auth rotation and media cleanup * feat(ui): gate external embed urls behind config * fix(ci): repair rebased branch drift * fix(ci): resolve remaining branch check failures
92 lines
2.7 KiB
TypeScript
92 lines
2.7 KiB
TypeScript
import type { IncomingMessage } from "node:http";
|
|
import { A2UI_PATH, CANVAS_HOST_PATH, CANVAS_WS_PATH } from "../../canvas-host/a2ui.js";
|
|
import { safeEqualSecret } from "../../security/secret-equal.js";
|
|
import type { AuthRateLimiter } from "../auth-rate-limit.js";
|
|
import {
|
|
authorizeHttpGatewayConnect,
|
|
type GatewayAuthResult,
|
|
type ResolvedGatewayAuth,
|
|
} from "../auth.js";
|
|
import { CANVAS_CAPABILITY_TTL_MS } from "../canvas-capability.js";
|
|
import { getBearerToken, resolveHttpBrowserOriginPolicy } from "../http-utils.js";
|
|
import type { GatewayWsClient } from "./ws-types.js";
|
|
|
|
export function isCanvasPath(pathname: string): boolean {
|
|
return (
|
|
pathname === A2UI_PATH ||
|
|
pathname.startsWith(`${A2UI_PATH}/`) ||
|
|
pathname === CANVAS_HOST_PATH ||
|
|
pathname.startsWith(`${CANVAS_HOST_PATH}/`) ||
|
|
pathname === CANVAS_WS_PATH
|
|
);
|
|
}
|
|
|
|
function hasAuthorizedWsClientForCanvasCapability(
|
|
clients: Set<GatewayWsClient>,
|
|
capability: string,
|
|
): boolean {
|
|
const nowMs = Date.now();
|
|
for (const client of clients) {
|
|
if (!client.canvasCapability || !client.canvasCapabilityExpiresAtMs) {
|
|
continue;
|
|
}
|
|
if (client.canvasCapabilityExpiresAtMs <= nowMs) {
|
|
continue;
|
|
}
|
|
if (safeEqualSecret(client.canvasCapability, capability)) {
|
|
// Sliding expiration while the connected node keeps using canvas.
|
|
client.canvasCapabilityExpiresAtMs = nowMs + CANVAS_CAPABILITY_TTL_MS;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
export async function authorizeCanvasRequest(params: {
|
|
req: IncomingMessage;
|
|
auth: ResolvedGatewayAuth;
|
|
trustedProxies: string[];
|
|
allowRealIpFallback: boolean;
|
|
clients: Set<GatewayWsClient>;
|
|
canvasCapability?: string;
|
|
malformedScopedPath?: boolean;
|
|
rateLimiter?: AuthRateLimiter;
|
|
}): Promise<GatewayAuthResult> {
|
|
const {
|
|
req,
|
|
auth,
|
|
trustedProxies,
|
|
allowRealIpFallback,
|
|
clients,
|
|
canvasCapability,
|
|
malformedScopedPath,
|
|
rateLimiter,
|
|
} = params;
|
|
if (malformedScopedPath) {
|
|
return { ok: false, reason: "unauthorized" };
|
|
}
|
|
|
|
let lastAuthFailure: GatewayAuthResult | null = null;
|
|
const token = getBearerToken(req);
|
|
if (token) {
|
|
const authResult = await authorizeHttpGatewayConnect({
|
|
auth: { ...auth, allowTailscale: false },
|
|
connectAuth: { token, password: token },
|
|
req,
|
|
trustedProxies,
|
|
allowRealIpFallback,
|
|
rateLimiter,
|
|
browserOriginPolicy: resolveHttpBrowserOriginPolicy(req),
|
|
});
|
|
if (authResult.ok) {
|
|
return authResult;
|
|
}
|
|
lastAuthFailure = authResult;
|
|
}
|
|
|
|
if (canvasCapability && hasAuthorizedWsClientForCanvasCapability(clients, canvasCapability)) {
|
|
return { ok: true };
|
|
}
|
|
return lastAuthFailure ?? { ok: false, reason: "unauthorized" };
|
|
}
|