openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
46 lines (45 loc) • 1.69 kB
JavaScript
import { t as WIDGET_CDN_ORIGINS } from "./widget-html-C-TQ8ePx.mjs";
import { c as WIDGET_MEDIA_SOURCES, r as buildSandboxHostPath } from "./sandbox-host-C-9vv4vO.mjs";
//#region src/gateway/board-sandbox.ts
let fixedSandboxPath;
function grantedConnectOrigins(e) {
if (e.grantState !== "granted") return;
const t = e.declared?.netOrigins;
return t?.length ? t : void 0;
}
function buildBoardWidgetSandboxPath(e) {
const t = grantedConnectOrigins(e);
const n = !t && !e.resourceOrigins?.length;
if (n && fixedSandboxPath !== void 0) return fixedSandboxPath;
const r = buildSandboxHostPath({
blockDescendantFrames: true,
mediaDomains: [...WIDGET_MEDIA_SOURCES, ...e.resourceOrigins ?? []],
resourceDomains: [.../* @__PURE__ */ new Set([...WIDGET_CDN_ORIGINS, ...e.resourceOrigins ?? []])],
...t ? { connectDomains: t } : {}
});
if (n) fixedSandboxPath = r;
return r;
}
/** Defense in depth for direct/legacy widget document loads outside the proxy host. */
function buildBoardWidgetContentSecurityPolicy(e) {
const t = grantedConnectOrigins(e)?.join(" ") ?? "'none'";
const n = e.resourceOrigins?.join(" ") ?? "";
const r = WIDGET_CDN_ORIGINS.join(" ");
return [
"default-src 'none'",
`script-src 'unsafe-inline' ${r} ${n}`.trim(),
`style-src 'unsafe-inline' ${r}`,
`font-src data: ${r}`,
`img-src data: ${n}`.trim(),
`media-src data: ${WIDGET_MEDIA_SOURCES.join(" ")} ${n}`.trim(),
`connect-src ${t}`,
"webrtc 'block'",
"base-uri 'none'",
"object-src 'none'",
"form-action 'none'",
"frame-src 'none'",
"sandbox allow-scripts"
].join("; ");
}
//#endregion
export { buildBoardWidgetSandboxPath as n, buildBoardWidgetContentSecurityPolicy as t };