fix(coderd): block SSRF in MCP OAuth2 discovery and client registration - #27989
Merged
ThomasK33 merged 1 commit intoAug 11, 2026
Merged
Conversation
MCP OAuth2 auto-discovery and Dynamic Client Registration fetched attacker-influenced URLs (the MCP server URL and any endpoints or redirects it advertises) with a plain HTTP client. A hostile MCP server could redirect these fetches to internal addresses such as cloud metadata (169.254.169.254) or loopback services and partially read the responses (Cure53 CDM-02-002). Route all discovery traffic through a dedicated client that resolves each hostname once, rejects destinations in private, loopback, link-local, multicast, unspecified, and special-use ranges, and dials a validated IP directly so DNS rebinding cannot swap in a private address after validation. Redirects pass through the same guarded dialer, IPv4-mapped IPv6 literals are unmapped before matching, and the client never uses a proxy because the destination IP would be invisible to the dialer. Manual OAuth2 configuration is unaffected. coderd.Options gains an internal allowlist seam so tests can serve mock MCP servers on loopback; there is intentionally no user-facing configuration to bypass the guard.
ThomasK33
marked this pull request as ready for review
August 11, 2026 09:59
ibetitsmike
approved these changes
Aug 11, 2026
ThomasK33
deleted the
tk/codagt-784-remediate-cdm-02-002-mcp-oauth2-discovery-ssrf
branch
August 11, 2026 10:02
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
MCP OAuth2 auto-discovery and Dynamic Client Registration fetched attacker-influenced URLs (the MCP server URL plus any endpoints or redirects it advertises) with a plain HTTP client. A hostile MCP server could redirect these discovery fetches to internal destinations such as cloud metadata (
169.254.169.254) or loopback-only services, with part of the response surfacing through the API error detail (Cure53 CDM-02-002, partially-blind SSRF).All discovery and registration traffic now goes through a dedicated SSRF-guarded HTTP client: each hostname is resolved once, destinations in private, loopback, link-local, multicast, unspecified, and special-use ranges are rejected, and a validated IP is dialed directly so DNS rebinding cannot swap in a private address between validation and connect. Redirects pass through the same guarded dialer, IPv4-mapped IPv6 literals are unmapped before matching, and the client never uses a proxy because the destination IP would be invisible to the dialer. The "partially blind" leak channel is also closed: failing registration responses no longer have their body echoed into the API error detail, only the HTTP status code. Manually configured OAuth2 endpoints are unaffected; only auto-discovery against internal addresses now fails by design.
coderd.Optionsgains an internal allowlist seam so tests can serve mock MCP servers on loopback; this is intentionally not user-facing configuration.Regression tests assert that an internal loopback canary receives zero requests across redirect scenarios (discovery GET, registration POST, metadata IP, DNS-resolving hostnames) at both the unit and API level, and that upstream response bodies never appear in returned errors.
Scope notes (relation to earlier remediation notes on CODAGT-784)
The Linear issue carries an earlier assessment and a prior remediation attempt (commit
0b3dc89540, never opened as a PR; its branch no longer exists). This PR supersedes that work with a narrower, deliberate scope:CODER_MCP_ALLOWED_PRIVATE_CIDRS. This PR intentionally ships no user-facing bypass for a security fix; the allowlist exists only as an internalcoderd.Optionstest seam. Deployments with intentionally internal MCP servers can configure OAuth2 endpoints manually, and a reviewed operator flag can be added later if needed.Closes CODAGT-784 (remediation for SEC-264 / Cure53 CDM-02-002).
Generated with
mux