Skip to content

Validate origin header#771

Open
Kehrlann wants to merge 2 commits intomainfrom
dgarnier/validate-origin-header
Open

Validate origin header#771
Kehrlann wants to merge 2 commits intomainfrom
dgarnier/validate-origin-header

Conversation

@Kehrlann
Copy link
Contributor

@Kehrlann Kehrlann commented Feb 4, 2026

Fixes #695 . Updates conformance tests.

Contents

Add Origin header validation for HTTP-based MCP server transports so servers can restrict which origins can connect (e.g. browser or cross-origin clients).

Introduces new ServerTransportSecurityValidator interface, to validate transport-level security. Default behavior stays permissive: transports use ServerTransportSecurityValidator.NOOP unless a validator is set via the builder.

The provided implementation is DefaultServerTransportSecurityValidator and only validates the Origin header, for now.

New APIs: example usage

HttpServletStreamableServerTransportProvider.builder()
// ...
.securityValidator(
    DefaultServerTransportSecurityValidator.builder()
        .allowedOrigin("http://localhost:*")
        .build())
// ...

Points of interest

Integration tests use the new JUnit 6 @ParameterizedClass API, which is another way of implementation "abstract base classes" for tests.

- Fixes #695
- Does not implement Host header validation yet

Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
@Kehrlann Kehrlann requested review from chemicL and tzolov and removed request for chemicL February 4, 2026 20:19
Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
@Kehrlann Kehrlann force-pushed the dgarnier/validate-origin-header branch from e5624d4 to 68ed795 Compare February 4, 2026 20:20
@Kehrlann Kehrlann requested a review from chemicL February 4, 2026 20:23
@Kehrlann Kehrlann marked this pull request as ready for review February 4, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return HTTP 403 when Origin header is invalid

1 participant