Skip to content

Commit f839537

Browse files
committed
Docs: clarify http headers validation
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
1 parent 90db9a6 commit f839537

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎docs/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ enables standardized integration between AI models and tools.
3636
- Supports Synchronous and Asynchronous programming paradigms
3737
- Pluggable JSON serialization (Jackson 2.x and Jackson 3.x)
3838
- Pluggable authorization hooks for server security
39-
- DNS rebinding protection with Host/Origin header validation
39+
- DNS rebinding protection with Host/Origin header validation (opt-in, see [HTTP Transport Security](server.md#http-transport-security))
4040

4141
!!! tip
4242
The core `io.modelcontextprotocol.sdk:mcp` module provides default STDIO, SSE, and Streamable HTTP client and server transport implementations without requiring external web frameworks.

‎docs/server.md‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Key features:
168168
(`keepAliveInterval`, `null` to disable)
169169
- Eviction of idle sessions — no open stream and no request for a full interval — every
170170
30 minutes by default (`sessionSweepInterval`, `null` to keep sessions until deleted)
171-
- Security validation support
171+
- Origin and Host validation (opt-in, see [HTTP Transport Security](#http-transport-security))
172172
- Graceful shutdown support
173173

174174
=== "Streamable HTTP WebFlux (external)"
@@ -261,6 +261,7 @@ Key features:
261261
- SSE endpoint (`/sse`) for server-to-client events
262262
- Message endpoint (configurable) for client-to-server requests
263263
- Error handling and response formatting
264+
- Origin and Host validation (opt-in, see [HTTP Transport Security](#http-transport-security))
264265
- Graceful shutdown support
265266

266267
=== "SSE WebFlux (external)"
@@ -317,6 +318,25 @@ Key features:
317318
- Support for traditional web applications
318319
- Synchronous operation handling
319320

321+
### HTTP Transport Security
322+
323+
!!! warning
324+
HTTP transports do not validate the `Origin` or `Host` headers by default.
325+
326+
To turn validation on, configure a `DefaultServerTransportSecurityValidator` with the allowed origins and hosts:
327+
328+
```java
329+
HttpServletStreamableServerTransportProvider transportProvider =
330+
HttpServletStreamableServerTransportProvider.builder()
331+
.mcpEndpoint("/mcp")
332+
.httpHeaderValidator(DefaultServerTransportSecurityValidator.builder()
333+
.allowedOrigin("http://localhost:*")
334+
.allowedHost("localhost:*")
335+
.build())
336+
.build();
337+
```
338+
339+
The same `httpHeaderValidator(...)` method is available on the Stateless and SSE transport builders.
320340

321341
## Server Capabilities
322342

0 commit comments

Comments
 (0)