@marimo-team/islands 0.26.1-dev84 → 0.26.1-dev87

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 (28) hide show
  1. package/dist/{ConnectedDataExplorerComponent-CO9uVewH.js → ConnectedDataExplorerComponent-BJBdnd0O.js} +9 -9
  2. package/dist/{ErrorBoundary-T8CwNebX.js → ErrorBoundary-BMasZGdI.js} +1 -1
  3. package/dist/{chat-ui-CjZbdpzb.js → chat-ui-BbJTFtyC.js} +524 -523
  4. package/dist/circle-question-mark-evCnVIut.js +19 -0
  5. package/dist/{code-visibility-BBgRhs2A.js → code-visibility-D06PC-M7.js} +5 -5
  6. package/dist/{common-BF30ifb8.js → common-WyRloDp8.js} +656 -655
  7. package/dist/{data-grid-overlay-editor-ChntsIBb.js → data-grid-overlay-editor-CmhsmW5x.js} +1 -1
  8. package/dist/{error-entries-CsXAdy1j.js → error-entries-DhZotdzQ.js} +2 -1
  9. package/dist/{config-CShkLThS.js → export-context-CkgZeARR.js} +80 -70
  10. package/dist/{feedback-button-nmOvfn22.js → feedback-button-KXwLqov4.js} +3 -3
  11. package/dist/{formats-BRDSQgKN.js → formats-CcQrzFo8.js} +2 -2
  12. package/dist/{glide-data-editor-SkR9hqZZ.js → glide-data-editor-BZp6FNlk.js} +3 -3
  13. package/dist/{globals-BjiU5aEs.js → globals-_1nZnPj9.js} +1 -1
  14. package/dist/{html-to-image-CwpapHNl.js → html-to-image-B8erjaaD.js} +3890 -3913
  15. package/dist/{loader-qPmiRXZd.js → loader-CGrYn73j.js} +421 -373
  16. package/dist/main.js +6443 -6453
  17. package/dist/{number-overlay-editor-GjrMTG9X.js → number-overlay-editor-BXbQC-jN.js} +1 -1
  18. package/dist/{process-output-ztSj9cDn.js → process-output-C-2_O5Ry.js} +2 -2
  19. package/dist/{reveal-component-BrZbx6s7.js → reveal-component-BQdJlYyE.js} +3 -3
  20. package/dist/{static-state-DhVFm8Z6.js → static-state-iw0PrHK4.js} +22 -33
  21. package/dist/toDate-BZg-byuO.js +13 -0
  22. package/dist/{vega-component-BxJFcD2G.js → vega-component-BzNDFvQf.js} +207 -203
  23. package/package.json +1 -1
  24. package/src/plugins/core/__test__/trusted-url.test.ts +53 -1
  25. package/src/plugins/core/trusted-url.ts +59 -1
  26. package/src/plugins/impl/vega/__tests__/resolve-data.test.ts +147 -2
  27. package/src/plugins/impl/vega/loader.ts +49 -2
  28. package/src/plugins/impl/vega/vega-component.tsx +3 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marimo-team/islands",
3
- "version": "0.26.1-dev84",
3
+ "version": "0.26.1-dev87",
4
4
  "main": "dist/main.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -5,7 +5,10 @@ import { userConfigAtom } from "@/core/config/config";
5
5
  import { parseUserConfig } from "@/core/config/config-schema";
6
6
  import { initialModeAtom } from "@/core/mode";
7
7
  import { store } from "@/core/state/jotai";
8
- import { isTrustedVirtualFileUrl } from "../trusted-url";
8
+ import {
9
+ isTrustedVirtualFileUrl,
10
+ resolveTrustedDataFetchUrl,
11
+ } from "../trusted-url";
9
12
 
10
13
  type ExportContextWindow = Window & {
11
14
  __MARIMO_EXPORT_CONTEXT__?: {
@@ -202,3 +205,52 @@ describe("isTrustedVirtualFileUrl", () => {
202
205
  });
203
206
  });
204
207
  });
208
+
209
+ describe("resolveTrustedDataFetchUrl", () => {
210
+ let trustStateSnapshot: ReturnType<typeof snapshotTrustState>;
211
+
212
+ beforeEach(() => {
213
+ trustStateSnapshot = snapshotTrustState();
214
+ clearTrustSignals();
215
+ });
216
+
217
+ afterEach(() => {
218
+ restoreTrustState(trustStateSnapshot);
219
+ });
220
+
221
+ it.each([
222
+ "./@file/123-data.csv",
223
+ "@file/123-data.arrow",
224
+ `${window.location.origin}/@file/123-data.json`,
225
+ "https://cdn.jsdelivr.net/npm/vega-datasets@2/data/cars.json",
226
+ "data:text/csv;base64,YQox",
227
+ ])("accepts %s before the notebook is trusted", (url) => {
228
+ expect(resolveTrustedDataFetchUrl(url)).toBe(
229
+ new URL(url, document.baseURI).href,
230
+ );
231
+ });
232
+
233
+ it.each([
234
+ "/api/files/download?path=/etc/passwd",
235
+ "api/files/download?path=/etc/passwd",
236
+ `${window.location.origin}/api/files/download?path=/etc/passwd`,
237
+ "./@file/../api/files/download?path=/etc/passwd",
238
+ "./@file/%2e%2e/api/files/download?path=/etc/passwd",
239
+ "data.csv",
240
+ "file:///etc/passwd",
241
+ // `fetch` resolves these against the page, so they reach the server
242
+ "http:/api/files/download?path=/etc/passwd",
243
+ "http:api/files/download?path=/etc/passwd",
244
+ "HTTP:/api/files/download?path=/etc/passwd",
245
+ `//${window.location.host}/api/files/download?path=/etc/passwd`,
246
+ ])("rejects %s before the notebook is trusted", (url) => {
247
+ expect(resolveTrustedDataFetchUrl(url)).toBeNull();
248
+ });
249
+
250
+ it("returns same-origin URLs unchanged once the user has run a cell", () => {
251
+ store.set(hasRunAnyCellAtom, true);
252
+ expect(resolveTrustedDataFetchUrl("public/data.csv")).toBe(
253
+ "public/data.csv",
254
+ );
255
+ });
256
+ });
@@ -1,7 +1,11 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import { hasRunAnyCellAtom } from "@/components/editor/cell/useRunCells";
4
- import { hasTrustedExportContext } from "@/core/static/export-context";
4
+ import { getRuntimeManager } from "@/core/runtime/config";
5
+ import {
6
+ hasTrustedExportContext,
7
+ hasTrustedNotebookContext,
8
+ } from "@/core/static/export-context";
5
9
  import { store } from "@/core/state/jotai";
6
10
 
7
11
  /**
@@ -37,6 +41,60 @@ export function isTrustedVirtualFileUrl(url: unknown): url is string {
37
41
  return false;
38
42
  }
39
43
 
44
+ /**
45
+ * The URL a plugin may fetch data (e.g. a Vega `data.url`) from, or `null` if
46
+ * it may not. Callers must fetch the returned URL, not the original string.
47
+ *
48
+ * Before the notebook is trusted, outputs on screen may come from a session
49
+ * cache, and the HTML sanitizer lets `<marimo-*>` elements through, so their
50
+ * URLs are untrusted. A same-origin URL could read marimo's authenticated API
51
+ * (e.g. `/api/files/download`), so until then the only marimo server URLs
52
+ * allowed are virtual files. Other origins and inline `data:`/`blob:` URLs
53
+ * cannot reach the server. The check compares origins, so loopback aliases of
54
+ * the server (`127.0.0.1` vs `localhost`, `[::1]`) count as other origins;
55
+ * the browser sends no cookies with those requests, so they are
56
+ * unauthenticated.
57
+ *
58
+ * Before trust, the result is the absolute `href` of `url` resolved against
59
+ * the runtime URL, so the URL that is checked is the URL that is fetched
60
+ * (e.g. `http:/api/...` resolves against the server, not to host `api`).
61
+ */
62
+ export function resolveTrustedDataFetchUrl(url: string): string | null {
63
+ if (hasTrustedNotebookContext()) {
64
+ return url;
65
+ }
66
+ let resolved: URL;
67
+ try {
68
+ resolved = resolveAgainstRuntime(url);
69
+ } catch {
70
+ return null;
71
+ }
72
+ if (resolved.protocol === "data:" || resolved.protocol === "blob:") {
73
+ return resolved.href;
74
+ }
75
+ if (resolved.protocol !== "http:" && resolved.protocol !== "https:") {
76
+ return null;
77
+ }
78
+ const virtualFileRoot = resolveAgainstRuntime("./@file/");
79
+ if (resolved.origin === virtualFileRoot.origin) {
80
+ return resolved.pathname.startsWith(virtualFileRoot.pathname)
81
+ ? resolved.href
82
+ : null;
83
+ }
84
+ return resolved.origin === window.location.origin ? null : resolved.href;
85
+ }
86
+
87
+ /**
88
+ * Unlike `asRemoteURL`, always resolves with the runtime URL as the base, the
89
+ * way `fetch` resolves with the page URL as the base.
90
+ */
91
+ function resolveAgainstRuntime(url: string): URL {
92
+ const base = getRuntimeManager()
93
+ .httpURL.toString()
94
+ .replace(/^blob:/, "");
95
+ return new URL(url, base);
96
+ }
97
+
40
98
  /**
41
99
  * Intentionally narrower than `hasTrustedNotebookContext` in
42
100
  * `@/core/static/export-context`: `auto_instantiate` and `read` mode are
@@ -1,6 +1,11 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
- import { afterEach, describe, expect, it, vi } from "vitest";
3
- import { vegaLoader } from "../loader";
2
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { hasRunAnyCellAtom } from "@/components/editor/cell/useRunCells";
4
+ import { userConfigAtom } from "@/core/config/config";
5
+ import { parseUserConfig } from "@/core/config/config-schema";
6
+ import { initialModeAtom } from "@/core/mode";
7
+ import { store } from "@/core/state/jotai";
8
+ import { createEmbedLoader, vegaLoadData, vegaLoader } from "../loader";
4
9
  import { resolveVegaSpecData } from "../resolve-data";
5
10
  import type { VegaLiteSpec } from "../types";
6
11
 
@@ -234,3 +239,143 @@ describe("resolveVegaSpecData", () => {
234
239
  expect(result).not.toHaveProperty("datasets");
235
240
  });
236
241
  });
242
+
243
+ describe("data URLs before the notebook is trusted", () => {
244
+ const download = "/api/files/download?path=/etc/passwd";
245
+ const snapshotTrustState = () => ({
246
+ userConfig: store.get(userConfigAtom),
247
+ hasRunAnyCell: store.get(hasRunAnyCellAtom),
248
+ initialMode: store.get(initialModeAtom),
249
+ });
250
+ let snapshot: ReturnType<typeof snapshotTrustState>;
251
+
252
+ beforeEach(() => {
253
+ snapshot = snapshotTrustState();
254
+ const config = parseUserConfig({});
255
+ store.set(userConfigAtom, {
256
+ ...config,
257
+ runtime: { ...config.runtime, auto_instantiate: false },
258
+ });
259
+ store.set(hasRunAnyCellAtom, false);
260
+ store.set(initialModeAtom, "edit");
261
+ });
262
+
263
+ afterEach(() => {
264
+ store.set(userConfigAtom, snapshot.userConfig);
265
+ store.set(hasRunAnyCellAtom, snapshot.hasRunAnyCell);
266
+ store.set(initialModeAtom, snapshot.initialMode);
267
+ vi.resetAllMocks();
268
+ });
269
+
270
+ it.each([download, `${window.location.origin}${download}`])(
271
+ "refuses to load %s",
272
+ async (url) => {
273
+ const load = vi.spyOn(vegaLoader, "load");
274
+ await expect(
275
+ resolveVegaSpecData(asSpec({ data: { url, format: { type: "csv" } } })),
276
+ ).rejects.toThrow("Run the notebook to load data");
277
+ expect(load).not.toHaveBeenCalled();
278
+ },
279
+ );
280
+
281
+ it.each([
282
+ "./@file/123-data.csv",
283
+ "https://cdn.jsdelivr.net/npm/vega-datasets@2/data/cars.csv",
284
+ ])("loads %s", async (url) => {
285
+ const load = vi.spyOn(vegaLoader, "load").mockResolvedValue("a\n1");
286
+ const result = await resolveVegaSpecData(
287
+ asSpec({ data: { url, format: { type: "csv" } } }),
288
+ );
289
+ expect(load).toHaveBeenCalledOnce();
290
+ expect(Object.values(result.datasets ?? {})).toEqual([[{ a: 1 }]]);
291
+ });
292
+
293
+ // `fetch` resolves these against the page, so they reach the server
294
+ const serverUrls = [
295
+ download,
296
+ "http:/api/files/download?path=/etc/passwd",
297
+ "http:api/files/download?path=/etc/passwd",
298
+ "HTTP:/api/files/download?path=/etc/passwd",
299
+ `//${window.location.host}/api/files/download?path=/etc/passwd`,
300
+ ];
301
+ const virtualFile = "./@file/123-data.csv";
302
+ const virtualFileHref = new URL(virtualFile, document.baseURI).href;
303
+ const dataflow = { context: "dataflow", response: "csv" } as const;
304
+
305
+ it.each(serverUrls)("vegaLoadData refuses %s", async (url) => {
306
+ const load = vi.spyOn(vegaLoader, "load");
307
+ const fetch = vi.spyOn(globalThis, "fetch");
308
+ await expect(vegaLoadData(url, { type: "csv" })).rejects.toThrow(
309
+ "Run the notebook to load data",
310
+ );
311
+ await expect(vegaLoadData(url, { type: "arrow" })).rejects.toThrow(
312
+ "Run the notebook to load data",
313
+ );
314
+ expect(load).not.toHaveBeenCalled();
315
+ expect(fetch).not.toHaveBeenCalled();
316
+ });
317
+
318
+ it("vegaLoadData fetches the URL it checked", async () => {
319
+ const load = vi.spyOn(vegaLoader, "load").mockResolvedValue("a\n1");
320
+ await expect(vegaLoadData(virtualFile, { type: "csv" })).resolves.toEqual([
321
+ { a: 1 },
322
+ ]);
323
+ expect(load).toHaveBeenCalledWith(virtualFileHref);
324
+
325
+ const fetch = vi
326
+ .spyOn(globalThis, "fetch")
327
+ .mockRejectedValue(new Error("offline"));
328
+ const arrowFile = "./@file/123-data.arrow";
329
+ await expect(vegaLoadData(arrowFile, { type: "arrow" })).rejects.toThrow(
330
+ "offline",
331
+ );
332
+ expect(fetch).toHaveBeenCalledWith(
333
+ new URL(arrowFile, document.baseURI).href,
334
+ );
335
+ });
336
+
337
+ it.each(serverUrls)("the embed loader refuses %s", async (url) => {
338
+ const embedLoader = createEmbedLoader({});
339
+ const http = vi.spyOn(embedLoader, "http").mockResolvedValue("a\n1");
340
+ const file = vi.spyOn(embedLoader, "file").mockResolvedValue("a\n1");
341
+
342
+ await expect(embedLoader.load(url)).rejects.toThrow(
343
+ "Run the notebook to load data",
344
+ );
345
+ expect(http).not.toHaveBeenCalled();
346
+ expect(file).not.toHaveBeenCalled();
347
+ });
348
+
349
+ // Vega fetches the `href` that `sanitize` returns
350
+ it("the embed loader returns the URL it checked", async () => {
351
+ const embedLoader = createEmbedLoader({});
352
+ await expect(
353
+ embedLoader.sanitize(virtualFile, dataflow),
354
+ ).resolves.toMatchObject({
355
+ href: virtualFileHref,
356
+ });
357
+ });
358
+
359
+ it("the embed loader keeps the chart's loader options", async () => {
360
+ const embedLoader = createEmbedLoader({
361
+ usermeta: {
362
+ embedOptions: { loader: { baseURL: "https://example.com/data/" } },
363
+ },
364
+ });
365
+ await expect(
366
+ embedLoader.sanitize("cars.csv", dataflow),
367
+ ).resolves.toMatchObject({
368
+ href: "https://example.com/data/cars.csv",
369
+ });
370
+ });
371
+
372
+ it("the embed loader leaves link URLs to Vega", async () => {
373
+ const embedLoader = createEmbedLoader({});
374
+ await expect(
375
+ embedLoader.sanitize("#details", { context: "href" }),
376
+ ).resolves.toMatchObject({ href: "#details" });
377
+ await expect(embedLoader.sanitize(download, dataflow)).rejects.toThrow(
378
+ "Run the notebook to load data",
379
+ );
380
+ });
381
+ });
@@ -1,6 +1,10 @@
1
1
  /* Copyright 2026 Marimo. All rights reserved. */
2
2
 
3
3
  import { tableFromIPC } from "@uwdata/flechette";
4
+ import type { Loader as VegaLoader } from "vega";
5
+ // @ts-expect-error vega-loader has no types
6
+ import { loader as createVegaLoader } from "vega-loader";
7
+ import { resolveTrustedDataFetchUrl } from "@/plugins/core/trusted-url";
4
8
  import { Logger } from "@/utils/Logger";
5
9
  import { Objects } from "@/utils/objects";
6
10
  import { batchedArrowLoader, createBatchedLoader } from "./batched";
@@ -145,6 +149,48 @@ typeParsers.boolean = customBooleanParser;
145
149
 
146
150
  export const vegaLoader = createBatchedLoader();
147
151
 
152
+ function trustedDataUrl(url: string): string {
153
+ const href = resolveTrustedDataFetchUrl(url);
154
+ if (href === null) {
155
+ throw new Error(`Run the notebook to load data from ${url}`);
156
+ }
157
+ return href;
158
+ }
159
+
160
+ /**
161
+ * Vega fetches some URLs itself (e.g. lookup transforms, Vega specs, image
162
+ * marks), so its loader must apply the same check as `vegaLoadData`.
163
+ * Link URLs (`context: "href"`) are navigated to, not fetched, so they are
164
+ * left to the wrapped loader.
165
+ */
166
+ function withTrustedDataUrls(loader: VegaLoader): VegaLoader {
167
+ return {
168
+ ...loader,
169
+ async sanitize(uri, options) {
170
+ const result = await loader.sanitize(uri, options);
171
+ if (options?.context !== "href") {
172
+ result.href = trustedDataUrl(result.href);
173
+ }
174
+ return result;
175
+ },
176
+ };
177
+ }
178
+
179
+ /**
180
+ * The loader for vega-embed. vega-embed ignores the spec's
181
+ * `usermeta.embedOptions.loader` options when it is given a loader, so the
182
+ * loader is built from those options.
183
+ */
184
+ export function createEmbedLoader(spec: { usermeta?: unknown }): VegaLoader {
185
+ const usermeta = spec.usermeta as
186
+ | { embedOptions?: { loader?: unknown } }
187
+ | undefined;
188
+ const options = usermeta?.embedOptions?.loader;
189
+ return withTrustedDataUrls(
190
+ createVegaLoader(typeof options === "object" ? options : undefined),
191
+ );
192
+ }
193
+
148
194
  /**
149
195
  * Load data from a URL and parse it according to the given format.
150
196
  *
@@ -165,10 +211,11 @@ export async function vegaLoadData<T = object>(
165
211
  } = {},
166
212
  ): Promise<T[]> {
167
213
  const { handleBigIntAndNumberLike = false, replacePeriod = false } = opts;
214
+ const href = trustedDataUrl(url);
168
215
 
169
216
  // Handle arrow data
170
217
  if (url.endsWith(".arrow") || format?.type === "arrow") {
171
- const arrow = await batchedArrowLoader(url);
218
+ const arrow = await batchedArrowLoader(href);
172
219
  return tableFromIPC(arrow, {
173
220
  useProxy: true,
174
221
  useDate: true,
@@ -187,7 +234,7 @@ export async function vegaLoadData<T = object>(
187
234
 
188
235
  // Load the data
189
236
  try {
190
- let csvOrJsonData = await vegaLoader.load(url);
237
+ let csvOrJsonData = await vegaLoader.load(href);
191
238
  if (!format) {
192
239
  // Infer by trying to parse
193
240
  if (typeof csvOrJsonData === "string") {
@@ -24,6 +24,7 @@ import { Objects } from "@/utils/objects";
24
24
  import { ErrorBanner } from "../common/error-banner";
25
25
  import { fixRelativeUrl } from "./fix-relative-url";
26
26
  import { arrow } from "./formats";
27
+ import { createEmbedLoader } from "./loader";
27
28
  import { makeSelectable } from "./make-selectable";
28
29
  import { getSelectionParamNames, ParamNames } from "./params";
29
30
  import { resolveVegaSpecData } from "./resolve-data";
@@ -138,6 +139,7 @@ const LoadedVegaComponent = ({
138
139
  fieldSelection,
139
140
  });
140
141
  }, [specMemo, chartSelection, fieldSelection]);
142
+ const embedLoader = useMemo(() => createEmbedLoader(specMemo), [specMemo]);
141
143
  const names = useMemo(
142
144
  () => getSelectionParamNames(selectableSpec),
143
145
  [selectableSpec],
@@ -277,6 +279,7 @@ const LoadedVegaComponent = ({
277
279
  mode: "vega-lite",
278
280
  tooltip: tooltipHandler.call,
279
281
  renderer: "canvas",
282
+ loader: embedLoader,
280
283
  },
281
284
  onError: handleError,
282
285
  onEmbed: handleNewView,