bigbug-dachong opened a new issue, #3887:
URL: https://github.com/apache/shenyu/issues/3887
### Question
查看了代码,插件中IP功能是通过 ForwardedRemoteAddressResolver 来实现获取真实ip的
但是在代码中,有2个点,没想清楚。
1、在extractXForwardedValues方法中,通过.split(", ")来切分ip,确定能切分开?是否多了空格?
`private List<String> extractXForwardedValues(final ServerWebExchange
exchange) {
List<String> xForwardedValues = exchange.getRequest().getHeaders()
.get(X_FORWARDED_FOR);
if (xForwardedValues == null || xForwardedValues.isEmpty()) {
return Collections.emptyList();
}
if (xForwardedValues.size() > 1) {
LOG.warn("Multiple X-Forwarded-For headers found, discarding
all");
return Collections.emptyList();
}
List<String> values = Arrays.asList(xForwardedValues.get(0).split(",
"));
if (values.size() == 1 && !StringUtils.hasText(values.get(0))) {
return Collections.emptyList();
}
return values;
}`
2、在判断XForwarded中可信值时,默认是取1,而且还倒序了。
加入中间经过代理层,这里是只信任上一跳吗?或者说只信任上一层代理地址?那和直接获取remote-ip不是一样了么?
`public InetSocketAddress resolve(final ServerWebExchange exchange) {
List<String> xForwardedValues = extractXForwardedValues(exchange);
Collections.reverse(xForwardedValues);
if (!xForwardedValues.isEmpty()) {
int index = Math.min(xForwardedValues.size(), maxTrustedIndex) -
1;
return new InetSocketAddress(xForwardedValues.get(index), 0);
}
return defaultRemoteIpResolver.resolve(exchange);
}`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscr...@shenyu.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org