Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(panels): a pinned page that refuses to be framed says so, with Open in browser (#4030)
Aditya Umale165f6fd96b8e
diff --git a/docs/pr-screenshots/web-panel-blocked-site/1-before-deny-and-csp.png b/docs/pr-screenshots/web-panel-blocked-site/1-before-deny-and-csp.pngnew file mode 100644index 0000000000..4c19a6af13Binary files /dev/null and b/docs/pr-screenshots/web-panel-blocked-site/1-before-deny-and-csp.png differdiff --git a/docs/pr-screenshots/web-panel-blocked-site/2-after-deny-and-csp.png b/docs/pr-screenshots/web-panel-blocked-site/2-after-deny-and-csp.pngnew file mode 100644index 0000000000..e1673b5e75Binary files /dev/null and b/docs/pr-screenshots/web-panel-blocked-site/2-after-deny-and-csp.png differdiff --git a/docs/pr-screenshots/web-panel-blocked-site/3-before-sameorigin.png b/docs/pr-screenshots/web-panel-blocked-site/3-before-sameorigin.pngnew file mode 100644index 0000000000..839f046203Binary files /dev/null and b/docs/pr-screenshots/web-panel-blocked-site/3-before-sameorigin.png differdiff --git a/docs/pr-screenshots/web-panel-blocked-site/4-after-sameorigin.png b/docs/pr-screenshots/web-panel-blocked-site/4-after-sameorigin.pngnew file mode 100644index 0000000000..dd9d4c3989Binary files /dev/null and b/docs/pr-screenshots/web-panel-blocked-site/4-after-sameorigin.png differdiff --git a/docs/pr-screenshots/web-panel-blocked-site/5-before-embeddable.png b/docs/pr-screenshots/web-panel-blocked-site/5-before-embeddable.pngnew file mode 100644index 0000000000..66ff4fd0c4Binary files /dev/null and b/docs/pr-screenshots/web-panel-blocked-site/5-before-embeddable.png differdiff --git a/docs/pr-screenshots/web-panel-blocked-site/6-after-embeddable.png b/docs/pr-screenshots/web-panel-blocked-site/6-after-embeddable.pngnew file mode 100644index 0000000000..79de40d419Binary files /dev/null and b/docs/pr-screenshots/web-panel-blocked-site/6-after-embeddable.png differdiff --git a/server/routes/table.ts b/server/routes/table.tsindex 6bb1143c50..a157b7ff19 100644--- a/server/routes/table.ts+++ b/server/routes/table.ts@@ -4,6 +4,7 @@ import type { json, readBody } from "../harness/http.ts";import type { RequestAuth } from "../request-auth.ts";import { cloudSyncRoutes } from "./cloud-sync.ts";import { ownMcpHttpRoutes } from "./own-mcp-http.ts";+import { webPanelRoutes } from "./web-panels.ts";export const PASS: unique symbol = Symbol("route.pass");@@ -22,7 +23,7 @@ export interface RouteContext {export type RouteHandler = (ctx: RouteContext) => Promise<typeof PASS | void>;/** Modules with no wiring from index.ts are listed here; index.ts pushes the rest. */-export const ROUTES: RouteHandler[] = [cloudSyncRoutes, ownMcpHttpRoutes];+export const ROUTES: RouteHandler[] = [cloudSyncRoutes, ownMcpHttpRoutes, webPanelRoutes];/** True means stop routing. A handler that wrote a response but returned PASS still counts as answered. */export async function dispatchRoutes(routes: readonly RouteHandler[], ctx: RouteContext): Promise<boolean> {diff --git a/server/routes/web-panels.ts b/server/routes/web-panels.tsnew file mode 100644index 0000000000..79f9808100--- /dev/null+++ b/server/routes/web-panels.ts@@ -0,0 +1,12 @@+import { checkFraming } from "../web-panel-framing.ts";+import { PASS, type RouteHandler } from "./table.ts";++/** GET /api/web-panels/framing?url=…&origin=…: whether the page at `url` lets the app at `origin` frame it.+ * Security: it reaches only public pages and answers with a verdict, never a page's content. */+export const webPanelRoutes: RouteHandler = async ({ res, url, path, method, json }) => {+ if (path !== "/api/web-panels/framing" || method !== "GET") return PASS;+ const page = url.searchParams.get("url");+ const origin = url.searchParams.get("origin");+ if (!page || !origin) return json(res, 400, { error: "url and origin are required." });+ return json(res, 200, { framing: await checkFraming(page, origin) });+};diff --git a/server/wait-probes.ts b/server/wait-probes.tsindex d2b3c1af42..2cd1d8b9fd 100644--- a/server/wait-probes.ts+++ b/server/wait-probes.ts@@ -1,6 +1,6 @@import { execFile } from "node:child_process";import { stat } from "node:fs/promises";-import { request as httpRequest, type IncomingMessage } from "node:http";+import { request as httpRequest, type IncomingHttpHeaders, type IncomingMessage } from "node:http";import { request as httpsRequest } from "node:https";import { isIP, type LookupFunction } from "node:net";import { join } from "node:path";@@ -165,18 +165,22 @@ export const PAGE_TIMEOUT_MS = 15_000;export const PAGE_MAX_BYTES = 2 * 1024 * 1024;export const PAGE_MAX_REDIRECTS = 3;-export type PageResult = { ok: true; text: string } | { ok: false; refused: boolean; error: string };+type Failure = { ok: false; refused: boolean; error: string };+export type PageResult = { ok: true; text: string } | Failure;+/** The 2xx answer a redirect chain ended on: its address, headers and at most `maxBytes` of its body. */+export type PublicPage = { ok: true; url: URL; headers: IncomingHttpHeaders; body: Buffer } | Failure;export interface PageFetchOptions {allow?: (target: { host: string; address: string }) => boolean;lookup?: (host: string) => Promise<Array<{ address: string; family: number }>>;timeoutMs?: number;maxBytes?: number;+ maxRedirects?: number;}-type Answer = { status: number; location?: string; body: Buffer };+type Answer = { status: number; location?: string; headers: IncomingHttpHeaders; body: Buffer };-const fail = (error: string, refused = false): PageResult => ({ ok: false, refused, error });+const fail = (error: string, refused = false): Failure => ({ ok: false, refused, error });function requestOnce(url: URL, address: { address: string; family: number }, signal: AbortSignal, maxBytes: number): Promise<Answer> {return new Promise((resolve, reject) => {@@ -195,10 +199,10 @@ function requestOnce(url: URL, address: { address: string; family: number }, sig},(response: IncomingMessage) => {const status = response.statusCode ?? 0;- const location = response.headers.location;+ const { headers } = response;if (status < 200 || status >= 300) {response.destroy();- resolve({ status, location, body: Buffer.alloc(0) });+ resolve({ status, location: headers.location, headers, body: Buffer.alloc(0) });return;}const chunks: Buffer[] = [];@@ -208,10 +212,10 @@ function requestOnce(url: URL, address: { address: string; family: number }, sigsize += chunk.length;if (size >= maxBytes) {response.destroy();- resolve({ status, body: Buffer.concat(chunks).subarray(0, maxBytes) });+ resolve({ status, headers, body: Buffer.concat(chunks).subarray(0, maxBytes) });}});- response.on("end", () => resolve({ status, body: Buffer.concat(chunks) }));+ response.on("end", () => resolve({ status, headers, body: Buffer.concat(chunks) }));response.on("error", reject);},);@@ -230,6 +234,13 @@ function withinSignal<T>(promise: Promise<T>, signal: AbortSignal): Promise<T> {}export async function fetchPageText(rawUrl: string, options: PageFetchOptions = {}): Promise<PageResult> {+ const page = await fetchPublicPage(rawUrl, options);+ return page.ok ? { ok: true, text: pageText(page.body.toString("utf8")) } : page;+}++/** Security: only a public address, checked again on every redirect and pinned for the request, so a page can't+ * point this server at itself or a private network. */+export async function fetchPublicPage(rawUrl: string, options: PageFetchOptions = {}): Promise<PublicPage> {const lookup = options.lookup ?? resolveTarget;const allow = options.allow ?? (({ address }) => addressClass(address, ownAddresses()) === "public");const maxBytes = options.maxBytes ?? PAGE_MAX_BYTES;@@ -255,12 +266,12 @@ export async function fetchPageText(rawUrl: string, options: PageFetchOptions =signal.throwIfAborted();const answer = await requestOnce(url, addresses[0], signal, maxBytes);if (answer.status >= 300 && answer.status < 400 && answer.location) {- if (hop >= PAGE_MAX_REDIRECTS) return fail("The page redirected too many times.");+ if (hop >= (options.maxRedirects ?? PAGE_MAX_REDIRECTS)) return fail("The page redirected too many times.");url = new URL(answer.location, url);continue;}if (answer.status < 200 || answer.status >= 300) return fail(`The page answered ${answer.status}.`);- return { ok: true, text: pageText(answer.body.toString("utf8")) };+ return { ok: true, url, headers: answer.headers, body: answer.body };}} catch {return signal.aborted ? fail("The page took too long to answer.") : fail("The page could not be reached.");diff --git a/server/web-panel-framing.test.ts b/server/web-panel-framing.test.tsnew file mode 100644index 0000000000..337f0cab28--- /dev/null+++ b/server/web-panel-framing.test.ts@@ -0,0 +1,106 @@+import { createServer, type Server } from "node:http";+import type { AddressInfo } from "node:net";++import { afterAll, beforeAll, describe, expect, it } from "vitest";++import { checkFraming, framingOf } from "./web-panel-framing.ts";++const APP = "http://127.0.0.1:8799";+const PAGE = "https://www.globo.com/";++describe("framingOf", () => {+ it("lets a page with neither header be framed", () => {+ expect(framingOf({}, PAGE, APP)).toBe("allowed");+ });++ it("follows X-Frame-Options as browsers do", () => {+ expect(framingOf({ "x-frame-options": "DENY" }, PAGE, APP)).toBe("blocked");+ expect(framingOf({ "x-frame-options": " sameorigin " }, PAGE, APP)).toBe("blocked");+ expect(framingOf({ "x-frame-options": "SAMEORIGIN" }, "http://127.0.0.1:8799/x", APP)).toBe("allowed");+ expect(framingOf({ "x-frame-options": "ALLOWALL" }, PAGE, APP)).toBe("allowed");+ expect(framingOf({ "x-frame-options": "ALLOW-FROM https://a.example" }, PAGE, APP)).toBe("allowed");+ expect(framingOf({ "x-frame-options": "DENY, SAMEORIGIN" }, PAGE, APP)).toBe("blocked");+ expect(framingOf({ "x-frame-options": "nonsense, other" }, PAGE, APP)).toBe("allowed");+ });++ it("reads Globo's frame-ancestors as refusing the app", () => {+ const csp = "frame-ancestors 'self' https://*.globo.com https://*.globoi.com https://*.i.globo https://*.techtudo.com.br always";+ expect(framingOf({ "content-security-policy": csp }, PAGE, APP)).toBe("blocked");+ });++ it("lets frame-ancestors override X-Frame-Options", () => {+ expect(framingOf({ "x-frame-options": "DENY", "content-security-policy": "frame-ancestors *" }, PAGE, APP)).toBe("allowed");+ });++ it("matches the app origin against each frame-ancestors source", () => {+ const verdict = (sources: string, app = APP) => framingOf({ "content-security-policy": `default-src 'self'; frame-ancestors ${sources}` }, PAGE, app);+ expect(verdict("'none'")).toBe("blocked");+ expect(verdict("'self'")).toBe("blocked");+ expect(verdict("*")).toBe("allowed");+ expect(verdict("http:")).toBe("allowed");+ expect(verdict("https:")).toBe("blocked");+ expect(verdict("http:", "https://omb.example.com")).toBe("allowed");+ expect(verdict("http://127.0.0.1:8799")).toBe("allowed");+ expect(verdict("http://127.0.0.1:*")).toBe("allowed");+ expect(verdict("http://127.0.0.1")).toBe("blocked");+ expect(verdict("127.0.0.1:8799")).toBe("blocked");+ expect(verdict("omb.example.com", "https://omb.example.com")).toBe("allowed");+ expect(verdict("*.example.com", "https://omb.example.com")).toBe("allowed");+ expect(verdict("*.example.com", "https://example.com")).toBe("blocked");+ expect(verdict("https://OMB.example.com/", "https://omb.example.com")).toBe("allowed");+ expect(verdict("https://omb.example.com:443", "https://omb.example.com")).toBe("allowed");+ expect(verdict("http://omb.example.com:80", "https://omb.example.com")).toBe("unknown");+ expect(framingOf({ "content-security-policy": "frame-ancestors; default-src *" }, PAGE, APP)).toBe("blocked");+ expect(verdict("'nonce-abc' 'unsafe-inline'")).toBe("blocked");+ });++ it("says unknown rather than blocked when it cannot read a source", () => {+ const verdict = (sources: string) => framingOf({ "content-security-policy": `frame-ancestors ${sources}` }, PAGE, APP);+ expect(verdict("http://127.0.0.1:8799/only/this")).toBe("unknown");+ expect(verdict("https://a.example/only/this")).toBe("blocked");+ expect(verdict("https://a.example %%")).toBe("unknown");+ });++ it("blocks when any one of several policies refuses, and ignores report-only", () => {+ expect(framingOf({ "content-security-policy": "frame-ancestors *, frame-ancestors 'none'" }, PAGE, APP)).toBe("blocked");+ expect(framingOf({ "content-security-policy-report-only": "frame-ancestors 'none'" }, PAGE, APP)).toBe("allowed");+ });+});++describe("checkFraming", () => {+ let server: Server;+ let port = 0;+ const test = {+ lookup: async (host: string) => (host === "panel.test" ? [{ address: "127.0.0.1", family: 4 }] : []),+ allow: ({ host }: { host: string }) => host === "panel.test",+ };+ beforeAll(async () => {+ server = createServer((req, res) => {+ if (req.url === "/deny") res.writeHead(200, { "x-frame-options": "DENY" }).end("no");+ else if (req.url === "/hop") res.writeHead(302, { location: "/deny" }).end();+ else if (req.url === "/ok") res.writeHead(200).end("yes");+ else res.writeHead(404).end();+ });+ await new Promise<void>((done) => server.listen(0, "127.0.0.1", done));+ port = (server.address() as AddressInfo).port;+ });+ afterAll(() => {+ server.closeAllConnections();+ server.close();+ });++ it("reads the headers of the page itself", async () => {+ expect(await checkFraming(`http://panel.test:${port}/deny`, APP, test)).toBe("blocked");+ expect(await checkFraming(`http://panel.test:${port}/ok`, APP, test)).toBe("allowed");+ });++ it("can't tell from a redirect, which may lead to a sign-in page the person's browser never gets", async () => {+ expect(await checkFraming(`http://panel.test:${port}/hop`, APP, test)).toBe("unknown");+ });++ it("can't tell for a page it may not or could not reach", async () => {+ expect(await checkFraming(`http://127.0.0.1:${port}/deny`, APP)).toBe("unknown");+ expect(await checkFraming(`http://panel.test:${port}/missing`, APP, test)).toBe("unknown");+ expect(await checkFraming("not a url", APP, test)).toBe("unknown");+ });+});diff --git a/server/web-panel-framing.ts b/server/web-panel-framing.tsnew file mode 100644index 0000000000..5068329b1e--- /dev/null+++ b/server/web-panel-framing.ts@@ -0,0 +1,99 @@+// Chrome fires `load` on a frame it refused, and the parent page can't tell that frame from a working cross-origin one+// (checked on Chrome 153), so only the page's own headers say why a pinned web panel stays blank. They are read the way+// browsers read them: HTML's X-Frame-Options processing and CSP Level 3's frame-ancestors.+import type { IncomingHttpHeaders } from "node:http";++import { fetchPublicPage, type PageFetchOptions } from "./wait-probes.ts";++/** `unknown` whenever this can't be sure. */+export type Framing = "allowed" | "blocked" | "unknown";++const SCHEME_SOURCE = /^[a-z][a-z0-9+.-]*:$/;+const HOST_SOURCE = /^(?:([a-z][a-z0-9+.-]*):\/\/)?(\*|(?:\*\.)?[a-z0-9-]+(?:\.[a-z0-9-]+)*)(?::(\d+|\*))?(\/[^?#]*)?$/;++function headerItems(value: string | string[] | undefined): string[] {+ return (value === undefined ? [] : [value].flat()).flatMap((item) => item.split(","));+}++/** An app on https may sit in a frame that only names http, as CSP lets a scheme upgrade. */+function schemeMatches(scheme: string, app: URL): boolean {+ return scheme === app.protocol || (scheme === "http:" && app.protocol === "https:");+}++function hostMatches(host: string, app: URL): boolean {+ if (host === "*") return true;+ if (host.startsWith("*.")) return app.hostname.endsWith(host.slice(1));+ return app.hostname === host;+}++function sourceMatches(token: string, page: URL, app: URL): boolean | null {+ const source = token.toLowerCase();+ if (source === "*") return true;+ if (source === "'self'") return app.origin === page.origin;+ if (source.startsWith("'")) return false;+ if (SCHEME_SOURCE.test(source)) return schemeMatches(source, app);+ const parts = HOST_SOURCE.exec(source);+ if (!parts) return null;+ const [, scheme, host, port, path] = parts;+ if (!schemeMatches(scheme ? `${scheme}:` : page.protocol, app)) return false;+ if (!hostMatches(host, app)) return false;+ const defaultPort = app.protocol === "https:" ? "443" : "80";+ const appPort = app.port || defaultPort;+ if (port === "80" && appPort === "443") return null;+ if (port !== "*" && (port ?? defaultPort) !== appPort) return false;+ return path === undefined || path === "/" ? true : null;+}++function ancestorsAllow(sources: string[], page: URL, app: URL): boolean | null {+ let unsure = false;+ for (const source of sources) {+ const matches = sourceMatches(source, page, app);+ if (matches) return true;+ if (matches === null) unsure = true;+ }+ return unsure ? null : false;+}++/** The source list of each enforced policy's first frame-ancestors directive. */+function frameAncestorLists(value: string | string[] | undefined): string[][] {+ const lists: string[][] = [];+ for (const policy of headerItems(value)) {+ const directive = policy.split(";").map((part) => part.trim().split(/\s+/)).find(([name]) => name.toLowerCase() === "frame-ancestors");+ if (directive) lists.push(directive.slice(1));+ }+ return lists;+}++function xFrameOptionsAllow(value: string | string[] | undefined, page: URL, app: URL): boolean {+ const options = new Set(headerItems(value).map((item) => item.trim().toLowerCase()));+ if (options.size > 1) return !["deny", "allowall", "sameorigin"].some((option) => options.has(option));+ if (options.has("deny")) return false;+ return !options.has("sameorigin") || page.origin === app.origin;+}++export function framingOf(headers: IncomingHttpHeaders, pageUrl: string, appOrigin: string): Framing {+ let page: URL;+ let app: URL;+ try {+ page = new URL(pageUrl);+ app = new URL(appOrigin);+ } catch {+ return "unknown";+ }+ const lists = frameAncestorLists(headers["content-security-policy"]);+ if (lists.length === 0) return xFrameOptionsAllow(headers["x-frame-options"], page, app) ? "allowed" : "blocked";+ let unsure = false;+ for (const sources of lists) {+ const allows = ancestorsAllow(sources, page, app);+ if (allows === false) return "blocked";+ if (allows === null) unsure = true;+ }+ return unsure ? "unknown" : "allowed";+}++/** Never from this computer or a private network. This request carries none of the person's cookies, so a redirect or+ * an error answer may be a sign-in page their browser never gets: those say unknown. */+export async function checkFraming(url: string, appOrigin: string, options: PageFetchOptions = {}): Promise<Framing> {+ const page = await fetchPublicPage(url, { maxBytes: 1, maxRedirects: 0, timeoutMs: 8_000, ...options });+ return page.ok ? framingOf(page.headers, page.url.href, appOrigin) : "unknown";+}diff --git a/src/components/WebPanelPage.test.ts b/src/components/WebPanelPage.test.tsindex 5cb63ec0e9..e696c6d63c 100644--- a/src/components/WebPanelPage.test.ts+++ b/src/components/WebPanelPage.test.ts@@ -9,9 +9,11 @@ const fixture = vi.hoisted(() => ({panels: [] as Array<{ id: string; name: string; url: string }>,state: { webPanelId: "panel-1" } as { webPanelId?: string },dispatch: vi.fn(),+ api: vi.fn(async (_path: string, _init?: unknown): Promise<unknown> => ({ framing: "allowed" })),}));vi.mock("@/lib/web-panel-preferences", () => ({ useWebPanels: () => fixture.panels }));vi.mock("@/state/store", () => ({ useStore: () => ({ state: fixture.state, dispatch: fixture.dispatch }) }));+vi.mock("@/state/api", () => ({ api: fixture.api }));const { WebPanelPage } = await import("./WebPanelPage");@@ -39,6 +41,46 @@ describe("a pinned web panel's page", () => {expect(host.textContent).toContain("Open in browser");});+ it("says a site that refuses to be framed refuses it, and offers the browser instead", async () => {+ fixture.panels = [{ id: "panel-1", name: "Globo", url: "https://www.globo.com/" }];+ fixture.api.mockResolvedValueOnce({ framing: "blocked" });+ await act(async () => root.render(createElement(WebPanelPage)));+ expect(fixture.api).toHaveBeenCalledWith(+ `/api/web-panels/framing?url=${encodeURIComponent("https://www.globo.com/")}&origin=${encodeURIComponent(window.location.origin)}`,+ expect.objectContaining({ background: true }),+ );+ expect(host.querySelector("iframe")).toBeNull();+ expect(host.textContent).toContain("www.globo.com doesn't allow other apps to show it");+ expect([...host.querySelectorAll("button")].filter((button) => button.textContent === "Open in browser")).toHaveLength(2);+ });++ it("frames the page at once, and keeps it when the check can't tell or fails", async () => {+ fixture.panels = [{ id: "panel-1", name: "Board", url: "https://board.example.com/" }];+ let answer: (value: unknown) => void = () => undefined;+ fixture.api.mockReturnValueOnce(new Promise((resolve) => { answer = resolve; }));+ act(() => root.render(createElement(WebPanelPage)));+ expect(host.querySelector("iframe")?.getAttribute("src")).toBe("https://board.example.com/");+ await act(async () => answer({ framing: "unknown" }));+ expect(host.querySelector("iframe")?.getAttribute("src")).toBe("https://board.example.com/");++ fixture.panels = [{ id: "panel-1", name: "Board", url: "https://other.example.com/" }];+ fixture.api.mockRejectedValueOnce(new Error("forbidden"));+ await act(async () => root.render(createElement(WebPanelPage)));+ expect(host.querySelector("iframe")?.getAttribute("src")).toBe("https://other.example.com/");+ });++ it("never shows a refused panel's message on the next panel", async () => {+ fixture.panels = [{ id: "panel-1", name: "Globo", url: "https://www.globo.com/" }];+ fixture.api.mockResolvedValueOnce({ framing: "blocked" });+ await act(async () => root.render(createElement(WebPanelPage)));+ expect(host.querySelector("iframe")).toBeNull();++ fixture.panels = [{ id: "panel-1", name: "Board", url: "https://board.example.com/" }];+ fixture.api.mockReturnValueOnce(new Promise(() => {}));+ act(() => root.render(createElement(WebPanelPage)));+ expect(host.querySelector("iframe")?.getAttribute("src")).toBe("https://board.example.com/");+ });+it("goes back to the chat when its panel was removed", () => {fixture.panels = [];act(() => root.render(createElement(WebPanelPage)));diff --git a/src/components/WebPanelPage.tsx b/src/components/WebPanelPage.tsxindex d87aee3add..bb63fee5cd 100644--- a/src/components/WebPanelPage.tsx+++ b/src/components/WebPanelPage.tsx@@ -8,6 +8,7 @@ import { openExternalLink } from "@/lib/app-links";import { t } from "@/lib/i18n";import { useWebPanels } from "@/lib/web-panel-preferences";import { isAppOrigin } from "@/lib/web-panels";+import { api } from "@/state/api";import { useStore } from "@/state/store";const LOAD_TIMEOUT_MS = 10_000;@@ -18,6 +19,7 @@ export function WebPanelPage() {const panel = panels.find((entry) => entry.id === state.webPanelId);const [reloads, setReloads] = useState(0);const [status, setStatus] = useState<"loading" | "loaded" | "failed">("loading");+ const [refusedUrl, setRefusedUrl] = useState<string>();// A removed panel leaves nothing to show: go back to the conversation.useEffect(() => {@@ -30,7 +32,18 @@ export function WebPanelPage() {return () => clearTimeout(timer);}, [panel?.url, reloads]);+ // The browser fires load on a frame it refused, so only the page's headers, read by the server, tell.+ useEffect(() => {+ const url = panel?.url;+ if (!url) return;+ const check = new AbortController();+ api<{ framing?: string }>(`/api/web-panels/framing?url=${encodeURIComponent(url)}&origin=${encodeURIComponent(window.location.origin)}`, { background: true, signal: check.signal })+ .then(({ framing }) => setRefusedUrl(framing === "blocked" ? url : undefined), () => undefined);+ return () => check.abort();+ }, [panel?.url, reloads]);+if (!panel) return null;+ const refused = refusedUrl === panel.url;const openInBrowser = () => void openExternalLink(panel.url).catch(() => undefined);return (@@ -52,10 +65,10 @@ export function WebPanelPage() {{t("webPanels.page.openInBrowser")}</button></header>- {status === "failed" || isAppOrigin(panel.url, window.location.origin) ? (+ {refused || status === "failed" || isAppOrigin(panel.url, window.location.origin) ? (<div className="flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center"><p className="text-[14px] font-medium text-ink">{t("webPanels.page.cantEmbed")}</p>- <p className="max-w-sm text-[13px] text-ink-secondary">{t("webPanels.page.cantEmbedBody")}</p>+ <p className="max-w-sm text-[13px] text-ink-secondary">{refused ? t("webPanels.page.refusedBody", { site: new URL(panel.url).host }) : t("webPanels.page.cantEmbedBody")}</p><button type="button" className="ui-button ui-button-primary" onClick={openInBrowser}>{t("webPanels.page.openInBrowser")}</button>diff --git a/src/locales/en.json b/src/locales/en.jsonindex d8fdf69105..1ea2a9807e 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -6278,6 +6278,7 @@"webPanels.page.openInBrowser": "Open in browser","webPanels.page.cantEmbed": "This page can't be shown inside the app","webPanels.page.cantEmbedBody": "Some sites refuse to be embedded. Open it in your browser instead.",+ "webPanels.page.refusedBody": "{site} doesn't allow other apps to show it. Open it in your browser instead.","botAccess.tools.title": "Tool selection","botAccess.tools.description": "Advanced: narrow the tools offered to this bot. Existing approvals still apply.","botAccess.tools.corrupt": "This bot's saved tool selection is damaged, so the bot can't start. Choose its tools again to fix it.",