Class DefaultServerTransportSecurityValidator
java.lang.Object
io.modelcontextprotocol.server.transport.DefaultServerTransportSecurityValidator
- All Implemented Interfaces:
ServerTransportSecurityValidator
public final class DefaultServerTransportSecurityValidator
extends Object
implements ServerTransportSecurityValidator
Default implementation of
ServerTransportSecurityValidator that validates the
Origin and Host headers against lists of allowed values.
Supports exact matches and wildcard port patterns (e.g., "http://example.com:*" for origins, "example.com:*" for hosts).
- Author:
- Daniel Garnier-Moiroux
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating instances ofDefaultServerTransportSecurityValidator. -
Field Summary
Fields inherited from interface io.modelcontextprotocol.server.transport.ServerTransportSecurityValidator
NOOP -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Creates a new builder for constructing a DefaultServerTransportSecurityValidator.voidvalidateHeaders(Map<String, List<String>> headers) Validates the HTTP headers from an incoming request.protected voidvalidateOrigin(String origin) Validates a single origin value against the allowed origins.
-
Method Details
-
validateHeaders
public void validateHeaders(Map<String, List<String>> headers) throws ServerTransportSecurityExceptionDescription copied from interface:ServerTransportSecurityValidatorValidates the HTTP headers from an incoming request.- Specified by:
validateHeadersin interfaceServerTransportSecurityValidator- Parameters:
headers- A map of header names to their values (multi-valued headers supported)- Throws:
ServerTransportSecurityException- if validation fails
-
validateOrigin
Validates a single origin value against the allowed origins. Subclasses can override this method to customize origin validation logic.- Parameters:
origin- The origin header value, or null if not present- Throws:
ServerTransportSecurityException- if the origin is not allowed
-
builder
Creates a new builder for constructing a DefaultServerTransportSecurityValidator.- Returns:
- A new builder instance
-