@marimo-team/islands 0.23.1-dev21 → 0.23.1-dev23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/{ConnectedDataExplorerComponent-Eq8bCe49.js → ConnectedDataExplorerComponent-P92i6wYx.js} +148 -148
  2. package/dist/{ImageComparisonComponent-DY3J_vIU.js → ImageComparisonComponent-HF4AY8_n.js} +2 -2
  3. package/dist/{Plot-BxlSHo0G.js → Plot-CK0oVgQL.js} +2 -2
  4. package/dist/{any-language-editor-BF8ew8wu.js → any-language-editor-BCvLfvzI.js} +7 -7
  5. package/dist/{button-Cn59RsBF.js → button-D1C3g5GI.js} +72 -71
  6. package/dist/{capabilities-Bml77Di-.js → capabilities-BwpUgo4S.js} +1 -1
  7. package/dist/{chat-ui-BdrC6z8t.js → chat-ui-CNHw9Osh.js} +2829 -2829
  8. package/dist/{check-C51PA02v.js → check-BgrdTLuv.js} +1 -1
  9. package/dist/{chunk-5FQGJX7Z-C428iZBW.js → chunk-5FQGJX7Z-VIref9gx.js} +4 -4
  10. package/dist/{click-outside-container-vCXhHl-R.js → click-outside-container-D3t6KDni.js} +1 -1
  11. package/dist/{code-block-37QAKDTI-D9EnJeBI.js → code-block-37QAKDTI-FQEoMOU1.js} +2 -2
  12. package/dist/{compiler-runtime-B_OLMU9S.js → compiler-runtime-CEbnTgxf.js} +1 -1
  13. package/dist/{copy-DzOz_Au7.js → copy-Bp6CK_Fg.js} +9 -9
  14. package/dist/{data-grid-overlay-editor-lKF301ME.js → data-grid-overlay-editor-C_sKPpLu.js} +4 -4
  15. package/dist/{dist-CjLQ79mo.js → dist-CTtLBPLZ.js} +11 -11
  16. package/dist/{dist-BoNJsA65.js → dist-DUFd1bhm.js} +1 -1
  17. package/dist/{error-banner-BQcJXy6k.js → error-banner-B_ioHva3.js} +121 -121
  18. package/dist/{esm-BmYNigxi.js → esm-CDHI9cuO.js} +15 -15
  19. package/dist/{glide-data-editor-D2X4D_xi.js → glide-data-editor-BFqEJGJW.js} +948 -948
  20. package/dist/{input-BRN2Mjzx.js → input-CSVEkmaZ.js} +288 -288
  21. package/dist/{label-J1N4mVcg.js → label-BebYlsDV.js} +257 -257
  22. package/dist/{loader-JmfPBSx5.js → loader-ZFbGsMN1.js} +15 -15
  23. package/dist/main.js +7114 -6962
  24. package/dist/mermaid-4DMBBIKO-BjtqcdX4.js +6 -0
  25. package/dist/{mermaid-UMKVHs_g.js → mermaid-BbhZNQeB.js} +18 -18
  26. package/dist/{number-overlay-editor-DxLoVuuE.js → number-overlay-editor-B02-t7Ar.js} +2 -2
  27. package/dist/{process-output-D3Q6xBZJ.js → process-output-Bekznt_B.js} +863 -863
  28. package/dist/{react-dom-BSUuJjCR.js → react-dom-D5FDLRUB.js} +1 -1
  29. package/dist/{react-vega-DayQmZjG.js → react-vega-BkjdpVsR.js} +2 -2
  30. package/dist/{react-vega-CzRAIHrv.js → react-vega-DBwal82H.js} +1 -1
  31. package/dist/{slides-component-_3tukGh-.js → slides-component-DLxprlqo.js} +26 -26
  32. package/dist/{spec-rP6otrXw.js → spec-3EPbPQZH.js} +4 -4
  33. package/dist/style.css +1 -1
  34. package/dist/{toDate-CfGr2xZ1.js → toDate-B1AzlBoW.js} +15 -15
  35. package/dist/{tooltip-BusGYw7Q.js → tooltip-DwNnFsxZ.js} +132 -132
  36. package/dist/{types-D4CFUmPq.js → types-pwjdK009.js} +15 -15
  37. package/dist/{useAsyncData-BzS3Ai32.js → useAsyncData-BL98MPIy.js} +3 -3
  38. package/dist/{useDeepCompareMemoize-AjORjhpL.js → useDeepCompareMemoize-CsyOnnjc.js} +25 -25
  39. package/dist/{useIframeCapabilities---aRgGdv.js → useIframeCapabilities-CsTUYYj7.js} +3 -3
  40. package/dist/{useLifecycle-B90lJH4p.js → useLifecycle-DrGGIsgp.js} +36 -36
  41. package/dist/{useTheme-ytmywQ5O.js → useTheme-CzwDokKe.js} +4 -4
  42. package/dist/{vega-component-C3akWtJ1.js → vega-component-KBJXEDZz.js} +42 -42
  43. package/dist/{zod-D4UoCYGu.js → zod-W5ZEjzaE.js} +23 -23
  44. package/package.json +4 -4
  45. package/src/core/islands/__tests__/bridge.test.ts +2 -12
  46. package/src/core/islands/__tests__/islands-harness.test.ts +348 -0
  47. package/src/core/islands/__tests__/parse.test.ts +466 -24
  48. package/src/core/islands/__tests__/test-utils.tsx +263 -0
  49. package/src/core/islands/bootstrap.ts +265 -0
  50. package/src/core/islands/bridge.ts +154 -75
  51. package/src/core/islands/components/IslandControls.tsx +103 -0
  52. package/src/core/islands/components/__tests__/IslandControls.test.tsx +185 -0
  53. package/src/core/islands/components/__tests__/useIslandControls.test.ts +208 -0
  54. package/src/core/islands/components/output-wrapper.tsx +76 -93
  55. package/src/core/islands/components/useIslandControls.ts +60 -0
  56. package/src/core/islands/components/web-components.tsx +168 -40
  57. package/src/core/islands/constants.ts +28 -0
  58. package/src/core/islands/main.ts +7 -205
  59. package/src/core/islands/parse.ts +73 -26
  60. package/src/core/islands/worker-factory.ts +86 -0
  61. package/src/plugins/core/__test__/trusted-url.test.ts +48 -0
  62. package/src/plugins/core/trusted-url.ts +20 -0
  63. package/src/plugins/impl/DataTablePlugin.tsx +7 -3
  64. package/src/plugins/impl/anywidget/__tests__/widget-binding.test.ts +27 -1
  65. package/src/plugins/impl/anywidget/widget-binding.ts +13 -0
  66. package/src/plugins/impl/mpl-interactive/MplInteractivePlugin.tsx +21 -0
  67. package/src/plugins/impl/mpl-interactive/__tests__/MplInteractivePlugin.test.tsx +119 -0
  68. package/src/plugins/impl/panel/PanelPlugin.tsx +31 -10
  69. package/src/plugins/impl/panel/__tests__/PanelPlugin.test.ts +60 -0
  70. package/dist/mermaid-4DMBBIKO-Cw46o6DN.js +0 -6
  71. /package/dist/{clsx-yW_RAw0K.js → clsx-CwTY0BxM.js} +0 -0
  72. /package/dist/{react-Bs6Z0kvn.js → react-DA-nE2FX.js} +0 -0
@@ -0,0 +1,86 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { getMarimoVersion } from "../meta/globals";
4
+ import workerUrl from "./worker/worker.tsx?worker&url";
5
+
6
+ /**
7
+ * Interface for creating Web Workers for islands
8
+ */
9
+ export interface WorkerFactory {
10
+ /**
11
+ * Creates a new worker instance
12
+ */
13
+ create(): Worker;
14
+ }
15
+
16
+ /**
17
+ * Configuration for the default worker factory
18
+ */
19
+ export interface DefaultWorkerFactoryConfig {
20
+ /**
21
+ * The URL to the worker script
22
+ * Defaults to the bundled worker
23
+ */
24
+ workerUrl?: string;
25
+
26
+ /**
27
+ * The name to give the worker (shows in DevTools)
28
+ * Defaults to the marimo version
29
+ */
30
+ workerName?: string;
31
+ }
32
+
33
+ /**
34
+ * Default implementation of WorkerFactory that creates Pyodide workers
35
+ * for islands mode.
36
+ */
37
+ export class DefaultWorkerFactory implements WorkerFactory {
38
+ private readonly url: string;
39
+ private readonly name: string;
40
+
41
+ constructor(config: DefaultWorkerFactoryConfig = {}) {
42
+ this.url = config.workerUrl || this.getDefaultWorkerUrl();
43
+ this.name = config.workerName || getMarimoVersion();
44
+ }
45
+
46
+ /**
47
+ * Creates a new Pyodide worker
48
+ */
49
+ create(): Worker {
50
+ const js = `import ${JSON.stringify(new URL(this.url, import.meta.url))}`;
51
+ const blob = new Blob([js], { type: "application/javascript" });
52
+ const objURL = URL.createObjectURL(blob);
53
+
54
+ const worker = new Worker(objURL, {
55
+ type: "module",
56
+ /* @vite-ignore */
57
+ name: this.name,
58
+ });
59
+
60
+ // Blob URL can be revoked once the worker has loaded the script
61
+ URL.revokeObjectURL(objURL);
62
+
63
+ return worker;
64
+ }
65
+
66
+ /**
67
+ * Gets the default worker URL based on environment
68
+ */
69
+ private getDefaultWorkerUrl(): string {
70
+ const url = import.meta.env.DEV
71
+ ? workerUrl
72
+ : makeRelativeWorkerUrl(workerUrl);
73
+ return url;
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Makes worker URLs relative for production builds
79
+ */
80
+ function makeRelativeWorkerUrl(url: string): string {
81
+ return url.startsWith("./")
82
+ ? url
83
+ : url.startsWith("/")
84
+ ? `.${url}`
85
+ : `./${url}`;
86
+ }
@@ -0,0 +1,48 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import { describe, expect, it } from "vitest";
3
+ import { isTrustedVirtualFileUrl } from "../trusted-url";
4
+
5
+ describe("isTrustedVirtualFileUrl", () => {
6
+ it.each([
7
+ "./@file/123-mpl.js",
8
+ "./@file/456-mpl.css",
9
+ "@file/789-bokeh.js",
10
+ "/@file/0-empty.txt",
11
+ "./@file/1234-name.with.dots.js",
12
+ ])("accepts virtual file path %s", (url) => {
13
+ expect(isTrustedVirtualFileUrl(url)).toBe(true);
14
+ });
15
+
16
+ it.each([
17
+ // Attack vector from the vulnerability report
18
+ "http://127.0.0.1:8820/poc.js",
19
+ "https://evil.example.com/x.js",
20
+ // Protocol-relative → takes attacker's origin
21
+ "//evil.example.com/x.js",
22
+ // Dangerous schemes
23
+ "javascript:alert(1)",
24
+ "data:text/javascript;base64,YWxlcnQoMSk=",
25
+ "file:///etc/passwd",
26
+ "blob:http://127.0.0.1/abc",
27
+ // Almost-but-not virtual file paths
28
+ "./evil.js",
29
+ "../@file/x.js",
30
+ "./malicious/@file/x.js",
31
+ "@file",
32
+ "@files/x.js",
33
+ // Query/fragment smuggling
34
+ "./@file/x.js?redirect=http://evil.com",
35
+ "./@file/x.js#http://evil.com",
36
+ // Empty and non-string
37
+ "",
38
+ ])("rejects %s", (url) => {
39
+ expect(isTrustedVirtualFileUrl(url)).toBe(false);
40
+ });
41
+
42
+ it("rejects non-string input", () => {
43
+ expect(isTrustedVirtualFileUrl(null)).toBe(false);
44
+ expect(isTrustedVirtualFileUrl(undefined)).toBe(false);
45
+ expect(isTrustedVirtualFileUrl(42)).toBe(false);
46
+ expect(isTrustedVirtualFileUrl({})).toBe(false);
47
+ });
48
+ });
@@ -0,0 +1,20 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ /**
4
+ * Whether a URL can be trusted to point at a marimo-served virtual file.
5
+ *
6
+ * Plugins that load remote scripts or stylesheets (e.g. MplInteractive, Panel)
7
+ * must call this before turning a plugin-supplied URL into a `<script src>` or
8
+ * `<link href>`. The backend always serializes these URLs as virtual file
9
+ * paths of the form `./@file/<byte_length>-<filename>` (see
10
+ * `VirtualFile.create_and_register`). Accepting anything else would let a
11
+ * maliciously crafted `<marimo-*>` element embedded in markdown load
12
+ * attacker-controlled JavaScript at same origin, since the HTML sanitizer
13
+ * lets arbitrary marimo custom elements and attributes through.
14
+ */
15
+ export function isTrustedVirtualFileUrl(url: unknown): url is string {
16
+ if (typeof url !== "string" || url.length === 0) {
17
+ return false;
18
+ }
19
+ return /^(\.?\/)?@file\/[^?#]+$/.test(url);
20
+ }
@@ -68,6 +68,7 @@ import {
68
68
  import { slotsController } from "@/core/slots/slots";
69
69
  import { store } from "@/core/state/jotai";
70
70
  import { isStaticNotebook } from "@/core/static/static-state";
71
+ import { isIslands } from "@/core/islands/utils";
71
72
  import { isInVscodeExtension } from "@/core/vscode/is-in-vscode";
72
73
  import { useAsyncData } from "@/hooks/useAsyncData";
73
74
  import { useDeepCompareMemoize } from "@/hooks/useDeepCompareMemoize";
@@ -1006,6 +1007,7 @@ const DataTableComponent = ({
1006
1007
  const canShowColumnExplorer = showColumnExplorer && !!preview_column;
1007
1008
 
1008
1009
  const isInVscode = isInVscodeExtension();
1010
+ const isIslandsMode = isIslands();
1009
1011
 
1010
1012
  return (
1011
1013
  <>
@@ -1091,13 +1093,15 @@ const DataTableComponent = ({
1091
1093
  onCellSelectionChange={handleCellSelectionChange}
1092
1094
  getRowIds={get_row_ids}
1093
1095
  toggleDisplayHeader={toggleDisplayHeader}
1094
- showChartBuilder={showChartBuilder}
1096
+ showChartBuilder={showChartBuilder && !isIslandsMode}
1095
1097
  isChartBuilderOpen={isChartBuilderOpen}
1096
1098
  showPageSizeSelector={showPageSizeSelector}
1097
- // Hidden in VSCode (for now) because we don't have a panel to show
1099
+ // Hidden in VSCode and islands because there's no panel to show
1098
1100
  // the table explorer.
1099
1101
  showTableExplorer={
1100
- (showRowExplorer || canShowColumnExplorer) && !isInVscode
1102
+ (showRowExplorer || canShowColumnExplorer) &&
1103
+ !isInVscode &&
1104
+ !isIslandsMode
1101
1105
  }
1102
1106
  togglePanel={togglePanel}
1103
1107
  isPanelOpen={isPanelOpen}
@@ -59,13 +59,39 @@ describe("WidgetDefRegistry", () => {
59
59
 
60
60
  it("should remove from cache on import failure so retry creates new promise", async () => {
61
61
  const promise1 = registry.getModule("http://localhost/a.js", "fail-hash");
62
- // The import will fail in Node (http: scheme not supported)
62
+ // The URL is rejected by the trusted-URL validator.
63
63
  await expect(promise1).rejects.toThrow();
64
64
  // After failure, cache should be cleared, so next call creates a new promise
65
65
  const promise2 = registry.getModule("http://localhost/a.js", "fail-hash");
66
66
  expect(promise1).not.toBe(promise2);
67
67
  promise2.catch(() => undefined);
68
68
  });
69
+
70
+ describe("URL validation", () => {
71
+ it.each([
72
+ // Attack vector: raw <marimo-anywidget data-js-url=...> in markdown
73
+ "http://127.0.0.1:8820/poc.mjs",
74
+ "https://evil.example.com/widget.mjs",
75
+ "//evil.example.com/widget.mjs",
76
+ "javascript:alert(1)",
77
+ "data:text/javascript;base64,YWxlcnQoMSk=",
78
+ "./@file/x.js?redirect=http://evil.com",
79
+ "",
80
+ ])("rejects untrusted URL: %s", async (url) => {
81
+ await expect(registry.getModule(url, `hash-${url}`)).rejects.toThrow(
82
+ /untrusted/i,
83
+ );
84
+ });
85
+
86
+ it("accepts virtual file paths (fails later at import time)", async () => {
87
+ // The URL passes validation but the import still fails because this
88
+ // is a Node test environment with no server. We only assert that
89
+ // the rejection reason is NOT the "untrusted URL" refusal.
90
+ await expect(
91
+ registry.getModule("./@file/123-widget.js", "trusted-hash"),
92
+ ).rejects.not.toThrow(/untrusted/i);
93
+ });
94
+ });
69
95
  });
70
96
 
71
97
  describe("WidgetBinding", () => {
@@ -5,6 +5,7 @@ import type { AnyWidget, Experimental } from "@anywidget/types";
5
5
  import { asRemoteURL } from "@/core/runtime/config";
6
6
  import { resolveVirtualFileURL } from "@/core/static/files";
7
7
  import { isStaticNotebook } from "@/core/static/static-state";
8
+ import { isTrustedVirtualFileUrl } from "@/plugins/core/trusted-url";
8
9
  import { Logger } from "@/utils/Logger";
9
10
  import type { Model } from "./model";
10
11
  import type { ModelState, WidgetModelId } from "./types";
@@ -80,6 +81,18 @@ class WidgetDefRegistry {
80
81
  }
81
82
 
82
83
  async #doImport(jsUrl: string): Promise<any> {
84
+ // Only trust marimo virtual file paths. Accepting arbitrary URLs
85
+ // would let a raw `<marimo-anywidget data-js-url=...>` element
86
+ // embedded in a markdown cell dynamically import attacker-controlled
87
+ // JavaScript at same origin (the HTML sanitizer allows any marimo-*
88
+ // custom element with any attribute through to the plugin layer).
89
+ if (!isTrustedVirtualFileUrl(jsUrl)) {
90
+ throw new Error(
91
+ `Refusing to load anywidget module from untrusted URL: ${String(
92
+ jsUrl,
93
+ )}`,
94
+ );
95
+ }
83
96
  let url = asRemoteURL(jsUrl).toString();
84
97
  if (isStaticNotebook()) {
85
98
  url = resolveVirtualFileURL(url);
@@ -5,12 +5,14 @@ import { useCallback, useEffect, useRef } from "react";
5
5
  import { z } from "zod";
6
6
  import { useEventListener } from "@/hooks/useEventListener";
7
7
  import { createPlugin } from "@/plugins/core/builder";
8
+ import { isTrustedVirtualFileUrl } from "@/plugins/core/trusted-url";
8
9
  import { MODEL_MANAGER, type Model } from "@/plugins/impl/anywidget/model";
9
10
  import type { ModelState, WidgetModelId } from "@/plugins/impl/anywidget/types";
10
11
  import type { IPluginProps } from "@/plugins/types";
11
12
  import { downloadBlob } from "@/utils/download";
12
13
  import { Logger } from "@/utils/Logger";
13
14
  import { MplCommWebSocket } from "./mpl-websocket-shim";
15
+ import { Functions } from "@/utils/functions";
14
16
 
15
17
  const MPL_SCOPE_CLASS = "mpl-interactive-figure";
16
18
 
@@ -73,6 +75,11 @@ async function ensureMplJs(jsUrl: string): Promise<void> {
73
75
  if (window.mpl) {
74
76
  return;
75
77
  }
78
+ if (!isTrustedVirtualFileUrl(jsUrl)) {
79
+ throw new Error(
80
+ `Refusing to load mpl.js from untrusted URL: ${String(jsUrl)}`,
81
+ );
82
+ }
76
83
  if (mplJsLoading) {
77
84
  return mplJsLoading;
78
85
  }
@@ -148,6 +155,12 @@ function patchToolbarImages(
148
155
  }
149
156
 
150
157
  function injectCss(container: HTMLElement, cssUrl: string): () => void {
158
+ if (!isTrustedVirtualFileUrl(cssUrl)) {
159
+ Logger.error(
160
+ `Refusing to load mpl CSS from untrusted URL: ${String(cssUrl)}`,
161
+ );
162
+ return Functions.NOOP;
163
+ }
151
164
  const link = document.createElement("link");
152
165
  link.rel = "stylesheet";
153
166
  link.href = cssUrl;
@@ -307,3 +320,11 @@ const MplInteractiveSlot = (props: IPluginProps<ModelIdRef, Data>) => {
307
320
  // Must match _MPL_SCOPE in from_mpl_interactive.py
308
321
  return <div ref={containerRef} className={MPL_SCOPE_CLASS} />;
309
322
  };
323
+
324
+ export const visibleForTesting = {
325
+ ensureMplJs,
326
+ injectCss,
327
+ resetMplJsLoading: () => {
328
+ mplJsLoading = null;
329
+ },
330
+ };
@@ -0,0 +1,119 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { Logger } from "@/utils/Logger";
4
+ import { visibleForTesting } from "../MplInteractivePlugin";
5
+
6
+ const { ensureMplJs, injectCss, resetMplJsLoading } = visibleForTesting;
7
+
8
+ describe("MplInteractivePlugin URL validation", () => {
9
+ beforeEach(() => {
10
+ // Reset module-level script-loading state and any stubs.
11
+ delete (window as { mpl?: unknown }).mpl;
12
+ resetMplJsLoading();
13
+ // Remove any scripts the tests added to document.head.
14
+ for (const el of document.head.querySelectorAll(
15
+ "script[data-test-mpl],link[data-test-mpl]",
16
+ )) {
17
+ el.remove();
18
+ }
19
+ });
20
+
21
+ afterEach(() => {
22
+ vi.restoreAllMocks();
23
+ });
24
+
25
+ describe("ensureMplJs", () => {
26
+ it("rejects the PoC attack URL without creating a <script>", async () => {
27
+ const appendSpy = vi.spyOn(document.head, "append");
28
+ await expect(ensureMplJs("http://127.0.0.1:8820/poc.js")).rejects.toThrow(
29
+ /untrusted/i,
30
+ );
31
+ expect(appendSpy).not.toHaveBeenCalled();
32
+ });
33
+
34
+ it.each([
35
+ "https://evil.example.com/x.js",
36
+ "//evil.example.com/x.js",
37
+ "javascript:alert(1)",
38
+ "data:text/javascript;base64,YWxlcnQoMSk=",
39
+ "./@file/x.js?redirect=http://evil.com",
40
+ ])("rejects %s", async (url) => {
41
+ const appendSpy = vi.spyOn(document.head, "append");
42
+ await expect(ensureMplJs(url)).rejects.toThrow(/untrusted/i);
43
+ expect(appendSpy).not.toHaveBeenCalled();
44
+ });
45
+
46
+ it("is a no-op when window.mpl is already present", async () => {
47
+ (window as { mpl?: unknown }).mpl = {};
48
+ const appendSpy = vi.spyOn(document.head, "append");
49
+ // Even a malicious URL should be ignored — short-circuit happens first.
50
+ await expect(
51
+ ensureMplJs("http://evil.example.com/x.js"),
52
+ ).resolves.toBeUndefined();
53
+ expect(appendSpy).not.toHaveBeenCalled();
54
+ });
55
+
56
+ it("creates a <script src> for a trusted virtual file URL", async () => {
57
+ const appendSpy = vi
58
+ .spyOn(document.head, "append")
59
+ .mockImplementation((...nodes) => {
60
+ // Simulate a successful load so ensureMplJs resolves.
61
+ for (const node of nodes) {
62
+ if (node instanceof HTMLScriptElement) {
63
+ queueMicrotask(() => node.onload?.(new Event("load")));
64
+ }
65
+ }
66
+ });
67
+
68
+ await expect(ensureMplJs("./@file/123-mpl.js")).resolves.toBeUndefined();
69
+
70
+ expect(appendSpy).toHaveBeenCalledTimes(1);
71
+ const appended = appendSpy.mock.calls[0][0] as HTMLScriptElement;
72
+ expect(appended.tagName).toBe("SCRIPT");
73
+ expect(appended.src).toContain("@file/123-mpl.js");
74
+ });
75
+ });
76
+
77
+ describe("injectCss", () => {
78
+ it("refuses to append <link> for the PoC attack CSS URL", () => {
79
+ const container = document.createElement("div");
80
+ const loggerSpy = vi.spyOn(Logger, "error").mockImplementation(() => {});
81
+
82
+ const cleanup = injectCss(container, "http://127.0.0.1:8820/x.css");
83
+
84
+ expect(container.querySelector("link")).toBeNull();
85
+ expect(loggerSpy).toHaveBeenCalledWith(
86
+ expect.stringContaining("untrusted"),
87
+ );
88
+ // Cleanup must be safe to call even when nothing was appended.
89
+ expect(() => cleanup()).not.toThrow();
90
+ });
91
+
92
+ it.each([
93
+ "https://evil.example.com/x.css",
94
+ "javascript:alert(1)",
95
+ "data:text/css,body{background:red}",
96
+ ])("refuses to append <link> for %s", (url) => {
97
+ const container = document.createElement("div");
98
+ vi.spyOn(Logger, "error").mockImplementation(() => {});
99
+
100
+ injectCss(container, url);
101
+
102
+ expect(container.querySelector("link")).toBeNull();
103
+ });
104
+
105
+ it("appends a <link> for a trusted virtual file URL", () => {
106
+ const container = document.createElement("div");
107
+
108
+ const cleanup = injectCss(container, "./@file/456-mpl.css");
109
+
110
+ const link = container.querySelector("link");
111
+ expect(link).not.toBeNull();
112
+ expect(link?.rel).toBe("stylesheet");
113
+ expect(link?.getAttribute("href")).toBe("./@file/456-mpl.css");
114
+
115
+ cleanup();
116
+ expect(container.querySelector("link")).toBeNull();
117
+ });
118
+ });
119
+ });
@@ -10,6 +10,7 @@ import {
10
10
  } from "@/hooks/useEventListener";
11
11
  import { createPlugin } from "@/plugins/core/builder";
12
12
  import { rpc } from "@/plugins/core/rpc";
13
+ import { isTrustedVirtualFileUrl } from "@/plugins/core/trusted-url";
13
14
  import type { IPluginProps } from "@/plugins/types";
14
15
  import { Logger } from "@/utils/Logger";
15
16
  import { EventBuffer, extractBuffers, MessageSchema } from "./utils";
@@ -64,7 +65,7 @@ declare global {
64
65
  }
65
66
 
66
67
  interface PanelData {
67
- extension: string | null;
68
+ extensionUrl: string | null;
68
69
  docs_json: Record<string, unknown>;
69
70
  render_json: {
70
71
  roots: Record<string, string>;
@@ -85,7 +86,7 @@ type PluginFunctions = {
85
86
  export const PanelPlugin = createPlugin<T>("marimo-panel")
86
87
  .withData(
87
88
  z.object({
88
- extension: z.string().nullable(),
89
+ extensionUrl: z.string().nullable(),
89
90
  docs_json: z.record(z.string(), z.unknown()),
90
91
  render_json: z
91
92
  .object({
@@ -110,9 +111,34 @@ function isBokehLoaded() {
110
111
  return window.Bokeh != null;
111
112
  }
112
113
 
114
+ /**
115
+ * Append a `<script src>` for the bokeh/panel extension.
116
+ *
117
+ * The URL must be a marimo virtual file path; anything else (e.g. an
118
+ * attacker-controlled URL injected via a raw `<marimo-panel>` element in a
119
+ * markdown cell) is refused.
120
+ */
121
+ export function loadPanelExtension(extensionUrl: string | null): boolean {
122
+ if (!extensionUrl) {
123
+ return false;
124
+ }
125
+ if (!isTrustedVirtualFileUrl(extensionUrl)) {
126
+ Logger.error(
127
+ `Refusing to load Panel extension from untrusted URL: ${String(
128
+ extensionUrl,
129
+ )}`,
130
+ );
131
+ return false;
132
+ }
133
+ const script = document.createElement("script");
134
+ script.src = extensionUrl;
135
+ document.head.append(script);
136
+ return true;
137
+ }
138
+
113
139
  const PanelSlot = (props: Props) => {
114
140
  const { data, functions, host } = props;
115
- const { extension, docs_json: docsJson, render_json: renderJson } = data;
141
+ const { extensionUrl, docs_json: docsJson, render_json: renderJson } = data;
116
142
  const ref = useRef<HTMLDivElement>(null);
117
143
  const rootModelIdRef = useRef<string | null>(null);
118
144
  const receiverRef = useRef<InstanceType<
@@ -173,12 +199,7 @@ const PanelSlot = (props: Props) => {
173
199
  return;
174
200
  }
175
201
 
176
- // Load the extension
177
- if (extension) {
178
- const script = document.createElement("script");
179
- script.innerHTML = extension;
180
- document.head.append(script);
181
- }
202
+ loadPanelExtension(extensionUrl);
182
203
 
183
204
  // Check if Bokeh is loaded every 10ms
184
205
  const checkBokeh = setInterval(() => {
@@ -189,7 +210,7 @@ const PanelSlot = (props: Props) => {
189
210
  }, 10);
190
211
 
191
212
  return () => clearInterval(checkBokeh);
192
- }, [extension, setLoaded]);
213
+ }, [extensionUrl, setLoaded]);
193
214
 
194
215
  // Listen for incoming messages
195
216
  useEventListener(
@@ -0,0 +1,60 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { Logger } from "@/utils/Logger";
4
+ import { loadPanelExtension } from "../PanelPlugin";
5
+
6
+ describe("loadPanelExtension", () => {
7
+ beforeEach(() => {
8
+ for (const el of document.head.querySelectorAll("script")) {
9
+ el.remove();
10
+ }
11
+ });
12
+
13
+ afterEach(() => {
14
+ vi.restoreAllMocks();
15
+ });
16
+
17
+ it("does nothing and returns false for null URL", () => {
18
+ const appendSpy = vi.spyOn(document.head, "append");
19
+ expect(loadPanelExtension(null)).toBe(false);
20
+ expect(appendSpy).not.toHaveBeenCalled();
21
+ });
22
+
23
+ it("refuses to load the PoC attack URL", () => {
24
+ const appendSpy = vi.spyOn(document.head, "append");
25
+ const loggerSpy = vi.spyOn(Logger, "error").mockImplementation(() => {});
26
+
27
+ expect(loadPanelExtension("http://127.0.0.1:8820/poc.js")).toBe(false);
28
+
29
+ expect(appendSpy).not.toHaveBeenCalled();
30
+ expect(loggerSpy).toHaveBeenCalledWith(
31
+ expect.stringContaining("untrusted"),
32
+ );
33
+ });
34
+
35
+ it.each([
36
+ "https://evil.example.com/x.js",
37
+ "//evil.example.com/x.js",
38
+ // An attacker embedding inline JS as a data URL — what the old plugin
39
+ // would have executed verbatim via script.innerHTML.
40
+ "data:text/javascript;base64,YWxlcnQoMSk=",
41
+ "javascript:alert(1)",
42
+ "./@file/x.js#http://evil.com",
43
+ ])("refuses to load %s", (url) => {
44
+ const appendSpy = vi.spyOn(document.head, "append");
45
+ vi.spyOn(Logger, "error").mockImplementation(() => {});
46
+
47
+ expect(loadPanelExtension(url)).toBe(false);
48
+ expect(appendSpy).not.toHaveBeenCalled();
49
+ });
50
+
51
+ it("appends a <script src> for a trusted virtual file URL", () => {
52
+ expect(loadPanelExtension("./@file/42-bokeh.js")).toBe(true);
53
+
54
+ const script = document.head.querySelector("script");
55
+ expect(script).not.toBeNull();
56
+ expect(script?.src).toContain("@file/42-bokeh.js");
57
+ // Must NOT populate innerHTML — that was the original vulnerability sink.
58
+ expect(script?.innerHTML).toBe("");
59
+ });
60
+ });
@@ -1,6 +0,0 @@
1
- import "./react-Bs6Z0kvn.js";
2
- import { a as tt } from "./chunk-5FQGJX7Z-C428iZBW.js";
3
- import "./jsx-runtime-9hcJiI23.js";
4
- export {
5
- tt as Mermaid
6
- };
File without changes
File without changes