Security hardening: MCP server auth#540
Merged
Merged
Conversation
3332a5f to
9e5624e
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds security hardening for MCP integrations by introducing opt-in MCP server authentication and default URL validation to mitigate client-side SSRF risks.
Changes:
- Add
requireAuthhook toMcpPluginto gate inbound MCP/mcprequests with 401 on failure. - Add
validateMcpServerUrlURL gate (scheme + DNS/private-network filtering) and exposeallowPrivateNetwork/validateUrlparams in the MCP client. - Add/adjust Jest tests to cover URL validation and server auth behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| external/mcpclient/src/url-validation.ts | Implements default URL scheme + private-network/DNS-based validation and error type. |
| external/mcpclient/src/url-validation.spec.ts | Adds unit tests for URL validation behavior and edge cases. |
| external/mcpclient/src/mcp-client-types.ts | Extends client params with allowPrivateNetwork and validateUrl. |
| external/mcpclient/src/mcp-client-plugin.ts | Wires URL validation into MCP client creation flow. |
| external/mcpclient/src/mcp-client-plugin.spec.ts | Stubs DNS lookup to keep existing tests deterministic/offline. |
| external/mcp/src/plugin.ts | Adds requireAuth option, startup warning, and auth middleware for MCP SSE route prefix. |
| external/mcp/src/plugin.spec.ts | Adds unit tests for new checkAuth behavior with various outcomes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Per team decision, the MCP client SSRF guard adds friction for legitimate on-prem MCP customers and the underlying risk is low-likelihood. Reverting the client-side URL validation work; the McpPlugin server auth (#14) and the Express-level path-prefix middleware refactor are kept. Removes: - external/mcpclient/src/url-validation.ts (and spec) - McpClientPluginParams.allowPrivateNetwork + validateUrl - validateMcpServerUrl call in makeMcpClient - DNS mock added to mcp-client-plugin.spec.ts
fd3444f to
2d8f3a3
Compare
In checkAuth, after the requireAuth try/catch, return early without writing a 401 if req.aborted is set. The client has already disconnected; attempting to set headers on a destroyed stream produces noisy warnings without changing observable behavior. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
lilyydu
approved these changes
May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses security scan finding #14 (MCP server mounted without auth). TypeScript half of a 2-SDK PR set (.NET PR is on the same branch name).
#14 — MCP server auth
New opt-in
requireAuthhook onMcpPluginOptions:Hook is called once per inbound MCP request via an Express-level prefix middleware on
/mcp(covers any current or future handler registered under that path).false/throw returns 401. When unset, all requests are accepted and a one-time startup warning fires when the SSE transport comes up.Design doc
design/mcp-server-auth-options.mdE2E verified
/mcpreturns 401 without auth, SSE handshake on correct bearer/api/messages): bot responded to a devtools chat message withREQUIRE_AUTH=1active simultaneouslyrequireAuthis unset; silent when set