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.49k stars 3.31k forks source link

Spring Cloud Gateway not allowing Encoded URL paths after Update #3384

Open kpolli opened 4 months ago

kpolli commented 4 months ago

Describe the bug I just updated my Spring Cloud Gateway Application from 2021.0.1 to 2023.0.1 and Spring Boot from 2.7.3 to 3.2.5. I have noticed that URL encoded values (like %2F) returns a HTTP Status 400 – Bad Request. I have tried putting break points but none seem to be hit. Is this no longer supported in the new version or there is a setting I'm missing or it's a bug?

Sample Calling http://localhost:8080/user/abc%2Fxyz doesn't work but http://localhost:8080/user/abc/xyz and http://localhost:8080/user/abcxyz both work after this change

tompson commented 3 months ago

maybe same issue as https://github.com/spring-cloud/spring-cloud-gateway/issues/3395

thuryn commented 3 months ago

We have the same issue - we remove one param calling: GatewayFilterSpec.removeRequestParameter("paramName") and I found that when value of (not removed) param contains encoded value (for exmple %5B) the param is sent without encoding. When I try to debug the problem I get into RemoveRequestParameterGatewayFilterFactory.apply method - there is line: MultiValueMap<String, String> queryParams = new LinkedMultiValueMap(request.getQueryParams()); where queryParamsin request are encoded, but in Map queryParams there is decoded value (which is probably correct). But the params are reinserted on the line containg: URI newUri = UriComponentsBuilder.fromUri(request.getURI()).replaceQueryParams(CollectionUtils.unmodifiableMultiValueMap(queryParams)).build().toUri(); and values are not encoded again.