Skip to content

Fix NPE when ServerHttpRequest.getMethod() is null in MethodRoutePredicateFactory#3958

Open
sebastian8x8 wants to merge 1 commit intospring-cloud:mainfrom
sebastian8x8:patch-1
Open

Fix NPE when ServerHttpRequest.getMethod() is null in MethodRoutePredicateFactory#3958
sebastian8x8 wants to merge 1 commit intospring-cloud:mainfrom
sebastian8x8:patch-1

Conversation

@sebastian8x8
Copy link

Issue

When Spring Cloud Gateway receives a request with an unknown or unsupported HTTP method (such as a raw CONNECT request), ServerHttpRequest.getMethod() returns null. The current implementation of MethodRoutePredicateFactory does not check for this case, which can result in a NullPointerException when the code tries to compare or operate on the method. This leads to a 500 Internal Server Error and exposes internal error details to clients.

Resolution

This PR adds a null check for the HTTP method in the GatewayPredicate implementation in MethodRoutePredicateFactory. If the method is null, the predicate now gracefully rejects the request (returns false), preventing the server from throwing an exception and instead handling unsupported or malformed HTTP methods safely. This improves the robustness of the gateway and avoids leaking internal error information.

Fixes:

  • Prevents NullPointerException in MethodRoutePredicateFactory.
  • Returns a safe response instead of 500 Internal Server Error for requests with unsupported/unknown HTTP methods.

…icateFactory

Signed-off-by: Sebastian Wieseler <sebastian.wieseler@8x8.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants