apache / apache/shenyu

[BUG] ContextPathParser concatenates null annotation value with /** — literal null/** rule condition

Open Beginner friendly
#6,863 1 comment 0 reactions 0 assignees View on GitHub
kubernetes priority: medium type: bug
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

## Description
`getRuleConditionList` (line 195) does `annotations.get(IngressConstants.PLUGIN_CONTEXT_PATH_PATH) + "/**"`. When the `shenyu.apache.org/plugin-context-path-path` annotation is absent (the common case — it is optional), `annotations.get()` returns null, and `null + "/**"` produces the string `"null/**"`. This string becomes the `paramValue` of a `ConditionData` with `PATH_PATTERN` operator, creating a rule that matches the literal path pattern "null/**". The same null is also set as `ruleHandle.contextPath` (line 172) and `ruleData.name` (line 180).

## Location
- `shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/parser/ContextPathParser.java:172,180,195`

## Impact
Every ingress without the optional context-path annotation gets a context-path rule that matches path pattern "null/**" — a no-op rule that never fires for real traffic, but creates phantom selectors/rules in the gateway cache. If a request path ever starts with `null/`, the rule unexpectedly matches.

## Suggested fix
Guard with `String contextPath = annotations.get(IngressConstants.PLUGIN_CONTEXT_PATH_PATH); if (Objects.isNull(contextPath)) { return res; }` (skip rule creation when no context path is configured), or use `Optional.ofNullable(...).orElse("")`.

## Related existing
None — distinct from M-10 (which triggers it for dubbo/sofa); this is the null-concatenation defect in `ContextPathParser` itself, present even for divide ingresses without the annotation.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/parser/ContextPathParser.java at lines 172, 180, and 195, then trace getRuleConditionList for an ingress without the optional annotation. Verify that no phantom context-path rule or literal null/** path is produced when the annotation is absent, and add regression coverage for that case.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kubernetes
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.