Skip to content

fix: additional pep 723 sanitization#10281

Merged
mscolnick merged 6 commits into
mainfrom
fix/pep723-additional-sanitization
Jul 23, 2026
Merged

fix: additional pep 723 sanitization#10281
mscolnick merged 6 commits into
mainfrom
fix/pep723-additional-sanitization

Conversation

@dmadisetti

@dmadisetti dmadisetti commented Jul 22, 2026

Copy link
Copy Markdown
Member

Summary

Hardening of pep 723 config options

Grg0rry and others added 3 commits July 22, 2026 15:15
Notebook (PEP 723) metadata embedded in a .py file is attacker-controllable
and is merged with the highest precedence over the operator's own user config.
The previous sanitizer only stripped a single key
(tool.marimo.runtime.auto_instantiate), so every other section passed through
unchecked.

That let a notebook override credential-affecting and traffic-affecting config
such as tool.marimo.ai.open_ai.base_url: marimo resolves the operator's
OPENAI_API_KEY from the environment as the fallback key for that overridden
base_url, so the next AI request would POST the operator's real key to an
attacker-controlled URL. The same shape applies to tool.marimo.mcp.*.url and
tool.marimo.completion.{api_key,base_url}.

Fix the root cause at the shared ScriptConfigManager choke point: permit only
an explicit safe set of cosmetic/editor sections (formatting, save, display,
keymap, diagnostics, lint, snippets, datasources) and drop everything else,
logging a warning per dropped section. The existing auto_instantiate strip is
retained as defense in depth.

Tests:
- test_script_config_manager_sanitizes_auto_instantiate updated to assert the
  whole runtime section is now dropped.
- test_script_config_manager_drops_credential_affecting_sections covers
  ai/mcp/completion/secrets/package_management/server being dropped while a
  cosmetic section survives.
- test_script_config_manager_ai_base_url_does_not_override is a direct
  regression for the ai.open_ai.base_url override.
…arly-return bug

- Allowlist language_servers, sharing, venv, runtime, experimental,
  package_management (no credential/traffic-affecting vector once
  auto_instantiate and isolate_apps are separately stripped).
- Add experimental.isolate_apps to the stripped-key list alongside
  runtime.auto_instantiate.
- Fix sanitize_pyproject_dict returning early from the whole function
  when one key_path's intermediate segment was missing, which silently
  skipped every subsequent key_path (caught by adding the second
  stripped key above).
- Update/add tests accordingly.
No behavior change: consolidate the attacker-controllable/highest-precedence
explanation to a single location and remove narrate-the-next-line comments
in the tests touched by the prior commit.
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Jul 23, 2026 2:34am

Request Review

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@dmadisetti dmadisetti added the internal A refactor or improvement that is not user facing label Jul 22, 2026
@dmadisetti

Copy link
Copy Markdown
Member Author

@Grg0rry can you sign our CLA please?

@dmadisetti
dmadisetti requested a review from mscolnick July 22, 2026 22:17

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed against the latest diff

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread marimo/_config/reader.py
@Grg0rry

Grg0rry commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

I have read the CLA Document and I hereby sign the CLA

@dmadisetti
dmadisetti marked this pull request as ready for review July 22, 2026 23:39
Copilot AI review requested due to automatic review settings July 22, 2026 23:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Hardens parsing of PEP 723 (“script” header) inline config by restricting which tool.marimo.* sections can be applied and by stripping additional sensitive keys, reducing the risk of attacker-controlled notebooks overriding operator config.

Changes:

  • Fix sanitize_pyproject_dict() to keep processing subsequent key paths even if an earlier path is missing intermediate segments.
  • Introduce a top-level allowlist for tool.marimo.<section> in script metadata and apply it in ScriptConfigManager.
  • Expand sanitization and add tests covering the new allowlist + additional stripped keys (experimental.isolate_apps, credential/traffic-related sections).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
marimo/_config/reader.py Adds script-metadata allowlist and improves sanitization behavior for multiple key paths.
marimo/_config/manager.py Applies allowlist + expanded sanitization when reading PEP 723 script config.
tests/_config/test_reader.py Adds regression test ensuring sanitization continues after a missing intermediate path.
tests/_config/test_manager.py Adds/updates tests asserting sensitive sections/keys are stripped while allowed config passes through.

Comment thread marimo/_config/reader.py Outdated
tool is a table per the pyproject.toml spec, but script metadata is raw,
untrusted TOML a notebook author fully controls. A non-table tool value
previously crashed with an opaque AttributeError several calls deep;
both call sites now share one validated accessor.
@mscolnick
mscolnick merged commit 1a21bd7 into main Jul 23, 2026
43 checks passed
@mscolnick
mscolnick deleted the fix/pep723-additional-sanitization branch July 23, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal A refactor or improvement that is not user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants