Skip to content

Security: safer CORS examples + avoid shell=True#2011

Closed
TheodorNEngoy wants to merge 4 commits intomodelcontextprotocol:mainfrom
TheodorNEngoy:codex/harden-cors-and-open-browser
Closed

Security: safer CORS examples + avoid shell=True#2011
TheodorNEngoy wants to merge 4 commits intomodelcontextprotocol:mainfrom
TheodorNEngoy:codex/harden-cors-and-open-browser

Conversation

@TheodorNEngoy
Copy link

@TheodorNEngoy TheodorNEngoy commented Feb 7, 2026

This hardens a few high-signal footguns that show up in MCP / tool-server code:

  • Examples: replace wildcard CORS (allow_origins=["*"]) with a localhost-only allow_origin_regex.
    This still supports browser-based clients during local dev while avoiding suggesting wildcard CORS as a default.
  • URL elicitation client snippet: use webbrowser.open() instead of subprocess.run(..., shell=True) for cross-platform browser launch.
  • Tests: make TestChildProcessCleanup less timing-sensitive by polling for file growth (reduces occasional Windows CI flakes) while keeping coverage at 100%.

@TheodorNEngoy
Copy link
Author

All checks are green.

This keeps examples safer by default (no wildcard CORS; localhost-only regex) and avoids subprocess(..., shell=True) for opening a browser (uses webbrowser.open() instead). Happy to adjust the default allowlist/regex if you’d prefer a different local-dev story.

@TheodorNEngoy
Copy link
Author

Closing to reduce review noise: this PR is now superseded by the split, narrower PRs:

Happy to resurrect/port over the remaining stdio test flake/coverage tweaks as a separate PR if those are still useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant