Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
test(clipper): fail when the preview's sandbox gains allow-scripts
Elian Doran2bc51fae8242
diff --git a/apps/web-clipper/entrypoints/popup/main.tsx b/apps/web-clipper/entrypoints/popup/main.tsxindex 4576cc2402..6cd2565a73 100644--- a/apps/web-clipper/entrypoints/popup/main.tsx+++ b/apps/web-clipper/entrypoints/popup/main.tsx@@ -494,8 +494,9 @@ function withDescription(labels: Record<string, string> | undefined, description/*** Makes the preview as tall as the page it shows, so that the page scrolls in `.page-body` together- * with the description above it. `allow-same-origin` lets the popup read the height; the sandbox- * still runs no script.+ * with the description above it. `allow-same-origin` lets the popup read the height, and gives the+ * frame the extension's origin. The sandbox must not get `allow-scripts` too: with both, the clipped+ * page's HTML runs as the extension, with its browser APIs.*/function fitToContent(frame: HTMLIFrameElement) {const height = frame.contentDocument?.documentElement.scrollHeight;diff --git a/apps/web-clipper/entrypoints/popup/popup.spec.tsx b/apps/web-clipper/entrypoints/popup/popup.spec.tsxindex 31ca796c3a..ff375089b6 100644--- a/apps/web-clipper/entrypoints/popup/popup.spec.tsx+++ b/apps/web-clipper/entrypoints/popup/popup.spec.tsx@@ -445,6 +445,19 @@ describe("popup", () => {expect(container.querySelector(".page-body .note-text")).not.toBeNull();});+ it("never lets a preview run scripts, since it shares the extension's origin", async () => {+ selection = SELECTION;+ await rerender();+ for (const mode of [ "Selection", "Page" ]) {+ await click(mode);+ const frame = container.querySelector(".page-body iframe.page-content");+ expect(frame, mode).not.toBeNull();+ const sandbox = frame?.getAttribute("sandbox")?.split(/\s+/);+ expect(sandbox, mode).toContain("allow-same-origin");+ expect(sandbox, mode).not.toContain("allow-scripts");+ }+ });+it("sizes the preview to the page, so that it scrolls with the description", async () => {const frame = container.querySelector<HTMLIFrameElement>(".page-body iframe.page-content");expect(frame).not.toBeNull();