fix: accept header accessor function in ServerTransportSecurityValidator#982
Open
neerajbhatt wants to merge 2 commits into
Open
Conversation
Replace Map<String, List<String>> parameter with Function<String, List<String>> in validateHeaders(), allowing callers to pass a header accessor instead of extracting all headers upfront. This is more efficient (only requested headers are looked up) and delegates case-insensitive header matching to the underlying request implementation (e.g. HttpServletRequest.getHeaders). - Update DefaultServerTransportSecurityValidator to use the accessor directly for Origin and Host headers - Update all three servlet transport providers to pass name -> Collections.list(request.getHeaders(name)) - Remove HttpServletRequestUtils (no longer needed) - Update unit tests to use accessor-based API Closes modelcontextprotocol#870
Contributor
|
The proposed changed would be breaking. The original |
Instead of a breaking change, introduce a deprecation path: - Keep validateHeaders(Map) as deprecated default method that bridges to the new validateHeaders(Function) via case-insensitive lookup - New implementations override validateHeaders(Function) for efficiency - Transport providers continue calling validateHeaders(Map) for backward compatibility with existing custom implementations - Restore HttpServletRequestUtils for header extraction in transports - Add tests for deprecated Map-based API and interface bridge behavior
Author
|
Updated with a deprecation path as suggested. The changes:
|
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.
Summary
Map<String, List<String>>parameter withFunction<String, List<String>>inServerTransportSecurityValidator.validateHeaders(), as proposed inServerTransportSecurityValidatoraccepts an accessor function for header #870HttpServletRequest.getHeadersis case-insensitive per the Servlet spec)HttpServletRequestUtilsutility class (no longer needed)Changes
ServerTransportSecurityValidator—validateHeaders(Function<String, List<String>> headerAccessor)DefaultServerTransportSecurityValidator— directly queriesOriginandHostvia accessor instead of iterating all headersname -> Collections.list(request.getHeaders(name))instead ofextractHeaders(request)Test plan
DefaultServerTransportSecurityValidatorTestspassServerTransportSecurityIntegrationTestspass (1 pre-existing flaky retry onmessageOriginNotAllowed)Closes #870