Spring Cloud Gateway Invalid IPv4 address

Viewed 660

I have the following setup:

  • Spring Cloud Gateway on Port 8080
  • Routing /user to Spring Rest API (Called User) on Port 9000
  • Routing /character to Spring Rest API (Called Character) on Port 9001
  • Spring Cloud Config Server on Port 8090

The Gateway and the two Rest API applications are connected to the Cloud Config to pull the configs. The applications themselves start up correctly and can be used via their respective ports. I tested this by calling /swagger-ui.html which works fine.

When calling /actuator/gateway/routes I get a list of the routes of the gateway, which seem fine.

For all four applications I set up:

server:
  address: 0.0.0.0
  port: 8080 # ports are adjusted for each service
  forward-headers-strategy: framework

When I did not use the Spring Cloud Config Server the Gateway was running fine. Now I'm receiving the following error whenever calling either /user/swagger-ui.html or /character/swagger-ui.html

java.lang.IllegalArgumentException: Invalid IPv4 address: 0:0:0:0:0:0:0:1:60979
    at org.springframework.web.util.UriComponentsBuilder.parseForwardedFor(UriComponentsBuilder.java:363) ~[spring-web-5.3.8.jar:5.3.8]
    at org.springframework.web.filter.ForwardedHeaderFilter$ForwardedHeaderExtractingRequest.<init>(ForwardedHeaderFilter.java:246) ~[spring-web-5.3.8.jar:5.3.8]
    at org.springframework.web.filter.ForwardedHeaderFilter.doFilterInternal(ForwardedHeaderFilter.java:149) ~[spring-web-5.3.8.jar:5.3.8]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.8.jar:5.3.8]

Tried changing forward-headers-strategy to native which did not help either. I dug into the UriComponentBuilder and set some breakpoints to investigate the variables in their and I suspect request.headers["forwarded"] is the reason it fails:

Breakpoint just before the Exception is thrown

It tries to resolve the "for" inside the variable which is not a IPv4 address and thus fails. Forcing ipv4 with "server.address" seemed to work before using Spring Cloud Config, does not now, however. Has anyone come across the same issue and knows what am I supposed to do to get rid off this exception?

So all in all the routing itself seems to work, as it routes to the correct application. The application itself (User in this case) throws the error, not the Gateway.

1 Answers

The issue is resolved with

Spring gateway version 3.0.4

which you can get from

org.springframework.cloud:spring-cloud-dependencies:2020.0.4

Related