Security hardening: MCP server auth#540
Merged
Merged
Conversation
corinagum
marked this pull request as ready for review
April 29, 2026 19:24
corinagum
force-pushed
the
cg/mcp-auth-hardening
branch
from
April 29, 2026 19:27
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
corinagum
force-pushed
the
cg/mcp-auth-hardening
branch
from
May 6, 2026 23:22
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) <[email protected]>
lilyydu
approved these changes
May 7, 2026
corinagum
added a commit
to microsoft/teams-sdk
that referenced
this pull request
May 27, 2026
## Summary Adds a Trust Model page under Essentials → App Configuration documenting the layered authentication model the SDK uses for inbound JSON Web Tokens. ## Why A scanner flagged the SDK's `JsonWebToken` accessor class because it does not perform signature verification at the point of token parsing. A cross-SDK audit confirmed this is intentional architecture: signature verification runs at the HTTP boundary (via the activity pipeline's token validator), and the accessor class is a typed view over already-validated payloads. Every consumer of decoded claims is downstream of a validator pass. This page makes the architectural invariant explicit for SDK consumers, reviewers, and future contributors. ## What's covered - What the SDK validates automatically on `/api/messages` (signature, issuer, audience, lifetime, algorithm) - What downstream code can rely on (typed accessors over validated tokens) - How to add custom authentication to non-default surfaces (MCP, callbacks, webhooks) — references the `requireAuth` hook recently added in microsoft/teams.ts#540 / microsoft/teams.net#448 - Anti-patterns to avoid (constructing the accessor from untrusted input as a basis for authorization decisions) ## Build verified `npm run build` clean. ## Related PRs - TypeScript: microsoft/teams.ts#586 - Python: microsoft/teams.py#432 - .NET: microsoft/teams.net#517 --------- Co-authored-by: Copilot Autofix powered by AI <[email protected]>
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