You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Pattern is all wildcards (e.g., "*.*") - matches any domain with at least that many labels
103
+
iflen(labels) <len(r.HostPattern) {
104
+
re.logger.Debug("rule does not match", "reason", "all-wildcard pattern requires at least pattern length labels", "rule", r.Raw, "method", method, "url", url, "pattern_length", len(r.HostPattern), "hostname_labels", len(labels))
105
+
returnfalse
106
+
}
107
+
} elseiflen(r.HostPattern) ==2 {
108
+
// Pattern like "*.com" - matches any single-label domain (same length)
109
+
iflen(labels) !=len(r.HostPattern) {
110
+
re.logger.Debug("rule does not match", "reason", "wildcard pattern requires same length for 2-label patterns", "rule", r.Raw, "method", method, "url", url, "pattern_length", len(r.HostPattern), "hostname_labels", len(labels))
111
+
returnfalse
112
+
}
113
+
} else {
114
+
// Pattern like "*.github.com" (3+ labels) - requires subdomain
115
+
// Host must have >= pattern length, but not be the base domain
116
+
iflen(labels) <len(r.HostPattern) {
117
+
re.logger.Debug("rule does not match", "reason", "wildcard pattern requires subdomain but host has fewer labels", "rule", r.Raw, "method", method, "url", url, "pattern_length", len(r.HostPattern), "hostname_labels", len(labels))
118
+
returnfalse
119
+
}
120
+
// Also ensure it's not the base domain (which would have len(labels) == len(r.HostPattern) - 1)
121
+
iflen(labels) ==len(r.HostPattern)-1 {
122
+
re.logger.Debug("rule does not match", "reason", "wildcard pattern does not match base domain", "rule", r.Raw, "method", method, "url", url, "pattern_length", len(r.HostPattern), "hostname_labels", len(labels))
123
+
returnfalse
124
+
}
125
+
}
91
126
92
-
// Since host patterns cannot end with asterisk, we only need to handle:
93
-
// "example.com" or "*.example.com" - match from the end (allowing subdomains)
94
-
fori, lp:=ranger.HostPattern {
95
-
labelIndex:=len(labels) -len(r.HostPattern) +i
96
-
ifstring(lp) !=labels[labelIndex] &&lp!="*" {
97
-
re.logger.Debug("rule does not match", "reason", "host pattern label mismatch", "rule", r.Raw, "method", method, "url", url, "expected", string(lp), "actual", labels[labelIndex])
98
-
returnfalse
127
+
// Match from the end (excluding the wildcard at the start)
128
+
// Pattern: ["*", "github", "com"]
129
+
// Host: ["api", "github", "com"] -> match "github" and "com"
130
+
fori:=1; i<len(r.HostPattern); i++ {
131
+
lp:=r.HostPattern[i]
132
+
labelIndex:=len(labels) -len(r.HostPattern) +i
133
+
ifstring(lp) !=labels[labelIndex] &&lp!="*" {
134
+
re.logger.Debug("rule does not match", "reason", "host pattern label mismatch", "rule", r.Raw, "method", method, "url", url, "expected", string(lp), "actual", labels[labelIndex])
135
+
returnfalse
136
+
}
137
+
}
138
+
} else {
139
+
// Exact domain pattern (e.g., "github.com")
140
+
// Must match exactly - same length, all labels match
0 commit comments