fix: enable DNS rebinding protection by default#659
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a Ktor route-scoped DNS rebinding protection plugin and enables it by default for MCP HTTP/SSE endpoints, aligning behavior with the TypeScript SDK advisory.
Changes:
- Introduces
DnsRebindingProtection(RouteScopedPlugin) with default localhost allowlist and optional Origin allowlist. - Enables DNS rebinding protection by default in
Route.mcp,Application.mcp,mcpStreamableHttp, andmcpStatelessStreamableHttp; deprecates the old transport configuration flags. - Updates/extends JVM tests and conformance server setup to reflect the new defaults and host parsing behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| kotlin-sdk-server/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/KtorRouteExtensionsTest.kt | Updates integration tests to explicitly disable protection where not under test. |
| kotlin-sdk-server/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/KtorApplicationExtensionsTest.kt | Updates Application extension test to explicitly disable protection where not under test. |
| kotlin-sdk-server/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/DnsRebindingProtectionTest.kt | Adds new tests covering Host/Origin validation and extractHostname. |
| kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServerTransport.kt | Deprecates old DNS config fields and updates header validation to be port-agnostic. |
| kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/KtorServer.kt | Adds new parameters to MCP helpers and enables protection by default via the new plugin. |
| kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/HostValidation.kt | New plugin + config + hostname extraction utility + default localhost allowlist. |
| kotlin-sdk-server/api/kotlin-sdk-server.api | Updates public API surface for new plugin/config and new MCP helper signatures. |
| conformance-test/src/main/kotlin/io/modelcontextprotocol/kotlin/sdk/conformance/ConformanceServer.kt | Removes redundant explicit DNS settings now covered by new defaults. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/HostValidation.kt
Outdated
Show resolved
Hide resolved
...r/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/DnsRebindingProtectionTest.kt
Show resolved
Hide resolved
...rc/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/KtorApplicationExtensionsTest.kt
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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.
Add
DnsRebindingProtectionKtor route-scoped plugin and enable it by default across all http transportsMotivation and Context
DNS rebinding protection was disabled by default (
enableDnsRebindingProtection = false), and sse endpoints (Route.mcp()) had zero protection. Same vulnerability as typescript sdk GHSA-w48q-cv73-mx4wHow Has This Been Tested?
all tests pass
Breaking Changes
Route.mcp(),Application.mcp()signatures changed (newenableDnsRebindingProtection,allowedHosts,allowedOriginsparams), binary incompatible on JVMenableDnsRebindingProtectiondefault changed fromfalsetotrueonmcpStreamableHttp/mcpStatelessStreamableHttplocalhost,127.0.0.1,[::1]— opt out withenableDnsRebindingProtection = falseOriginheader (non-browser clients)Configuration.enableDnsRebindingProtection,.allowedHosts,.allowedOriginsdeprecated in favor of the pluginTypes of changes
Checklist