apache / apache/shenyu

[IP address] <When accessing through IP+port number, the real IP address obtained by the server is that of the shenyu server>

Open
#5,383 1 comment 0 reactions 0 assignees View on GitHub
type: question
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

### Question

When accessing through IP+port number, the real IP address obtained by the server is that of the shenyu server
shenyu version: 2.6.0
Use http method to register, websocket to synchronize data, and divide plug-in method.
Reproduction method:
Request server IP address: 172.17.91.11 intranet
shenyu-gateway server ip address: 172.17.90.58 intranet
Server server IP address: 172.17.90.58
How to get the real IP on the server side:
`
public static String getIpAddr(HttpServletRequest request) {
try {
String ip = request.getHeader("x-forwarded-for");
if (ip == null || ip.length() == 0 || (INVALID_URL.equalsIgnoreCase(ip))) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || (INVALID_URL.equalsIgnoreCase(ip))) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || (INVALID_URL.equalsIgnoreCase(ip))) {
ip = request.getHeader("X-Real-IP");
}
if (ip == null || ip.length() == 0 || (INVALID_URL.equalsIgnoreCase(ip))) {
ip = request.getRemoteAddr();
}
if (ip != null) {
String[] ips = ip.split(",");
ip = ips[0];
}
return ip;
} catch (Exception e) {
log.info("error=>", e);
}
return null;
}`
Reproduction process:
Calling method ==> curl --location 'http://172.17.90.58:9195/user/shenyu/test01'
Expected: The server log prints ip==>172.17.91.11
Actual: The server log prints ip==>172.17.90.58
![Uploading 5122897A-D379-46DF-860A-DA58DCD2CD9C.png…]()

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the reported request with curl to 172.17.90.58:9195/user/shenyu/test01 and compare the server's client-IP headers with request.getRemoteAddr(). Trace how ShenYu forwards the request and client IP through the gateway; done means the downstream server logs 172.17.91.11 rather than 172.17.90.58.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.