@marimo-team/islands 0.23.3-dev13 → 0.23.3-dev16
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.
- package/dist/main.js +1131 -1113
- package/dist/{reveal-component-CrnLosc4.js → reveal-component-D5Ma1jUH.js} +1 -1
- package/dist/{slide-Dl7Rf496.js → slide-I_e7XJHS.js} +569 -465
- package/package.json +1 -1
- package/src/components/editor/output/JsonOutput.tsx +157 -4
- package/src/components/editor/output/__tests__/JsonOutput-mimetype.test.tsx +80 -0
- package/src/components/editor/output/__tests__/json-output.test.ts +147 -2
- package/src/core/islands/__tests__/bridge.test.ts +116 -5
- package/src/core/islands/bridge.ts +5 -1
- package/src/core/static/export-context.ts +43 -0
- package/src/plugins/core/__test__/trusted-url.test.ts +130 -18
- package/src/plugins/core/trusted-url.ts +23 -10
- package/src/plugins/impl/anywidget/__tests__/widget-binding.test.ts +29 -1
- package/src/plugins/impl/mpl-interactive/__tests__/MplInteractivePlugin.test.tsx +34 -0
- package/src/plugins/impl/panel/__tests__/PanelPlugin.test.ts +35 -2
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
export interface MarimoExportContext {
|
|
4
|
+
trusted: true;
|
|
5
|
+
notebookCode?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare global {
|
|
9
|
+
interface Window {
|
|
10
|
+
__MARIMO_EXPORT_CONTEXT__?: Readonly<MarimoExportContext>;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function isMarimoExportContext(
|
|
15
|
+
value: unknown,
|
|
16
|
+
): value is Readonly<MarimoExportContext> {
|
|
17
|
+
if (typeof value !== "object" || value === null) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const candidate = value as MarimoExportContext;
|
|
22
|
+
if (candidate.trusted !== true) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (
|
|
26
|
+
candidate.notebookCode !== undefined &&
|
|
27
|
+
typeof candidate.notebookCode !== "string"
|
|
28
|
+
) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getMarimoExportContext():
|
|
35
|
+
| Readonly<MarimoExportContext>
|
|
36
|
+
| undefined {
|
|
37
|
+
const context = window?.__MARIMO_EXPORT_CONTEXT__;
|
|
38
|
+
return isMarimoExportContext(context) ? context : undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function hasTrustedExportContext(): boolean {
|
|
42
|
+
return getMarimoExportContext()?.trusted === true;
|
|
43
|
+
}
|
|
@@ -1,10 +1,66 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
3
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";
|
|
4
7
|
import { store } from "@/core/state/jotai";
|
|
5
8
|
import { isTrustedVirtualFileUrl } from "../trusted-url";
|
|
6
9
|
|
|
10
|
+
type ExportContextWindow = Window & {
|
|
11
|
+
__MARIMO_EXPORT_CONTEXT__?: {
|
|
12
|
+
trusted: true;
|
|
13
|
+
notebookCode?: string;
|
|
14
|
+
};
|
|
15
|
+
__MARIMO_STATIC__?: unknown;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function snapshotTrustState() {
|
|
19
|
+
return {
|
|
20
|
+
hasRunAnyCell: store.get(hasRunAnyCellAtom),
|
|
21
|
+
userConfig: store.get(userConfigAtom),
|
|
22
|
+
initialMode: store.get(initialModeAtom),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function restoreTrustState(snapshot: ReturnType<typeof snapshotTrustState>) {
|
|
27
|
+
store.set(hasRunAnyCellAtom, snapshot.hasRunAnyCell);
|
|
28
|
+
store.set(userConfigAtom, snapshot.userConfig);
|
|
29
|
+
store.set(initialModeAtom, snapshot.initialMode);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function setAutoInstantiate(value: boolean) {
|
|
33
|
+
const cleared = parseUserConfig({});
|
|
34
|
+
store.set(userConfigAtom, {
|
|
35
|
+
...cleared,
|
|
36
|
+
runtime: { ...cleared.runtime, auto_instantiate: value },
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function clearTrustSignals() {
|
|
41
|
+
store.set(hasRunAnyCellAtom, false);
|
|
42
|
+
setAutoInstantiate(false);
|
|
43
|
+
store.set(initialModeAtom, "edit");
|
|
44
|
+
}
|
|
45
|
+
|
|
7
46
|
describe("isTrustedVirtualFileUrl", () => {
|
|
47
|
+
let windowWithExportContext: ExportContextWindow;
|
|
48
|
+
let trustStateSnapshot: ReturnType<typeof snapshotTrustState>;
|
|
49
|
+
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
windowWithExportContext = window as ExportContextWindow;
|
|
52
|
+
trustStateSnapshot = snapshotTrustState();
|
|
53
|
+
clearTrustSignals();
|
|
54
|
+
delete windowWithExportContext.__MARIMO_EXPORT_CONTEXT__;
|
|
55
|
+
delete windowWithExportContext.__MARIMO_STATIC__;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
afterEach(() => {
|
|
59
|
+
restoreTrustState(trustStateSnapshot);
|
|
60
|
+
delete windowWithExportContext.__MARIMO_EXPORT_CONTEXT__;
|
|
61
|
+
delete windowWithExportContext.__MARIMO_STATIC__;
|
|
62
|
+
});
|
|
63
|
+
|
|
8
64
|
it.each([
|
|
9
65
|
"./@file/123-mpl.js",
|
|
10
66
|
"./@file/456-mpl.css",
|
|
@@ -48,40 +104,96 @@ describe("isTrustedVirtualFileUrl", () => {
|
|
|
48
104
|
expect(isTrustedVirtualFileUrl({})).toBe(false);
|
|
49
105
|
});
|
|
50
106
|
|
|
51
|
-
|
|
52
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Data URLs are the WASM / Pyodide fallback shape (see
|
|
109
|
+
* `virtual_file.py`: when `virtual_files_supported=False`, files are
|
|
110
|
+
* emitted directly as base64 data URLs). The tests below cover each
|
|
111
|
+
* supported and unsupported trust signal.
|
|
112
|
+
*/
|
|
113
|
+
describe("data URL acceptance", () => {
|
|
114
|
+
const SAFE_DATA_URLS = [
|
|
115
|
+
"data:text/javascript;base64,ZXhwb3J0IGRlZmF1bHQge30=",
|
|
116
|
+
"data:application/javascript;base64,ZXhwb3J0IGRlZmF1bHQge30=",
|
|
117
|
+
"data:text/css;base64,Ym9keXt9",
|
|
118
|
+
];
|
|
53
119
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
120
|
+
it.each(SAFE_DATA_URLS)(
|
|
121
|
+
"accepts %s once the user has run a cell",
|
|
122
|
+
(url) => {
|
|
123
|
+
store.set(hasRunAnyCellAtom, true);
|
|
124
|
+
expect(isTrustedVirtualFileUrl(url)).toBe(true);
|
|
125
|
+
},
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
it("accepts safe data URL when trusted export context is present", () => {
|
|
129
|
+
windowWithExportContext.__MARIMO_EXPORT_CONTEXT__ = {
|
|
130
|
+
trusted: true,
|
|
131
|
+
notebookCode: "import marimo\napp = marimo.App()",
|
|
132
|
+
};
|
|
133
|
+
expect(
|
|
134
|
+
isTrustedVirtualFileUrl(
|
|
135
|
+
"data:text/javascript;base64,ZXhwb3J0IGRlZmF1bHQge30=",
|
|
136
|
+
),
|
|
137
|
+
).toBe(true);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("rejects safe data URL when only read mode is present", () => {
|
|
141
|
+
store.set(initialModeAtom, "read");
|
|
142
|
+
expect(
|
|
143
|
+
isTrustedVirtualFileUrl(
|
|
144
|
+
"data:text/javascript;base64,ZXhwb3J0IGRlZmF1bHQge30=",
|
|
145
|
+
),
|
|
146
|
+
).toBe(false);
|
|
57
147
|
});
|
|
58
148
|
|
|
59
|
-
|
|
60
|
-
|
|
149
|
+
it("rejects safe data URL when only auto_instantiate is enabled", () => {
|
|
150
|
+
setAutoInstantiate(true);
|
|
151
|
+
expect(
|
|
152
|
+
isTrustedVirtualFileUrl(
|
|
153
|
+
"data:text/javascript;base64,ZXhwb3J0IGRlZmF1bHQge30=",
|
|
154
|
+
),
|
|
155
|
+
).toBe(false);
|
|
61
156
|
});
|
|
62
157
|
|
|
63
|
-
it
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
158
|
+
it("rejects safe data URL when only a marimo-code tag is present", () => {
|
|
159
|
+
const tag = document.createElement("marimo-code");
|
|
160
|
+
tag.textContent = encodeURIComponent("import marimo\napp = marimo.App()");
|
|
161
|
+
document.body.appendChild(tag);
|
|
162
|
+
try {
|
|
163
|
+
expect(
|
|
164
|
+
isTrustedVirtualFileUrl(
|
|
165
|
+
"data:text/javascript;base64,ZXhwb3J0IGRlZmF1bHQge30=",
|
|
166
|
+
),
|
|
167
|
+
).toBe(false);
|
|
168
|
+
} finally {
|
|
169
|
+
tag.remove();
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("rejects safe data URL when only __MARIMO_STATIC__ is present", () => {
|
|
174
|
+
windowWithExportContext.__MARIMO_STATIC__ = { files: {} };
|
|
175
|
+
expect(
|
|
176
|
+
isTrustedVirtualFileUrl(
|
|
177
|
+
"data:text/javascript;base64,ZXhwb3J0IGRlZmF1bHQge30=",
|
|
178
|
+
),
|
|
179
|
+
).toBe(false);
|
|
69
180
|
});
|
|
70
181
|
|
|
71
182
|
it.each([
|
|
72
|
-
// Non-base64 data URLs are refused
|
|
183
|
+
// Non-base64 data URLs are refused because the unencoded payload
|
|
184
|
+
// broadens the parsing/loading surface for attacker-controlled content.
|
|
73
185
|
"data:text/javascript,alert(1)",
|
|
74
186
|
"data:text/javascript;charset=utf-8,alert(1)",
|
|
75
|
-
// HTML / SVG / arbitrary types are refused
|
|
187
|
+
// HTML / SVG / arbitrary types are refused even when trusted.
|
|
76
188
|
"data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==",
|
|
77
189
|
"data:image/svg+xml;base64,PHN2Zy8+",
|
|
78
190
|
"data:application/octet-stream;base64,AAA=",
|
|
79
|
-
])("still rejects unsafe data URL %s", (url) => {
|
|
191
|
+
])("still rejects unsafe data URL %s in trusted context", (url) => {
|
|
192
|
+
store.set(hasRunAnyCellAtom, true);
|
|
80
193
|
expect(isTrustedVirtualFileUrl(url)).toBe(false);
|
|
81
194
|
});
|
|
82
195
|
|
|
83
|
-
it("rejects data
|
|
84
|
-
store.set(hasRunAnyCellAtom, false);
|
|
196
|
+
it("rejects data URLs when no trust signal is set", () => {
|
|
85
197
|
expect(
|
|
86
198
|
isTrustedVirtualFileUrl(
|
|
87
199
|
"data:text/javascript;base64,ZXhwb3J0IGRlZmF1bHQge30=",
|
|
@@ -1,6 +1,7 @@
|
|
|
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
5
|
import { store } from "@/core/state/jotai";
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -15,13 +16,13 @@ import { store } from "@/core/state/jotai";
|
|
|
15
16
|
* attacker-controlled JavaScript at same origin, since the HTML sanitizer
|
|
16
17
|
* lets arbitrary marimo custom elements and attributes through.
|
|
17
18
|
*
|
|
18
|
-
* Some runtimes (WASM, VS Code
|
|
19
|
-
*
|
|
19
|
+
* Some runtimes (WASM, VS Code, and trusted exported notebook contexts such as
|
|
20
|
+
* Quarto islands) have no backend to serve virtual files, so `VirtualFile`
|
|
21
|
+
* falls back to inline base64 data URLs (see `virtual_file.py`).
|
|
20
22
|
* We accept those only once the user has explicitly run a cell in the current
|
|
21
|
-
* notebook
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* new attack surface.
|
|
23
|
+
* notebook, or when a first-party export script has installed a trusted
|
|
24
|
+
* notebook export context. Both cases already imply trust in notebook-authored
|
|
25
|
+
* code, so loading the matching data URL is not a new attack surface.
|
|
25
26
|
*/
|
|
26
27
|
export function isTrustedVirtualFileUrl(url: unknown): url is string {
|
|
27
28
|
if (typeof url !== "string" || url.length === 0) {
|
|
@@ -30,16 +31,28 @@ export function isTrustedVirtualFileUrl(url: unknown): url is string {
|
|
|
30
31
|
if (/^(\.?\/)?@file\/[^?#]+$/.test(url)) {
|
|
31
32
|
return true;
|
|
32
33
|
}
|
|
33
|
-
if (isSafeDataUrl(url)
|
|
34
|
+
if (isSafeDataUrl(url)) {
|
|
34
35
|
return true;
|
|
35
36
|
}
|
|
36
37
|
return false;
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
function hasNotebookTrustedDataUrlContext(): boolean {
|
|
41
|
+
return store.get(hasRunAnyCellAtom) || hasTrustedExportContext();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Safe data URL formats: JS/CSS inlined as base64. Non-base64 data URLs and
|
|
46
|
+
* other MIME types (HTML, SVG, octet-stream, etc.) are refused because they
|
|
47
|
+
* broaden the surface for attacker-controlled inline content.
|
|
48
|
+
*/
|
|
39
49
|
function isSafeDataUrl(url: string): boolean {
|
|
40
|
-
|
|
50
|
+
const isSafeKind =
|
|
41
51
|
url.startsWith("data:text/javascript;base64,") ||
|
|
42
52
|
url.startsWith("data:application/javascript;base64,") ||
|
|
43
|
-
url.startsWith("data:text/css;base64,")
|
|
44
|
-
)
|
|
53
|
+
url.startsWith("data:text/css;base64,");
|
|
54
|
+
if (!isSafeKind) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
return hasNotebookTrustedDataUrlContext();
|
|
45
58
|
}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
-
import {
|
|
2
|
+
import type { ExtractAtomValue } from "jotai";
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { hasRunAnyCellAtom } from "@/components/editor/cell/useRunCells";
|
|
5
|
+
import { userConfigAtom } from "@/core/config/config";
|
|
6
|
+
import { parseUserConfig } from "@/core/config/config-schema";
|
|
7
|
+
import { initialModeAtom } from "@/core/mode";
|
|
8
|
+
import { store } from "@/core/state/jotai";
|
|
3
9
|
import { Model } from "../model";
|
|
4
10
|
import type { ModelState, WidgetModelId } from "../types";
|
|
5
11
|
import { visibleForTesting } from "../widget-binding";
|
|
@@ -18,9 +24,31 @@ function createMockComm() {
|
|
|
18
24
|
|
|
19
25
|
describe("WidgetDefRegistry", () => {
|
|
20
26
|
let registry: InstanceType<typeof WidgetDefRegistry>;
|
|
27
|
+
let previousConfig: ExtractAtomValue<typeof userConfigAtom>;
|
|
28
|
+
let previousMode: ExtractAtomValue<typeof initialModeAtom>;
|
|
29
|
+
let previousHasRunAnyCell: ExtractAtomValue<typeof hasRunAnyCellAtom>;
|
|
21
30
|
|
|
22
31
|
beforeEach(() => {
|
|
23
32
|
registry = new WidgetDefRegistry();
|
|
33
|
+
// Force "no notebook trust" so the `data:` rejection test below
|
|
34
|
+
// exercises the untrusted branch. The positive trust path is covered
|
|
35
|
+
// centrally in trusted-url.test.ts.
|
|
36
|
+
previousConfig = store.get(userConfigAtom);
|
|
37
|
+
previousMode = store.get(initialModeAtom);
|
|
38
|
+
previousHasRunAnyCell = store.get(hasRunAnyCellAtom);
|
|
39
|
+
store.set(hasRunAnyCellAtom, false);
|
|
40
|
+
const cleared = parseUserConfig({});
|
|
41
|
+
store.set(userConfigAtom, {
|
|
42
|
+
...cleared,
|
|
43
|
+
runtime: { ...cleared.runtime, auto_instantiate: false },
|
|
44
|
+
});
|
|
45
|
+
store.set(initialModeAtom, "edit");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
afterEach(() => {
|
|
49
|
+
store.set(userConfigAtom, previousConfig);
|
|
50
|
+
store.set(initialModeAtom, previousMode);
|
|
51
|
+
store.set(hasRunAnyCellAtom, previousHasRunAnyCell);
|
|
24
52
|
});
|
|
25
53
|
|
|
26
54
|
it("should cache modules by jsHash and return same promise", () => {
|
|
@@ -1,12 +1,41 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import type { ExtractAtomValue } from "jotai";
|
|
2
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { hasRunAnyCellAtom } from "@/components/editor/cell/useRunCells";
|
|
5
|
+
import { userConfigAtom } from "@/core/config/config";
|
|
6
|
+
import { parseUserConfig } from "@/core/config/config-schema";
|
|
7
|
+
import { initialModeAtom } from "@/core/mode";
|
|
8
|
+
import { store } from "@/core/state/jotai";
|
|
3
9
|
import { Logger } from "@/utils/Logger";
|
|
4
10
|
import { visibleForTesting } from "../MplInteractivePlugin";
|
|
5
11
|
|
|
6
12
|
const { ensureMplJs, injectCss, resetMplJsLoading } = visibleForTesting;
|
|
7
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Clear every "notebook trust" signal `isTrustedVirtualFileUrl` consults so
|
|
16
|
+
* the rejection cases below test the actually-untrusted branch. Positive
|
|
17
|
+
* export-context trust is covered centrally in trusted-url.test.ts.
|
|
18
|
+
*/
|
|
19
|
+
function clearTrustSignals() {
|
|
20
|
+
store.set(hasRunAnyCellAtom, false);
|
|
21
|
+
const cleared = parseUserConfig({});
|
|
22
|
+
store.set(userConfigAtom, {
|
|
23
|
+
...cleared,
|
|
24
|
+
runtime: { ...cleared.runtime, auto_instantiate: false },
|
|
25
|
+
});
|
|
26
|
+
store.set(initialModeAtom, "edit");
|
|
27
|
+
}
|
|
28
|
+
|
|
8
29
|
describe("MplInteractivePlugin URL validation", () => {
|
|
30
|
+
let previousConfig: ExtractAtomValue<typeof userConfigAtom>;
|
|
31
|
+
let previousMode: ExtractAtomValue<typeof initialModeAtom>;
|
|
32
|
+
let previousHasRunAnyCell: ExtractAtomValue<typeof hasRunAnyCellAtom>;
|
|
33
|
+
|
|
9
34
|
beforeEach(() => {
|
|
35
|
+
previousConfig = store.get(userConfigAtom);
|
|
36
|
+
previousMode = store.get(initialModeAtom);
|
|
37
|
+
previousHasRunAnyCell = store.get(hasRunAnyCellAtom);
|
|
38
|
+
clearTrustSignals();
|
|
10
39
|
// Reset module-level script-loading state and any stubs.
|
|
11
40
|
delete (window as { mpl?: unknown }).mpl;
|
|
12
41
|
resetMplJsLoading();
|
|
@@ -20,6 +49,9 @@ describe("MplInteractivePlugin URL validation", () => {
|
|
|
20
49
|
|
|
21
50
|
afterEach(() => {
|
|
22
51
|
vi.restoreAllMocks();
|
|
52
|
+
store.set(userConfigAtom, previousConfig);
|
|
53
|
+
store.set(initialModeAtom, previousMode);
|
|
54
|
+
store.set(hasRunAnyCellAtom, previousHasRunAnyCell);
|
|
23
55
|
});
|
|
24
56
|
|
|
25
57
|
describe("ensureMplJs", () => {
|
|
@@ -35,6 +67,8 @@ describe("MplInteractivePlugin URL validation", () => {
|
|
|
35
67
|
"https://evil.example.com/x.js",
|
|
36
68
|
"//evil.example.com/x.js",
|
|
37
69
|
"javascript:alert(1)",
|
|
70
|
+
// Data URL is rejected only in an untrusted context. WASM/autoInstantiate
|
|
71
|
+
// intentionally accepts it — covered by trusted-url.test.ts.
|
|
38
72
|
"data:text/javascript;base64,YWxlcnQoMSk=",
|
|
39
73
|
"./@file/x.js?redirect=http://evil.com",
|
|
40
74
|
])("rejects %s", async (url) => {
|
|
@@ -1,10 +1,39 @@
|
|
|
1
1
|
/* Copyright 2026 Marimo. All rights reserved. */
|
|
2
|
+
import type { ExtractAtomValue } from "jotai";
|
|
2
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { hasRunAnyCellAtom } from "@/components/editor/cell/useRunCells";
|
|
5
|
+
import { userConfigAtom } from "@/core/config/config";
|
|
6
|
+
import { parseUserConfig } from "@/core/config/config-schema";
|
|
7
|
+
import { initialModeAtom } from "@/core/mode";
|
|
8
|
+
import { store } from "@/core/state/jotai";
|
|
3
9
|
import { Logger } from "@/utils/Logger";
|
|
4
10
|
import { loadPanelExtension } from "../PanelPlugin";
|
|
5
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Force the "no notebook trust" branch so the `data:` URL rejection below
|
|
14
|
+
* actually exercises the untrusted path. Positive export-context trust is
|
|
15
|
+
* covered centrally in trusted-url.test.ts.
|
|
16
|
+
*/
|
|
17
|
+
function clearTrustSignals() {
|
|
18
|
+
store.set(hasRunAnyCellAtom, false);
|
|
19
|
+
const cleared = parseUserConfig({});
|
|
20
|
+
store.set(userConfigAtom, {
|
|
21
|
+
...cleared,
|
|
22
|
+
runtime: { ...cleared.runtime, auto_instantiate: false },
|
|
23
|
+
});
|
|
24
|
+
store.set(initialModeAtom, "edit");
|
|
25
|
+
}
|
|
26
|
+
|
|
6
27
|
describe("loadPanelExtension", () => {
|
|
28
|
+
let previousConfig: ExtractAtomValue<typeof userConfigAtom>;
|
|
29
|
+
let previousMode: ExtractAtomValue<typeof initialModeAtom>;
|
|
30
|
+
let previousHasRunAnyCell: ExtractAtomValue<typeof hasRunAnyCellAtom>;
|
|
31
|
+
|
|
7
32
|
beforeEach(() => {
|
|
33
|
+
previousConfig = store.get(userConfigAtom);
|
|
34
|
+
previousMode = store.get(initialModeAtom);
|
|
35
|
+
previousHasRunAnyCell = store.get(hasRunAnyCellAtom);
|
|
36
|
+
clearTrustSignals();
|
|
8
37
|
for (const el of document.head.querySelectorAll("script")) {
|
|
9
38
|
el.remove();
|
|
10
39
|
}
|
|
@@ -12,6 +41,9 @@ describe("loadPanelExtension", () => {
|
|
|
12
41
|
|
|
13
42
|
afterEach(() => {
|
|
14
43
|
vi.restoreAllMocks();
|
|
44
|
+
store.set(userConfigAtom, previousConfig);
|
|
45
|
+
store.set(initialModeAtom, previousMode);
|
|
46
|
+
store.set(hasRunAnyCellAtom, previousHasRunAnyCell);
|
|
15
47
|
});
|
|
16
48
|
|
|
17
49
|
it("does nothing and returns false for null URL", () => {
|
|
@@ -35,8 +67,9 @@ describe("loadPanelExtension", () => {
|
|
|
35
67
|
it.each([
|
|
36
68
|
"https://evil.example.com/x.js",
|
|
37
69
|
"//evil.example.com/x.js",
|
|
38
|
-
//
|
|
39
|
-
//
|
|
70
|
+
// Data URL is rejected only in an untrusted context — the WASM fallback
|
|
71
|
+
// legitimately produces these, so trusted-url.test.ts covers the
|
|
72
|
+
// positive path when a notebook trust signal is set.
|
|
40
73
|
"data:text/javascript;base64,YWxlcnQoMSk=",
|
|
41
74
|
"javascript:alert(1)",
|
|
42
75
|
"./@file/x.js#http://evil.com",
|