Skip to content

feat: enforce SSRF protection for MCP config-directed traffic - #28242

Merged
ibetitsmike merged 12 commits into
mainfrom
mike/codagt-711-mcp-ssrf
Aug 30, 2026
Merged

feat: enforce SSRF protection for MCP config-directed traffic#28242
ibetitsmike merged 12 commits into
mainfrom
mike/codagt-711-mcp-ssrf

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Routes all MCP config-directed traffic from coderd and chatd through a shared SSRF-protected HTTP client, now that organization admins, not only deployment admins, control MCP server URLs (#27942 and its stack below).

Summary

  • Uses the coder/safedial library: it blocks private and special-purpose destinations at dial time (validating resolved addresses at connection time so DNS rebinding cannot bypass the check) and rejects cross-origin redirects.
  • Covers the complete traffic surface: OAuth2 discovery, dynamic client registration, code exchange, token refresh, revocation, and runtime MCP connections from chatd.
  • Deployments that intentionally host internal MCP servers opt in via the new --mcp-allowed-private-cidrs (CODER_MCP_ALLOWED_PRIVATE_CIDRS) option.
  • Includes the deployment configuration surface, generated docs, CLI goldens, TypeScript types, and regression coverage for each traffic path.

Merge window

This protection originally lived inside #27942 and was split out to keep that diff reviewable. Until this PR lands, the stack below ships with only main's existing discovery IP-range guard (CODER_MCP_OAUTH2_DISCOVERY_ALLOWED_IP_RANGES), while org admins can already point MCP configs at arbitrary URLs. This PR should merge promptly after the stack below it.

Top of the MCP org-separation stack (CODAGT-711 -> CODAGT-717 audit -> CODAGT-712 ACLs -> CODAGT-806 token RBAC -> CODAGT-714 org picker -> this PR).

Mux (AI agent) authored this PR on Mike's behalf.

@linear-code

linear-code Bot commented Aug 18, 2026

Copy link
Copy Markdown

CODAGT-711

@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Docs preview

Check off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here.

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 2e5292cbdf

ℹ️ 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".

@ibetitsmike
ibetitsmike force-pushed the mike/codagt-711-mcp-ssrf branch from 2e5292c to 85bb3af Compare August 18, 2026 08:31
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 85bb3af7bc

ℹ️ 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".

Comment thread coderd/mcpssrf/client.go Outdated
@ibetitsmike
ibetitsmike force-pushed the mike/codagt-711-mcp-ssrf branch from 85bb3af to 814375a Compare August 18, 2026 09:15
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 814375ab5e

ℹ️ 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".

@ibetitsmike
ibetitsmike force-pushed the mike/codagt-711-mcp-ssrf branch from 814375a to 78f219b Compare August 18, 2026 10:18
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 78f219bc06

ℹ️ 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".

Comment thread coderd/mcpssrf/client.go Outdated
Comment thread coderd/mcpssrf/client.go Outdated
@ibetitsmike
ibetitsmike force-pushed the mike/codagt-711-mcp-ssrf branch from 78f219b to 573efd3 Compare August 18, 2026 10:52
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 573efd387b

ℹ️ 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".

Comment thread coderd/mcpssrf/client.go Outdated
Comment thread coderd/mcpssrf/client.go Outdated
@ibetitsmike
ibetitsmike force-pushed the mike/codagt-711-mcp-ssrf branch from 573efd3 to 65a3878 Compare August 18, 2026 11:45
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@coderagents

coderagents Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Documentation Check

New Documentation Needed

  • docs/ai-coder/agents/platform-controls/mcp-servers.md - This page documents the admin-configured MCP server url field but not the new SSRF behavior this PR introduces. Document that MCP server destinations resolving to private or reserved IP ranges are now blocked by default (covering OAuth2 discovery, OAuth2 token and revocation exchanges, and runtime MCP connections), and how a deployment admin exempts specific internal networks via --mcp-allowed-private-cidrs (CODER_MCP_ALLOWED_PRIVATE_CIDRS). Without this, an admin who points an MCP server at an internal URL will hit a connection block with no in-product doc explaining why. The AI Gateway proxy page (docs/ai-coder/ai-gateway/ai-gateway-proxy/setup.md) already documents the analogous behavior and is a good model for wording.

Note

The generated reference docs (docs/admin/setup/configuration-reference.md, docs/reference/cli/server.md, docs/reference/api/*) are already updated by this PR and are auto-generated, so no manual edits are needed there.


Automated review via Coder Agents

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 65a3878ca2

ℹ️ 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".

@ibetitsmike
ibetitsmike force-pushed the mike/codagt-711-mcp-ssrf branch from 65a3878 to 32e109c Compare August 18, 2026 12:18
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@ibetitsmike
ibetitsmike force-pushed the mike/codagt-711-mcp-ssrf branch from 50221da to 2cb04fe Compare August 19, 2026 18:50
@ibetitsmike
ibetitsmike force-pushed the mike/codagt-711-mcp-ssrf branch from 2cb04fe to 6ffda35 Compare August 19, 2026 19:12
@ibetitsmike
ibetitsmike force-pushed the mike/codagt-711-mcp-ssrf branch from 6ffda35 to ef77e94 Compare August 19, 2026 19:25
@ibetitsmike
ibetitsmike force-pushed the mike/codagt-711-mcp-ssrf branch from ef77e94 to b01077b Compare August 19, 2026 19:37
Base automatically changed from mike/codagt-714-mcp-org-picker to main August 19, 2026 19:46
@ibetitsmike
ibetitsmike force-pushed the mike/codagt-711-mcp-ssrf branch from b01077b to 6590af1 Compare August 19, 2026 19:54
@ibetitsmike
ibetitsmike force-pushed the mike/codagt-711-mcp-ssrf branch 2 times, most recently from 63aae9e to 8486714 Compare August 27, 2026 07:22
The MCP SSRF guard was extracted into github.com/coder/safedial so other
services can share it. Beyond the extraction, safedial hardens the same
policy: it panics instead of silently substituting a blank transport for
unguardable bases, preserves cookie jars, decodes every RFC 6052 NAT64
layout, fails closed on invalid addresses, and bounds dials to 30s even
without a caller deadline.
safedial panics when http.DefaultTransport has been globally replaced
with a non-*http.Transport instead of silently guarding a blank
transport, so the transport-isolation test must install its counting
sentinel only after coderd's guarded MCP client is constructed.
@ibetitsmike
ibetitsmike force-pushed the mike/codagt-711-mcp-ssrf branch from 8486714 to 0676c6d Compare August 30, 2026 10:56
@ibetitsmike
ibetitsmike merged commit d6b67e8 into main Aug 30, 2026
31 checks passed
@ibetitsmike
ibetitsmike deleted the mike/codagt-711-mcp-ssrf branch August 30, 2026 11:09
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants