spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.54k stars 3.33k forks source link

duplicate slashes '///' in the URI path are rewritten to single slash '/' #2795

Closed sudhakar6343 closed 1 year ago

sudhakar6343 commented 1 year ago

Issue: Incorrect URL with multiple slashes in the URI path is converted to correct URL with single slash and routed to the target service.

User Request: https://10.69.53.14/api/rsm/v4////////resource Routed to target as: https://localhost:8443/api/rsm/v4/resource

Expected: Number of slashes in the URI path should remain the same.

Spring cloud gateway version : 2021.0.4

GatewayRoute config: spring: cloud: gateway: routes:

GatewayLogs: 2022-12-01 05:43:27.134 DEBUG 8 --- [or-http-epoll-2] o.s.c.g.h.RoutePredicateHandlerMapping : Route matched: path_match 2022-12-01 05:43:27.134 DEBUG 8 --- [or-http-epoll-2] o.s.c.g.h.RoutePredicateHandlerMapping : Mapping [Exchange: POST https://10.69.53.14/api/rsm/v4////////resource] to Route{id='path_match', uri=https://localhost:8443, order=0, predicate=Paths: [/**], match trailing slash: true, gatewayFilters=[], metadata={}} 2022-12-01 05:43:27.134 DEBUG 8 --- [or-http-epoll-2] o.s.c.g.h.RoutePredicateHandlerMapping : [8728ccd8-2214] Mapped to org.springframework.cloud.gateway.handler.FilteringWebHandler@3d93b551 2022-12-01 05:43:27.134 DEBUG 8 --- [or-http-epoll-2] o.s.c.g.handler.FilteringWebHandler : Sorted gatewayFilterFactories: [[GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.RemoveCachedBodyFilter@23c388c2}, order = -2147483648], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.AdaptCachedBodyGlobalFilter@2a492f2a}, order = -2147482648], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.NettyWriteResponseFilter@7fe083b1}, order = -1], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ForwardPathFilter@74f7d1d2}, order = 0], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter@486be205}, order = 10000], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.config.GatewayNoLoadBalancerClientAutoConfiguration$NoLoadBalancerClientFilter@5ca17ab0}, order = 10150], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.WebsocketRoutingFilter@4b4dd216}, order = 2147483646], GatewayFilterAdapter{delegate=com.amdocs.onp.proxy.platformproxyserver.GlobalPreFilter@16afbd92}, [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.NettyRoutingFilter@2c5d601e}, order = 2147483647], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ForwardRoutingFilter@f713686}, order = 2147483647]] 2022-12-01 05:43:27.135 INFO 8 --- [or-http-epoll-2] c.a.o.p.p.GlobalPreFilter : Global Pre Filter executed 2022-12-01 05:43:27.137 DEBUG 8 --- [or-http-epoll-2] r.netty.http.client.HttpClientConnect : [5df6d65e-2214, L:/127.0.0.1:37896 - R:localhost/127.0.0.1:8443] Handler is being applied: {uri=https://localhost:8443/api/rsm/v4/resource, method=POST}

spencergibb commented 1 year ago

This also happens for normal webflux endpoints, so I suspect there is not much I can do about it. Maybe @rstoyanchev can shed some light on it?

spring-cloud-issues commented 1 year ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-cloud-issues commented 1 year ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

skrutzler commented 1 year ago

I just came across the same issue reported here. Is it possible to re-open that issue? @spencergibb

foo///bar is forwarded to foo/bar ( and not to the valid URI spec foo/{path-variable1=""}/{path-variable2=""}/bar )

According to RFC2396 (https://www.ietf.org/rfc/rfc3986.txt) in section 3.3 it is stated that the segment can be empty so that a//b would give you ['a', '', 'b'] "

 =>   path-abempty  = *( "/" segment )
      path-absolute = "/" [ segment-nz *( "/" segment ) ]
      path-noscheme = segment-nz-nc *( "/" segment )
      path-rootless = segment-nz *( "/" segment )
      path-empty    = 0<pchar>

 =>   segment       = *pchar
      segment-nz    = 1*pchar
      segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
                    ; non-zero-length segment without any colon ":"

      pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"

 ...
 A path consists of a sequence of path segments separated by a slash ("/") character.