Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

feat(sharing): enforce sharing config as server-side security (#9578)

Florian Verdonck8ca34dd9a08a
diff --git a/frontend/src/components/editor/actions/useNotebookActions.tsx b/frontend/src/components/editor/actions/useNotebookActions.tsx
index 0e9db7ce7a..54c4adf52c 100644
--- a/frontend/src/components/editor/actions/useNotebookActions.tsx
+++ b/frontend/src/components/editor/actions/useNotebookActions.tsx
@@ -142,9 +142,10 @@ export function useNotebookActions() {
const { selectedLayout } = useLayoutState();
const { setLayoutView } = useLayoutActions();
const togglePresenting = useTogglePresenting();
- // Fallback: if sharing is undefined, both are enabled by default
+ // Fallback: if sharing is undefined, all options are enabled by default
const sharingHtmlEnabled = resolvedConfig.sharing?.html ?? true;
const sharingWasmEnabled = resolvedConfig.sharing?.wasm ?? true;
+ const sharingMolabEnabled = resolvedConfig.sharing?.molab ?? true;
// Server-side PDF export is always available outside WASM.
// Browser print fallback is used in WASM.
@@ -360,7 +361,8 @@ export function useNotebookActions() {
icon: <Share2Icon size={14} strokeWidth={1.5} />,
label: "Share",
handle: NOOP_HANDLER,
- hidden: !sharingHtmlEnabled && !sharingWasmEnabled,
+ hidden:
+ !sharingHtmlEnabled && !sharingWasmEnabled && !sharingMolabEnabled,
dropdown: [
{
icon: <GlobeIcon size={14} strokeWidth={1.5} />,
@@ -387,6 +389,7 @@ export function useNotebookActions() {
{
icon: <MarimoPlusIcon size={14} strokeWidth={1.5} />,
label: "Create molab notebook",
+ hidden: !sharingMolabEnabled,
handle: async () => {
const code = await readCode();
const url = createShareableLink({
diff --git a/frontend/src/components/static-html/static-banner.tsx b/frontend/src/components/static-html/static-banner.tsx
index e8757b2ca7..00340b1d9c 100644
--- a/frontend/src/components/static-html/static-banner.tsx
+++ b/frontend/src/components/static-html/static-banner.tsx
@@ -6,6 +6,7 @@ import { useAtomValue } from "jotai";
import { CopyIcon, DownloadIcon } from "lucide-react";
import type React from "react";
import { Constants } from "@/core/constants";
+import { useResolvedMarimoConfig } from "@/core/config/config";
import { codeAtom } from "@/core/saving/file-state";
import { useFilename } from "@/core/saving/filename";
import { isStaticNotebook } from "@/core/static/static-state";
@@ -66,6 +67,9 @@ const StaticBannerDialog = ({ code }: { code: string }) => {
filename = filename.slice(lastSlash + 1);
}
+ const [resolvedConfig] = useResolvedMarimoConfig();
+ const molabEnabled = resolvedConfig.sharing?.molab !== false;
+
const href = window.location.href;
const molabLink = createShareableLink({
code,
@@ -118,28 +122,30 @@ const StaticBannerDialog = ({ code }: { code: string }) => {
</div>
)}
- <div className="pt-3 border-t flex gap-2 items-center">
- <Button
- asChild={true}
- variant="outline"
- size="xs"
- className="shrink-0"
- >
- <a href={molabLink} target="_blank" rel="noopener noreferrer">
- <MarimoPlusIcon
- size={12}
- strokeWidth={1.5}
- className="mr-1.5 mt-px text-(--grass-11)"
- />
- Open in molab
- </a>
- </Button>
- <p className="text-sm text-(--sky-12)">
- Run this notebook in{" "}
- <span className="font-semibold">molab</span>, marimo's
- cloud-hosted notebook platform.
- </p>
- </div>
+ {molabEnabled && (
+ <div className="pt-3 border-t flex gap-2 items-center">
+ <Button
+ asChild={true}
+ variant="outline"
+ size="xs"
+ className="shrink-0"
+ >
+ <a href={molabLink} target="_blank" rel="noopener noreferrer">
+ <MarimoPlusIcon
+ size={12}
+ strokeWidth={1.5}
+ className="mr-1.5 mt-px text-(--grass-11)"
+ />
+ Open in molab
+ </a>
+ </Button>
+ <p className="text-sm text-(--sky-12)">
+ Run this notebook in{" "}
+ <span className="font-semibold">molab</span>, marimo's
+ cloud-hosted notebook platform.
+ </p>
+ </div>
+ )}
</DialogDescription>
</DialogHeader>
<div className="flex gap-3 pt-2">
diff --git a/frontend/src/core/config/config-schema.ts b/frontend/src/core/config/config-schema.ts
index fe7d75aef0..7274dd9b63 100644
--- a/frontend/src/core/config/config-schema.ts
+++ b/frontend/src/core/config/config-schema.ts
@@ -210,6 +210,7 @@ export const UserConfigSchema = z
.looseObject({
html: z.boolean().optional(),
wasm: z.boolean().optional(),
+ molab: z.boolean().optional(),
})
.optional(),
mcp: z
diff --git a/marimo/_config/config.py b/marimo/_config/config.py
index 51c0c61b33..9c394a2b3e 100644
--- a/marimo/_config/config.py
+++ b/marimo/_config/config.py
@@ -570,10 +570,12 @@ class SharingConfig(TypedDict):
- `html`: if `False`, HTML sharing options will be hidden from the UI
- `wasm`: if `False`, WebAssembly sharing options will be hidden from the UI
+ - `molab`: if `False`, molab sharing options will be hidden from the UI
"""
html: NotRequired[bool]
wasm: NotRequired[bool]
+ molab: NotRequired[bool]
@dataclass
diff --git a/marimo/_server/api/endpoints/export.py b/marimo/_server/api/endpoints/export.py
index 1500f79f70..93ea9c350c 100644
--- a/marimo/_server/api/endpoints/export.py
+++ b/marimo/_server/api/endpoints/export.py
@@ -94,11 +94,13 @@ async def export_as_html(
if not app_state.session_manager.should_send_code_to_frontend():
body.include_code = False
+ resolved_config = session.config_manager.get_config()
html, filename = Exporter().export_as_html(
app=session.app_file_manager.app,
filename=session.app_file_manager.filename,
session_view=session.session_view,
- display_config=session.config_manager.get_config()["display"],
+ display_config=resolved_config["display"],
+ sharing_config=resolved_config.get("sharing"),
request=body,
)
diff --git a/marimo/_server/export/__init__.py b/marimo/_server/export/__init__.py
index ca0ebfb276..bd11c197d1 100644
--- a/marimo/_server/export/__init__.py
+++ b/marimo/_server/export/__init__.py
@@ -13,7 +13,7 @@ from marimo._ast.app import InternalApp
from marimo._ast.errors import CycleError, MultipleDefinitionError
from marimo._ast.load import load_app
from marimo._cli.print import echo
-from marimo._config.config import DisplayConfig, RuntimeConfig
+from marimo._config.config import RuntimeConfig
from marimo._config.manager import (
get_default_config_manager,
)
@@ -167,15 +167,17 @@ def export_as_wasm(
# Inline the layout file, if it exists
app.inline_layout_file()
config = get_default_config_manager(current_path=path.absolute_name)
+ resolved = config.get_config()
result = Exporter().export_as_wasm(
filename=path.short_name,
app=app,
- display_config=config.get_config()["display"],
+ display_config=resolved["display"],
mode=mode,
code=app.to_py(),
asset_url=asset_url,
show_code=show_code,
+ sharing_config=resolved.get("sharing"),
)
return ExportResult(
contents=result[0],
@@ -332,7 +334,8 @@ async def run_app_then_export_as_html(
file_manager.app.inline_layout_file()
config = get_default_config_manager(current_path=file_manager.path)
- display_config = cast(DisplayConfig, config.get_config()["display"])
+ resolved = config.get_config()
+ display_config = resolved["display"]
session_view, did_error = await run_app_until_completion(
file_manager,
cli_args,
@@ -344,6 +347,7 @@ async def run_app_then_export_as_html(
app=file_manager.app,
session_view=session_view,
display_config=display_config,
+ sharing_config=resolved.get("sharing"),
request=ExportAsHTMLRequest(
include_code=include_code,
download=False,
@@ -377,7 +381,8 @@ async def run_app_then_export_as_wasm(
file_manager.app.inline_layout_file()
config = get_default_config_manager(current_path=file_manager.path)
- display_config = cast(DisplayConfig, config.get_config()["display"])
+ resolved = config.get_config()
+ display_config = resolved["display"]
session_view, did_error = await run_app_until_completion(
file_manager,
@@ -406,6 +411,7 @@ async def run_app_then_export_as_wasm(
asset_url=asset_url,
session_snapshot=session_snapshot,
notebook_snapshot=notebook_snapshot,
+ sharing_config=resolved.get("sharing"),
)
return ExportResult(
contents=html,
@@ -433,7 +439,7 @@ async def export_as_html_without_execution(
view.last_executed_code[cell_data.cell_id] = cell_data.code
config = get_default_config_manager(current_path=file_manager.path)
- display_config = cast(DisplayConfig, config.get_config()["display"])
+ display_config = config.get_config()["display"]
html, filename = Exporter().export_as_html(
filename=file_manager.filename,
diff --git a/marimo/_server/export/exporter.py b/marimo/_server/export/exporter.py
index 4ba6c01816..ce18001843 100644
--- a/marimo/_server/export/exporter.py
+++ b/marimo/_server/export/exporter.py
@@ -15,6 +15,7 @@ from marimo._config.config import (
DEFAULT_CONFIG,
DisplayConfig,
MarimoConfig,
+ SharingConfig,
)
from marimo._config.settings import GLOBAL_SETTINGS
from marimo._config.utils import deep_copy
@@ -102,12 +103,13 @@ class Exporter:
session_view: SessionView,
display_config: DisplayConfig,
request: ExportAsHTMLRequest,
+ sharing_config: SharingConfig | None = None,
) -> tuple[str, str]:
index_html = get_html_contents()
filename = get_filename(filename)
- # Configure notebook with display settings
- config = self._prepare_display_config(display_config)
+ # Configure notebook with display and sharing settings
+ config = self._prepare_display_config(display_config, sharing_config)
# Serialize notebook state
session_snapshot = serialize_session_view(
@@ -165,16 +167,16 @@ class Exporter:
return html, download_filename
def _prepare_display_config(
- self, display_config: DisplayConfig
+ self,
+ display_config: DisplayConfig,
+ sharing_config: SharingConfig | None = None,
) -> MarimoConfig:
- """Prepare config with display settings for static notebook."""
- # We only want pass the display config in the static notebook,
- # since we use:
- # - display.theme
- # - display.cell_output
- config = deep_copy(DEFAULT_CONFIG)
+ """Prepare config with display and sharing settings for static notebook."""
+ config: MarimoConfig = deep_copy(DEFAULT_CONFIG)
config["display"] = display_config
- return cast(MarimoConfig, config)
+ if sharing_config:
+ config["sharing"] = sharing_config
+ return config
@staticmethod
def _iter_html_data_strings(
@@ -396,14 +398,13 @@ class Exporter:
asset_url: str | None = None,
session_snapshot: NotebookSessionV1 | None = None,
notebook_snapshot: NotebookV1 | None = None,
+ sharing_config: SharingConfig | None = None,
) -> tuple[str, str]:
"""Export notebook as a WASM-powered standalone HTML file."""
index_html = get_html_contents()
filename = get_filename(filename)
- # We only want to pass the display config in the static notebook
- config: MarimoConfig = deep_copy(DEFAULT_CONFIG)
- config["display"] = display_config
+ config = self._prepare_display_config(display_config, sharing_config)
# Remove autosave
config["save"]["autosave"] = "off"
diff --git a/packages/openapi/api.yaml b/packages/openapi/api.yaml
index 824d9b9e1c..ebf37f230a 100644
--- a/packages/openapi/api.yaml
+++ b/packages/openapi/api.yaml
@@ -4624,10 +4624,13 @@ components:
description: "Configuration for sharing features.\n\n **Keys.**\n\n -\
\ `html`: if `False`, HTML sharing options will be hidden from the UI\n \
\ - `wasm`: if `False`, WebAssembly sharing options will be hidden from the\
- \ UI"
+ \ UI\n - `molab`: if `False`, molab sharing options will be hidden from\
+ \ the UI"
properties:
html:
type: boolean
+ molab:
+ type: boolean
wasm:
type: boolean
required: []
diff --git a/packages/openapi/src/api.ts b/packages/openapi/src/api.ts
index e714ddee20..8c6ceca577 100644
--- a/packages/openapi/src/api.ts
+++ b/packages/openapi/src/api.ts
@@ -6169,9 +6169,11 @@ export interface components {
*
* - `html`: if `False`, HTML sharing options will be hidden from the UI
* - `wasm`: if `False`, WebAssembly sharing options will be hidden from the UI
+ * - `molab`: if `False`, molab sharing options will be hidden from the UI
*/
SharingConfig: {
html?: boolean;
+ molab?: boolean;
wasm?: boolean;
};
/** ShutdownSessionRequest */