[BUG] Kubernetes upstream protocol annotation can break Divide and Dubbo ingress parsing
- Dominant language
- Java
- Stars
- 8.8k
- Forks
- 3.1k
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 85
Description
### Current Behavior
Kubernetes ingress parsing can throw when the `shenyu.apache.org/upstreams-protocol` annotation has fewer entries than the number of endpoint addresses.
In `DivideIngressParser`, the parser indexes the protocol array once per endpoint address without checking the length:
```java
upstream.setProtocol(Objects.isNull(protocol) ? "http://" : protocol[i++]);
```
In `DubboIngressParser`, the parser also requires the annotation to exist and then increments `i` twice in one expression:
```java
String[] protocols = annotations.get(IngressConstants.UPSTREAMS_PROTOCOL_ANNOTATION_KEY).split(",");
...
.protocol(Objects.isNull(protocols[i++]) ? "dubbo://" : protocols[i++])
```
This can skip protocol entries and can throw `ArrayIndexOutOfBoundsException` even when the annotation length matches the endpoint count. If the annotation is missing in the Dubbo parser, `annotations.get(...).split(",")` can also throw.
### Expected Behavior
The parsers should tolerate a missing or shorter protocol annotation by using the plugin default protocol for endpoints without an explicit protocol, matching the safer behavior used by the websocket parser.
### Steps to Reproduce
1. Create a Kubernetes ingress that references a service with multiple endpoint addresses.
2. Set `shenyu.apache.org/upstreams-protocol` to a single value, or omit it for Dubbo.
3. Reconcile the ingress.
4. Divide/Dubbo parsing can throw while building upstreams.
### Code Location
- `shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/parser/DivideIngressParser.java`
- `shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/parser/DubboIngressParser.java`
- `shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/parser/WebSocketParser.java`
- websocket parsing already guards `i < protocols.length`, which is the safer behavior.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.