apache / apache/shenyu

[BUG] IPv6 upstream addresses are parsed incorrectly by colon splitting

Open
#6,442 2 comments 0 reactions 1 assignee Claimed by @wy471x View on GitHub
admin common type: bug
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

### Current Behavior

Several admin/common runtime paths parse upstream URLs by splitting on `:`. This breaks valid IPv6 upstream addresses.

Evidence:

- `shenyu-common/src/main/java/org/apache/shenyu/common/utils/UpstreamCheckUtils.java:67-73`
- `shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/LoadServiceDocEntryImpl.java:153-158`
- `shenyu-admin/src/main/java/org/apache/shenyu/admin/transfer/DiscoveryTransfer.java:352-361`

Examples:

```java
hostPort = StringUtils.split(http[1], Constants.COLONS);
...
String[] upstreamUrlArr = discoveryUpstreamData.getUrl().split(":");
...
.map(url -> url.split(":", 2))
```

For valid IPv6 literals such as `[2001:db8::1]:8080` or `http://[2001:db8::1]:8080`, colon splitting truncates the host and/or attempts to parse part of the IPv6 literal as a port. That can produce a failed health check, wrong discovery upstream data, or `NumberFormatException`.

### Expected Behavior

Valid IPv6 upstream addresses should be parsed with URI/host-port aware logic and should work in health checks, discovery conversion, and API document loading.

### Steps To Reproduce

Use an upstream URL such as:

```text
[2001:db8::1]:8080
http://[2001:db8::1]:8080
```

Then trigger one of these paths:

- upstream health check via `UpstreamCheckUtils.checkUrl(...)`
- discovery upstream conversion via `DiscoveryTransfer.mapToDiscoveryUpstreamData(...)`
- API document instance loading via `LoadServiceDocEntryImpl.getInstances2(...)`

### Suggested Fix

Use `java.net.URI` or a host-port parser that supports bracketed IPv6 literals. Avoid raw `split(":")` for URLs or host:port strings.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.