Skip to content

CLI: doctor --mcp sends the API key only to a Studio that proves its identity - #14178

Merged
danielhanchen merged 1 commit into
mainfrom
sec/s137-mcp-doctor-identity
Oct 19, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
sec/s137-mcp-doctor-identity

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Hardening from the latest security scan, in unsloth doctor --mcp (added in #14077).

Problem. When UNSLOTH_STUDIO_URL is not set, the MCP doctor finds Unsloth Studio by probing local ports for the public /api/health answer, then sends UNSLOTH_API_KEY as a bearer token to /api/inference/loaded-models and /mcp/. /api/health is public, so anything listening on that loopback port can answer it. On a shared machine, another local user listening on 127.0.0.1:8888 while Studio is stopped would receive the owner's API key. unsloth chat and unsloth start already guard against this with verify_studio_identity (an HMAC challenge only this machine's Studio can answer) before sending a secret; the doctor skipped it.

Change (unsloth_cli/commands/mcp.py). For an auto-discovered loopback server, the doctor calls verify_studio_identity first. If it fails, the key is not sent to either endpoint and the doctor reports API key: set, not sent with a hint to set UNSLOTH_STUDIO_URL.

  • A normal local Studio passes the check, so the doctor's output is unchanged.
  • An explicit UNSLOTH_STUDIO_URL is still trusted as before (the user named the server), which keeps SSH-tunnel setups working.
  • Read-only and idempotent; no other command changes.

Tests (unsloth_cli/tests/test_doctor_mcp.py): a new case where the found server fails the identity check asserts no Authorization header reaches it, and that UNSLOTH_STUDIO_URL still sends the key; plus the new hint. Both fail on main and pass here. The full unsloth_cli/tests suite passes (2095 passed).

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T02:38:15.519238Z 4564886 Manual request
🔒 Security Review ✅ Completed 2026-10-19T02:38:09.738141Z 4564886 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-19T02:35:46.932976Z 4564886 PR opened
🔒 Security Review ⚠️ Failed 2026-10-19T02:35:51.382317Z 4564886 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 45648861da

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 45648861da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 0c23763 into main Oct 19, 2026
@danielhanchen
danielhanchen deleted the sec/s137-mcp-doctor-identity branch October 19, 2026 04:01
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