spring-cloud / spring-cloud/spring-cloud-gateway
The non-ascii in the url was encoded 2 times, causing a parsing error
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.9k
- Forks
- 3.5k
- Avg merge
- 20h 57m
- Merged PRs (30d)
- 8
Description
Describe the bug
spring-cloud-gateway-server 3.1.8
when i send req(http://127.0.0.1:9991/test/testparam?chineseName=测试¶ms[]=1¶ms[]=2) to gatewayserver by postman or chrome,the app(http://127.0.0.1:8080) get parameter value of chineseName is %E6%B5%8B%E8%AF%95.
When I send the request directly to the app(http://127.0.0.1:8080), I get the correct parameter values(测试)
I found that the request parameter name contained [], which caused the url to be judged not to be fully encoded during verification, and the gateway re-encoded it again.
gateway codes :
RouteToRequestUrlFilter#filter
public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) {
。。。
// The internal judgment here returns false, but in fact the client has already encoded it once
boolean encoded = ServerWebExchangeUtils.containsEncodedParts(uri);
URI routeUri = route.getUri();
After chrome or postman encoding, actually send the request http://127.0.0.1:9991/test/testparam?chineseName=%E5%90%B4%E5%AD%90%E6%95%AC¶ms[]=1¶ms []=2
the chrome version is 117.0.5938.150(64)
about postman:
Postman for Windows
Version 8.11.1
win32 10.0.19045 / x64
Sample
some my app codes :
@GetMapping("/testparam")
public void paramTest(
ParamTest paramTest
) {
String name = paramTest.getChineseName();
log.info("name={}", name);
}
public class ParamTest {
private String chineseName;
private Integer[] params;
public String getChineseName() {
return chineseName;
}
public void setChineseName(String chineseName) {
this.chineseName = chineseName;
}
public Integer[] getParams() {
return params;
}
public void setParams(Integer[] params) {
this.params = params;
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at RouteToRequestUrlFilter#filter and inspect ServerWebExchangeUtils.containsEncodedParts, using the provided request with chineseName and params[] as the reproduction. Trace why the gateway treats the already encoded URI as unencoded, then add coverage showing the downstream app receives 测试 rather than a percent-encoded value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, spring-boot
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100