Match path before Content-Type in GraphQlRequestPredicates - #1486
Open
MarcoKunze-CPE wants to merge 1 commit into
Open
Match path before Content-Type in GraphQlRequestPredicates#1486MarcoKunze-CPE wants to merge 1 commit into
MarcoKunze-CPE wants to merge 1 commit into
Conversation
The GraphQL route predicates evaluated the request path last, after the method, Content-Type and Accept checks. Since the Content-Type check throws UnsupportedMediaTypeStatusException for an unparseable header, any POST anywhere in the application with a malformed Content-Type was answered with 415 during handler lookup, even when the request did not target the GraphQL endpoint at all. Evaluate the path first so that requests to other paths are never affected by Content-Type parsing. The 415 for unparseable Content-Type values on the GraphQL path itself is unchanged. Applies to both the WebMvc and the WebFlux predicate variants. See spring-projectsgh-1485
Author
|
Transparency note: this was researched and written by an AI coding assistant (Claude) operating on my account, after we diagnosed the failure mode in our production stack. Please review it with the appropriate scrutiny, and feel free to close it if it is not relevant or does not match the project's design intent. One known caveat we leave to the team's judgement: with the path matched first, |
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.
Fixes #1485
The GraphQL route predicates evaluate the request path last, after the method, Content-Type and Accept checks:
Since #1145,
contentTypeMatchthrowsUnsupportedMediaTypeStatusExceptionfor an unparseable Content-Type. BecauseRouterFunctionMappingevaluates the predicate during handler lookup for every request, any POST anywhere in the application with a malformed Content-Type is answered 415 — even when it does not target the GraphQL endpoint at all (details and a real-world failure mode with Vaadin heartbeats in #1485).This change evaluates
pathMatchfirst, so requests to other paths are never affected by Content-Type or Accept parsing. The deliberate 415 from #1145 is unchanged for requests genuinely aimed at the GraphQL path — the existingshouldRejectRequestWithInvalidContentTypetest still passes. Applied to both the WebMvc and the WebFlux predicate variants, with a regression test each (shouldNotRejectRequestWithInvalidContentTypeOnDifferentPath, red against the previous ordering with exactly theUnsupportedMediaTypeStatusException, green with this change; all 40 tests in bothGraphQlRequestPredicatesTestsclasses pass).