Skip to content

Commit e3d3557

Browse files
committed
CUSTESC-23757: Fix a bug where a wildcard ingress rule would match an host without starting with a dot
1 parent b0663dc commit e3d3557

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

ingress/ingress.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func matchHost(ruleHost, reqHost string) bool {
5858

5959
// Validate hostnames that use wildcards at the start
6060
if strings.HasPrefix(ruleHost, "*.") {
61-
toMatch := strings.TrimPrefix(ruleHost, "*.")
61+
toMatch := strings.TrimPrefix(ruleHost, "*")
6262
return strings.HasSuffix(reqHost, toMatch)
6363
}
6464
return false

ingress/rule_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ func Test_rule_matches(t *testing.T) {
148148
},
149149
want: true,
150150
},
151+
{
152+
name: "Hostname with wildcard should not match if no dot present",
153+
rule: Rule{
154+
Hostname: "*.api.abc.cloud",
155+
},
156+
args: args{
157+
requestURL: MustParseURL(t, "https://testing-api.abc.cloud"),
158+
},
159+
want: false,
160+
},
151161
}
152162
for _, tt := range tests {
153163
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)