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

   ### 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.
   


-- 
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