Aias00 opened a new issue, #6447:
URL: https://github.com/apache/shenyu/issues/6447

   ### Current Behavior
   
   The TCP proxy parses remote addresses from `SocketAddress.toString()` with 
substring logic.
   
   Evidence:
   
   
`shenyu-protocol/shenyu-protocol-tcp/src/main/java/org/apache/shenyu/protocol/tcp/TcpBootstrapServer.java:93-99`
   
   ```java
   String address = socketAddress.toString();
   return address.substring(1, address.indexOf(':'));
   ```
   
   
`shenyu-protocol/shenyu-protocol-tcp/src/main/java/org/apache/shenyu/protocol/tcp/connection/ActivityConnectionObserver.java:88-93`
   
   ```java
   String cacheUrl = cacheSocketAddress.toString().substring(1);
   String removedUrl = u.getUrl();
   return StringUtils.equals(cacheUrl, removedUrl);
   ```
   
   This assumes `SocketAddress.toString()` is always formatted as 
`/<host>:<port>`. That is brittle and fails for IPv6 addresses such as 
`/[2001:db8::1]:12345`, unresolved addresses, or any address implementation 
with a different `toString()` format.
   
   Consequences:
   
   - `TcpBootstrapServer.getIp(...)` can extract the wrong client IP and 
request the wrong upstream connection.
   - `ActivityConnectionObserver.onRemove(...)` can fail to match removed 
upstreams and leave stale TCP connections alive.
   
   ### Expected Behavior
   
   TCP proxy should use typed address APIs instead of parsing 
`SocketAddress.toString()`.
   
   For `InetSocketAddress`, use `getHostString()`, `getAddress()`, and 
`getPort()` as appropriate. For unsupported address types, fail with a 
controlled error/log message.
   
   ### Steps To Reproduce
   
   1. Use TCP proxy with an IPv6 client/upstream or a non-standard/unresolved 
`SocketAddress`.
   2. Trigger `bridgeConnections(...)` or upstream removal.
   3. The current substring logic extracts the wrong host or compares the wrong 
address string.
   
   ### Suggested Fix
   
   Convert `SocketAddress` to `InetSocketAddress` when possible and use 
`getHostString()` / `getPort()`. Avoid substring parsing on `toString()` in 
both `TcpBootstrapServer` and `ActivityConnectionObserver`.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to